I need a function which will check for a string in a text. (May be label/textbox text).
The function should check if a particular text exist in it, then if found it should make it bold.
How this should be done?
I need a function which will check for a string in a text. (May be label/textbox text).
The function should check if a particular text exist in it, then if found it should make it bold.
How this should be done?
EDIT: This answer applies to WinForms only.
The Label control does not allow partial formatting - which means that each formatting style you apply will affect the whole string.
The RichTextBox component allows you to do partial formatting - i.e applying a style on a specific word in the text.
More on RichTextBox can be found here
Here i found an answer that its possible (offcourse it is, almost everything is possible, haha :P).
Assuming you mean ASP.NET then such code will work:
string myString = "The quick brown fox jumps over the lazy dog";
string textToReplace = "fox";
myString = myString.Replace(textToReplace, "<span style=\"font-weight: bold;\">" + textToReplace + "</span>");
Then apply the string as Text of a label. You can't make text bold inside textbox.
The above example will make the word fox bold.
Lets, suppose the Label variable is label,
You can do if using desktop application,
**if(label.Text != string.Empty)
{
label.Font.Bold = true;
}**
and if you are using Asp.Net you have to do it using javascript if want to do it on the client side.
If you want to make portion od a label text bold, it is not allowed by the framework, rather you could take multiple labels for that.