简体   繁体   English

如何在C#Winforms中创建下拉信息框?

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

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. 我搜索过,找不到C#Winforms的任何内容。 Do any free controls out there exist for this or will I have to create it myself? 是否存在任何免费控制或我是否必须自己创建? Many thanks, Richard 非常感谢,理查德

Using ToolStripControlHost and ToolStripDropDown controls can provide this for you: 使用ToolStripControlHost和ToolStripDropDown控件可以为您提供:

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: 结果:

在此输入图像描述

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM