Format text in a messagebox

G

garyusenet

Hi i have a messagebox like so.

MessageBox.Show(mystring);

I would like to highlight each occurance of the word "and" in the
messagebox. How do I tell the messagebox to highlight each occurance of
the word and, in the string mystring that it is displaying?

Thanks,

Gary.
 
G

garyusenet

Ah so the functionality isn't within the messagebox itself.

I haven't written my own implementations of common controls yet. Could
you offer any advice please, as I'm a novice.

Many Thanks,

Gary.
 
G

Guest

you must create a form who will have the same look as the MessageBox.
with 1 Richtextbox for the text you want to display, 2 buttons (OK and
cancel).
In your form, you write a function like:

public void show (string msg, string Highlighttext, Color c)
{
this. Richtextbox.text = msg;

// here comes the function to find and highlight text
// Richtextbox has functions like Find, SelectionColor,...
// example in VB At: http://support.microsoft.com/kb/154884

this. Showdialog ();
}

Voila...
 
T

tcomer

I haven't written my own implementations of common controls yet. Could
you offer any advice please, as I'm a novice.

I would do a google search for "c# inherit form controls" or something
of the like. There is lots of information out there to get you started.
Ultimately, you will need to write your own class that inherits the
functionality of the MessageBox class. For example:

using System.Windows.Forms;

public class MyMessageBox : MessageBox
{
....
}

You may also want to read up on overriding base class functions. I hope
that helps.

Best Regards,
Tyson Comer
 
L

Lebesgue

Ultimately, you will need to write your own class that inherits the
functionality of the MessageBox class. For example:

using System.Windows.Forms;

public class MyMessageBox : MessageBox
{
...
}

Please note that this will not work since the MessageBox class has only one
static method to perform all the logic - show a message box. It is not
designed to be inherited.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top