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 The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
Shah
  • 1,604
  • 4
  • 20
  • 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
  • 25,159
  • 9
  • 44
  • 67
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,289
  • 2
  • 20
  • 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 The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
-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,537
  • 2
  • 25
  • 38
  • He want only part bold, not the whole Label. And it's possible with server side code in ASP.NET – Shadow The GPT Wizard Nov 30 '11 at 10:53
  • i am using Asp.Net. The function should be in csharp as i have to do some validation. and if it becomes true then it should be highlighted/ bold. on web page. – Shah Nov 30 '11 at 10:55