C#当鼠标光标悬停在ControlLabel它会显示物品清单?什么样的控制是什么? [英] C# When the mouse cursor hovering in ControlLabel it will show up list of items? What kind of control is that?
问题描述
我有一个标签控制,然后当鼠标指针徘徊在它大约1秒,它会显示在文本格式的产品清单(的项目是纯文本或它也是一个控制)。这就像在网站首页/联系我们/关于我们/帮助。什么样的控制我打算使用?
I have a Label Control then when mouse cursor is hovering around it for about 1second, it will show list of items in text format(the items are either plain text or it is also a control). It's like in the website Home/Contact Us/About Us/Help. What kind of control i'm going to use?
例如像。 www.ebay.com。在我的易趣,它会显示您的物品,如汇总/投标/列表/消息...等等...
Like for example. www.ebay.com. Under "My Ebay", it will shows you the items, eg Summary/Bids/List/Messages...etc...
推荐答案
您看到了什么是最好的一个工具提示
实施
What you see is best implemented by a ToolTip
.
要添加工具提示
来你通常会做这样的控制方式:
To add a ToolTip
to a Control you usually do this:
- 添加
工具提示
从工具箱中的表格
- 现在,形式作为属性的新属性字段上的每个控制面板:
工具提示的yourToolTipName
- 设置为要显示的工具提示每个控件的工具提示文本。
- Add a
ToolTip
from the toolbox to theForm
- Now each control on the form as a new property field in the properties pane:
"ToolTip" on "yourToolTipName"
- Set a tooltip text for each control you want to show a tool tip.
这是非常简单的。
因此,许多人认为,这是所有工具提示
可以做到的。
This is really simple.
Therefore many folks believe that that is all a ToolTip
can do.
但它可以是< STRONG>创建和修改动态和样式在许多方面。显示项目清单是完全没有问题的。
But it can be created and modified dynamically and styled in many ways. Showing a list of items is no problem at all..
要使用数据加载动态你的代码的 MouseHover
To load it with data dynamically you code the MouseHover
event of your Label
:
private void yourLabel_MouseHover(object sender, EventArgs e)
{
toolTip1.SetToolTip(yourLabel, yourData);
}
当然,你可能要调用一个函数来调用合适的和当前的数据为每个标签的
..:字符串loadData(标签LBL)
如果你愿意,你可以很容易地的OwnerDraw 的工具提示
。首先代码的弹出
事件:
If you want to you can easily ownerdraw the ToolTip
. First code its Popup
event:
private void toolTip1_Popup(object sender, PopupEventArgs e)
{
toolTip1.BackColor = Color.LightGoldenrodYellow; // pick a Color if you want to
toolTip1.OwnerDraw = true;
}
然后绘图
事件:
private void toolTip1_Draw(object sender, DrawToolTipEventArgs e)
{
using (Font font = new Font("Consolas", e.Font.SizeInPoints))
{
e.DrawBackground();
e.DrawBorder();
e.Graphics.DrawString(e.ToolTipText, font, Brushes.DarkMagenta, e.Bounds);
}
请注意,工具提示
将自动调整显示的文本。另外请注意,您可以嵌入 \\\
字符来创建换行符。
Note that the ToolTip
will automatically resize to display the text. Also note that you can embed \n
characters to create line breaks.
我选择的是等宽字体索拉
,所以我可以创造良好的对齐文本列。还要注意的是,如果你想放大的字体,你应该通过额外的线路和/或空间添加足够的空间,这是因为在尺寸的工具提示<中/ code >区从其原创字体大小计算,你不能选择不同的字体为它..见的这里更多的是一点...
I chose the monospaced font Consolas
, so I can create nicely aligned columns of text. Also note that if you want to enlarge the font you should add enough room via extra lines and/or space, this is because the size of the ToolTip
area is calculated from its original font size and you can't pick a different Font for it.. See here for a little more on that..
另外请注意,您不需要在所有设置属性的设计师。在 MouseHover
做所有你需要的..
Also note that you do not need to set the property in the designer at all. The MouseHover
does all you need..
这篇关于C#当鼠标光标悬停在ControlLabel它会显示物品清单?什么样的控制是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!