How to create drop down information box in C# Winf

2019-01-29 06:15发布

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

2条回答
虎瘦雄心在
2楼-- · 2019-01-29 06:49

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

查看更多
不美不萌又怎样
3楼-- · 2019-01-29 06:50

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));
查看更多
登录 后发表回答