how to include bold tag in my windowsform .cs file?
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:
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";
精彩评论