Add text bullets to a C# form

后端 未结 5 1050
梦如初夏
梦如初夏 2021-02-08 17:41

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?

相关标签:
5条回答
  • 2021-02-08 18:12

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

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

    0 讨论(0)
  • 2021-02-08 18:21

    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());
    
    0 讨论(0)
  • 2021-02-08 18:24

    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.

    0 讨论(0)
  • 2021-02-08 18:25

    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 *.

    0 讨论(0)
  • 2021-02-08 18:39

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

    0 讨论(0)
提交回复
热议问题