开发者

how to include bold tag in my windowsform .cs file?

开发者 https://www.devze.com 2023-03-27 06:23 出处:网络
I currently have the following code: Label lbltxt = new Label(); lbltxt.Font = new System.Drawing.Font(\"Microsoft Sans Serif\",

I currently have the following code:

Label lbltxt = new Label(); 
lbltxt.Font = new System.Drawing.Font("Microsoft Sans Serif",
                                      10F,
                                      System.Drawing.FontStyle.Bold,
                                      System.Drawing.GraphicsUnit.Point,
                                      ((byte)(0)));

lbltxt.Text = dr["Title"].ToString();           
string tex开发者_Go百科t = lbltxt.Text;

string s = lbltxt.Text + Environment.NewLine + dr["Description"].ToString();

I want to bold the dr["title"] and add it to normal dr["description"]. I used above code to bold a part and added it to the dr["description"], but it was not working. I'm using this in winforms, i added dataset to datagridview and display result in datadridview.


Your question made me realize that you need a RichTextBox version of a DataGridViewTextBoxColumn. I Googled that and found a promising article on codeproject.com:

RichTextBox Cell in a DataGridView

I've never used the code before so I'm not sure if there are any serious limitations, but it looks like something you can use.

Take a look at the screenshot I made after downloading and running the project:

how to include bold tag in my windowsform .cs file?

Notice I've added a new line with bolded text at cell position 0, 0.


This should format your Title into <b> tags for you.

lbltxt.Text = string.Format("<b>{0}</b>", dr["Title"].ToString());

-Edit-

Turns out Html tags don't render in the Text attribute. Try styling it instead.

lbltxt.Style["font-weight"] == "heavy";
0

精彩评论

暂无评论...
验证码 换一张
取 消