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

来源:互联网 发布:hubner软件 编辑:程序博客网 时间:2024/05/29 08:42

今天做个项目,想将用户体验做好点,涉及到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.         }
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 耳朵里进了蚊子怎么办 有虫子爬进耳朵怎么办 虫子死在耳朵里怎么办 早上起床口苦口臭怎么办 耳朵被耳屎堵了怎么办 油耳朵被堵住了怎么办 棉签掏耳朵堵了怎么办 耳朵被气堵住了怎么办 掏耳朵发炎了疼怎么办 掏耳朵掏深了疼怎么办 耳朵里进了虫子怎么办? 耳朵里飞进小虫怎么办 一只耳朵听力差怎么办 62岁耳朵有点聋怎么办 一支耳朵有点聋怎么办 80岁老人耳朵聋怎么办 被nlp课程洗脑了怎么办 手上张了个鸡眼怎么办 手上长了个鸡眼怎么办 6岁儿童手指脱皮怎么办 手指骨折后关节僵硬怎么办 手指外伤后关节肿大僵硬怎么办 胳膊骨折了手肿怎么办 耳朵被肘了耳鸣怎么办 耳朵鼓膜外显的怎么办 耳膜破了怎么办为好 耳朵的鼓膜破了怎么办 被打耳鼓膜穿孔怎么办 两只耳朵嗡嗡响怎么办 耳朵长了个脓包怎么办 胸一个大一个小怎么办 把耳朵掏出血了怎么办 掏耳朵戳出血了怎么办 耳朵戳伤流血了怎么办 耳朵挖破出血了怎么办 耳朵让耳屎堵了怎么办 手被牙齿划破了怎么办 耳朵掏伤了很痛怎么办 掏伤耳朵发炎了怎么办 耳朵被掏发炎了怎么办 打的耳洞化脓了怎么办