利用C#实现标注式消息提示窗口
2006-11-18 00:09
423 查看
为了更加友好的将提示信息呈现给用户,我们必须对标准的Windows消息提示窗口进行处理。我们大家在Windows XP下使用U盘、闪存等移动存储设备,当插上或拔下这些设备时任务栏区域都会显示一个淡黄色背景,且具有标注样式的提示窗口弹出来,这样的提示即友善又美观,那么这到底是怎么实现的呢?其实道理并不复杂,该标注式提示窗口本身就是一个不规则窗体,当显示时它会将标注窗口的箭头指向不同控件。 一、技术要点 就像本文开头所说的"标注式消息提示窗口"其实就是一个具有不规则外形的窗体,但却具备了更加复杂的属性和行为。标注的箭头会根据不同控件指向不同的位置,当需要标注的控件过于接近屏幕的边缘时,标注窗口还会自动调整显示位置以及箭头的长短和大小。 我们为新创建的窗体取名为InfoWindow。在类的头部定义intArc和intArrowHeight两个私有变量,可以适当调整它们的值来微调提示窗口的位置和箭头的大小与位置。 提示窗口的箭头位置无非具有左上、右上、左下和右下四个可能性,我们为此定义了枚举类型的变量ArrowLocation,根据提示窗口位于屏幕的不同位置,GetArrowLocation可以计算提示窗口的位置并且返回适当的ArrowLocation,定义如下:
将提示窗口的背景颜色设置成Info 我们发现这样的外观有点别扭,没错!因为提示窗口缺少黑色边框!所以,还需要在窗体的OnPaint事件中添加代码,如下:
| ||||
启动Visual Studio 2005,新建Visual C#的Windows应用程序项目,并取名为ShowInfoWindow,添加4个Button组件、1个Label组件、1个textBox组件和3个Panel组件,其中3个Button用来显示标注式消息提示窗口并分别附着在三个组件之上,代码如下:
…… private InfoWindow iw; …… private void button1_Click(object sender, EventArgs e) { iw = new InfoWindow(); iw.ShowInfoWindow(label1, "关于标签组件的提示说明。"); } private void button3_Click(object sender, EventArgs e) { iw = new InfoWindow(); iw.ShowInfoWindow(button2, "关于按钮组件的提示说明。"); } private void button4_Click(object sender, EventArgs e) { iw = new InfoWindow(); iw.ShowInfoWindow(textBox1, "关于文本框组件的提示说明。"); } |
三、总结
本文演示了标注式消息提示窗口的创建和显示,利用GraphicsPath对象、Region对象以及屏幕坐标映射等方法有效的实现了提示窗口的外观和样式,提示窗口可以自动附着在相应控件之上,并且根据附着控件在屏幕上的位置自动调整提示窗口箭头的位置和大小。演示程序在Windows XP SP2以及.Net 框架 2.0环境下运行通过。
相关文章推荐
- 利用C#实现标注式消息提示窗口
- 利用C#实现标注式消息提示窗口
- 【转】利用C#实现标注式消息提示窗口
- 利用C#实现标注式消息提示窗口
- 利用C#实现标注式消息提示窗口
- 仿QQ、MSN消息提示窗口的实现(C#)
- 利用Cookies实现指定时间内消息只提示一次
- 利用 C# 实现任务栏通知窗口
- WinForm:实现类似QQ消息框一样的右下角消息提示窗口
- 窗口抖动和类消息提示窗口的实现
- C#+JS简单实现 定时轮询数据表 以及时弹出消息提示窗口
- C# :实现水印与图片合成,并利用Graphics 压缩图像质量 , (委托实现listBox的动态添加提示)
- C# 模仿QQ、MSN消息提示系列 三、实现多个提示效果
- c# 实现在屏幕的右下角的提示窗口
- 利用C#实现任务栏通知窗口
- C#+JS简单实现 定时轮询数据表 以及时弹出消息提示窗口
- 利用 C# 实现任务栏通知窗口
- QQ收到消息窗口闪烁效果实现[C#]
- QQ风格淡入淡出消息提示窗口的实现(WinForm)
- C#实现仿msn提示消息在登录后只弹出一次的效果(downmoon)