How to create drop down information box in C# Winf

2019-01-29 05:46发布

问题:

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 that is for C# Winforms. Do any free controls out there exist for this or will I have to create it myself? Many thanks, Richard

回答1:

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:



回答2:

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));