用tooltip实现winform中的层的概念,在tooltip中绘制图形

今天做个项目,想将用户体验做好点,涉及到tooltip显示图片,查阅msdn后写出如下代码:效果不错:D(<==自我感觉良好= =#)呵呵!

完成以后猛然发现这个效果不正是前段时间苦苦寻觅的winform中的"层"效果吗?T_T 100分就这样飘远了~~

直奔主题

 

  1.  private void Form1_Load(object sender, EventArgs e)
  2.         {
  3.             this.toolTip1.SetToolTip( button1,"hi there!");
  4.             
  5.         }
  6.         private void toolTip1_Draw(object sender, DrawToolTipEventArgs e)
  7.         {
  8.             if (e.AssociatedControl == button1)
  9.             {
  10.                 
  11.                 e.DrawBackground();
  12.                 e.Graphics.DrawLines(SystemPens.ControlLightLight, new Point[] {
  13.                     new Point (0, e.Bounds.Height - 1), 
  14.                     new Point (0, 0), 
  15.                     new Point (e.Bounds.Width - 1, 0)
  16.                 });
  17.                 
  18.                 e.Graphics.DrawImage(bit, new Point(0, 0));
  19.                 
  20.                 e.Graphics.DrawLines(SystemPens.ControlDarkDark, new Point[] {
  21.                     new Point (0, e.Bounds.Height - 1), 
  22.                     new Point (e.Bounds.Width - 1, e.Bounds.Height - 1), 
  23.                     new Point (e.Bounds.Width - 1, 0)
  24.                 });
  25.                 // Specify custom text formatting flags.
  26.                 TextFormatFlags sf = TextFormatFlags.Right;//|
  27.                                      //TextFormatFlags.HorizontalCenter |
  28.                                      //TextFormatFlags.NoFullWidthCharacterBreak;
  29.                 // Draw the standard text with customized formatting options.
  30.                 e.DrawText(sf);
  31.                 
  32.                 
  33.             }
  34.         }
  35.         Bitmap bit;
  36.         private void toolTip1_Popup(object sender, PopupEventArgs e)
  37.         {
  38.             bit = new Bitmap(@"C:/Documents and Settings/Administrator/My Documents/My Pictures/e/resizable.gif");
  39.             int widt = TextRenderer.MeasureText(toolTip1.GetToolTip(e.AssociatedControl), this.Font).Width;
  40.             Size si = new Size(bit.Width+widt+20,bit.Height);
  41.             e.ToolTipSize = si;
  42.         }
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
winToolTip是一个用于在用户界面上显示提示信息的控件。它可以在鼠标移动到控件或指定位置时自动显示。要在winform使用ToolTip,首先需要将ToolTip控件拖放到用户窗体上。然后,可以通过设置ToolTip的属性来控制显示的延迟时间、提示文本以及其他参数。例如,可以设置AutoPopDelay属性来控制提示信息的显示时间,设置InitialDelay属性来控制鼠标悬停多久后显示提示信息,设置ReshowDelay属性来控制再次显示提示信息的延迟时间。还可以通过ShowAlways属性来指定是否始终显示提示信息,即使窗体不处于活动状态。 在使用ToolTip时,可以使用Show和Hide方法来控制提示信息的显示和隐藏。如果遇到无法隐藏提示信息的问题,可以在再次触发Show之前调用Hide方法来隐藏。另外,如果提示信息不能及时更新,可能是因为内存清理存在问题,可以在显示之前调用Dispose方法清除内存,然后重新实例化ToolTip控件。 总结来说,winformToolTip控件可以用于在用户界面上显示提示信息,可以通过设置属性来控制提示信息的显示和隐藏,还可以使用Show和Hide方法来控制提示信息的显示和隐藏。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [C#WinformToolTip的简单用法](https://blog.csdn.net/diaoshanwai2368/article/details/102220537)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [Winform窗体学习笔记 第二十七篇 ToolTip类](https://blog.csdn.net/liuxiaomao1988/article/details/87432348)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值