How to create drop down information box in C# Winforms?

后端 未结 2 1444
耶瑟儿~
耶瑟儿~ 2020-12-21 21:52

I want to make a button that can drop down a multi-line label or form which contains help documentation for the user.

I have searched and I can\'t find anything tha

2条回答
  •  礼貌的吻别
    2020-12-21 22:43

    Using ToolStripControlHost and ToolStripDropDown controls can provide this for you:

    private void button1_Click(object sender, EventArgs e) {
      var helpInfo = new StringBuilder();
      helpInfo.AppendLine("This is line one.");
      helpInfo.AppendLine("This is line two.");
      var textHelp = new TextBox() { Multiline = true,
                                     ReadOnly = true,
                                     Text = helpInfo.ToString(),
                                     MinimumSize = new Size(100, 100)
                                    };
      var toolHost = new ToolStripControlHost(textHelp);
      toolHost.Margin = new Padding(0);
      var toolDrop = new ToolStripDropDown();
      toolDrop.Padding = new Padding(0);
      toolDrop.Items.Add(toolHost);
      toolDrop.Show(button1, button1.Width, 0);
    }
    

    Result:

    enter image description here

提交回复
热议问题