Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add text bullets to a C# form

Tags:

c#

winforms

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!

like image 415
Ryan Rodemoyer Avatar asked Sep 23 '10 20:09

Ryan Rodemoyer


2 Answers

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());
like image 91
Jeff Ogata Avatar answered Sep 28 '22 07:09

Jeff Ogata


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").

like image 21
KeithS Avatar answered Sep 28 '22 08:09

KeithS