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

后端 未结 2 1443
耶瑟儿~
耶瑟儿~ 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:27

    I think it will be a bad user experience to see a tooltip on click of a button. However, you can use this if you really want to

    var b  = new Button();
    b.Click += (sender, args) => new ToolTip().Show("Help documentation", b.Parent, new Point(b.Location.X, b.Location.X + 10));
    
    0 讨论(0)
  • 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

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