今天做个项目,想将用户体验做好点,涉及到tooltip显示图片,查阅msdn后写出如下代码:效果不错:D(<==自我感觉良好= =#)呵呵!
完成以后猛然发现这个效果不正是前段时间苦苦寻觅的winform中的"层"效果吗?T_T 100分就这样飘远了~~
直奔主题
- private void Form1_Load(object sender, EventArgs e)
- {
- this.toolTip1.SetToolTip( button1,"hi there!");
- }
- private void toolTip1_Draw(object sender, DrawToolTipEventArgs e)
- {
- if (e.AssociatedControl == button1)
- {
- e.DrawBackground();
- e.Graphics.DrawLines(SystemPens.ControlLightLight, new Point[] {
- new Point (0, e.Bounds.Height - 1),
- new Point (0, 0),
- new Point (e.Bounds.Width - 1, 0)
- });
- e.Graphics.DrawImage(bit, new Point(0, 0));
- e.Graphics.DrawLines(SystemPens.ControlDarkDark, new Point[] {
- new Point (0, e.Bounds.Height - 1),
- new Point (e.Bounds.Width - 1, e.Bounds.Height - 1),
- new Point (e.Bounds.Width - 1, 0)
- });
- // Specify custom text formatting flags.
- TextFormatFlags sf = TextFormatFlags.Right;//|
- //TextFormatFlags.HorizontalCenter |
- //TextFormatFlags.NoFullWidthCharacterBreak;
- // Draw the standard text with customized formatting options.
- e.DrawText(sf);
- }
- }
- Bitmap bit;
- private void toolTip1_Popup(object sender, PopupEventArgs e)
- {
- bit = new Bitmap(@"C:/Documents and Settings/Administrator/My Documents/My Pictures/e/resizable.gif");
- int widt = TextRenderer.MeasureText(toolTip1.GetToolTip(e.AssociatedControl), this.Font).Width;
- Size si = new Size(bit.Width+widt+20,bit.Height);
- e.ToolTipSize = si;
- }