views:

66

answers:

5

I am creating a form in C# and need to display text on the form. I need some of the text to show up in a bulleted, unordered list. Is it possible to do this while using a label? Or a rich text box? I am not using ASP.NET and this is for a desktop app.

My message should look like this:

To continue please selected one of the actions below:

  • Click ButtonA to do this action.
  • Click ButtonB to do this action.

Thanks!

A: 

Yes you can use text below:

const string text = @"To continue please selected one of the actions below:

. Click ButtonA to do this action.
. Click ButtonB to do this action.";
label1.Text = text;

You can use special characters for the bullet as well such as *.

Aliostad
+1  A: 

You can use ASCII or UniCode characters, and reformat your string to replace a marker character with the formatting character.

Say you defined your string like so:

var myMessage = "To continue please selected one of the actions below: * Click ButtonA to do this action. * Click ButtonB to do this action."

you could do a Regex.Replace that looked for asterisks and converted to bullets:

var formattedString = Regex.Replace(myMessage, "\*", "\r\n \u2022");

Since the string was defined on one line, we also put in a newline ("\r\n").

KeithS
A normal String.Replace() will do the job just as well without the need to quote the "*"
Ian Ringrose
A: 

You could use a WebBrowser control. I.E.:

WebBrowser webBrowser1 = new WebBrowser(); webBrowser1.DocumentText 1 = "<li>Click ButtonA ...</li><li>Click ButtonB ...</li>"

Richard Hein
A: 

If you'll take a look at the Character Map (Start > Programs > Accessories > System Tools > Character Map), you can locate the keystroke "code" for most characters.

For Arial Text, the "Middle Dot" keystroke combination is:

Alt+0183

To place this in your text using Visual Studio, hold down the Alt key while typing in "0183" on the Numeric Keypad (not the keys over the alpha pad).

This should give you "·" in your text.

That's as close as I have come.

Note that other special characters (degrees - Alt+0176 °, copyright - Alt+0169 ©, and many others) can be included with this technique.

jp2code
+1  A: 

Just to add as a suggestion to the OP, I have found that using a StringBuilder to construct multi-line messages helps me keep the formatting straight:

StringBuilder messageBuilder = new StringBuilder(200);

messageBuilder.Append("To continue, please select one of the actions below:");
messageBuilder.Append(Environment.NewLine);
messageBuilder.Append(Environment.NewLine);
messageBuilder.Append("\t\u2022 Click Button A to do this action.");
messageBuilder.Append(Environment.NewLine);
messageBuilder.Append("\t\u2022 Click Button B to do this action.");

MessageBox.Show(messageBuilder.ToString());
adrift
I used this answer. As a side note, I did not use a standard MessageBox as I created my own form as a pseduo custom message box. When adding text to the label I could not use '\t' and had to add the spaces manually.
rodey