0

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?

Shadow Wizard Says No More War
  • 64,101
  • 26
  • 136
  • 201
Shah
  • 1,494
  • 4
  • 16
  • 33

4 Answers4

1

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

Shai
  • 24,239
  • 7
  • 43
  • 65
0

Here i found an answer that its possible (offcourse it is, almost everything is possible, haha :P).

Make portion of a Label's Text to be styled bold

Community
  • 1
  • 1
Stefan Koenen
  • 2,238
  • 2
  • 19
  • 32
0

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.

Shadow Wizard Says No More War
  • 64,101
  • 26
  • 136
  • 201
-1

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.

FIre Panda
  • 6,351
  • 2
  • 24
  • 37