winForm帮助信息
在项目开发中,由于没更新一块内容,帮助文档都得及时更新,否则将导致最新的应用程序与帮助文档不一致。为此,写了一个帮助页面,这样就可以实时看到帮助信息。
首先,新建了一个帮助信息类,代码如下:
- /// <summary>
- /// 帮助信息类
- /// </summary>
- public class HelpInfo
- {
- #region Properties
- /// <summary>
- /// 矩形框
- /// </summary>
- public Rectangle HelpRectangle { get; set; }
- /// <summary>
- /// 矩形框画笔
- /// </summary>
- public Pen HelpRectanglePen { get; set; }
- /// <summary>
- /// 描述信息
- /// </summary>
- public List<TextStyle> HelpExplainStyle { get; set; }
- /// <summary>
- /// 帮助图片
- /// </summary>
- public List<ImageStyle> HelpImage { get; set; }
- /// <summary>
- /// 帮助指导线
- /// </summary>
- public List<HelpFinger> HelpFinger { get; set; }
- #endregion
- #region ctor
- public HelpInfo()
- {
- }
- #endregion
- }
- /// <summary>
- /// 画指导线类
- /// </summary>
- public class HelpFinger
- {
- /// <summary>
- /// 开始位置
- /// </summary>
- public Point Start { get; private set; }
- /// <summary>
- /// 结束位置
- /// </summary>
- public Point End { get; private set; }
- /// <summary>
- /// 线条宽度
- /// </summary>
- public float Width { get; private set; }
- /// <summary>
- /// 线的颜色
- /// </summary>
- public Color PenColor { get; private set; }
- /// <summary>
- /// 画带箭头的线
- /// </summary>
- /// <param name="start">开始位置</param>
- /// <param name="end">结束位置</param>
- /// <param name="width">线的宽度</param>
- public HelpFinger(Point start, Point end, float width = 1f)
- {
- this.Start = start;
- this.End = end;
- this.Width = width;
- this.PenColor = Color.YellowGreen;
- }
- /// <summary>
- /// 画带箭头的线
- /// </summary>
- /// <param name="start">开始位置</param>
- /// <param name="end">结束位置</param>
- /// <param name="color">线的颜色</param>
- /// <param name="width">线的宽度</param>
- public HelpFinger(Point start, Point end, Color color, float width = 1f)
- {
- this.Start = start;
- this.End = end;
- this.PenColor = color;
- this.Width = width;
- }
- }
- /// <summary>
- /// 帮助图片样式设置
- /// </summary>
- public class ImageStyle
- {
- /// <summary>
- /// 图片位置
- /// </summary>
- public Point ImagePosition { get; set; }
- /// <summary>
- /// 要显示的图片
- /// </summary>
- public Image Image { get; set; }
- /// <summary>
- /// 帮助图片
- /// </summary>
- /// <param name="image">要显示的图片</param>
- /// <param name="point">图片位置</param>
- public ImageStyle(Image image=null,Point point=new Point() )
- {
- this.Image = image;
- this.ImagePosition = point;
- }
- }
- /// <summary>
- /// 描述信息文本类
- /// </summary>
- public class TextStyle
- {
- #region Properties
- /// <summary>
- /// 文本位置
- /// </summary>
- public Point TextExplainStartPosition { get; set; }
- /// <summary>
- /// 文本格式
- /// </summary>
- public Font TextFont { get; set; }
- /// <summary>
- /// 文本的颜色和纹理
- /// </summary>
- public SolidBrush TextSolidBrush { get; set; }
- /// <summary>
- /// 描述文本
- /// </summary>
- public string TextExplain { get; set; }
- /// <summary>
- /// 指定应用于所绘制文本的格式化属性(如行距和对齐方式)
- /// </summary>
- public StringFormat TextExplainFormat { get; set; }
- #endregion
- #region ctor
- public TextStyle()
- {
- }
- /// <summary>
- /// 描述信息
- /// </summary>
- /// <param name="textExplain">描述文本</param>
- /// <param name="textStartPosition">文本位置</param>
- /// <param name="textFont">文本格式,包括字体、字号和字形属性</param>
- /// <param name="textSolidBrush">定义单色画笔</param>
- /// <param name="textExplainFormat">封装文本布局信息</param>
- public TextStyle(string textExplain, Point textStartPosition, Font textFont = null, SolidBrush textSolidBrush = null, StringFormat textExplainFormat=null)
- {
- this.TextExplain = textExplain;
- this.TextExplainStartPosition = textStartPosition;
- this.TextFont = textFont;
- this.TextSolidBrush = textSolidBrush;
- this.TextExplainFormat = textExplainFormat;
- }
- #endregion
- }
帮助页面代码如下:
- /// <summary>
- /// 帮助图片
- /// </summary>
- private Image helpImage = null;
- /// <summary>
- /// 存储不透明窗体及关闭按钮窗体
- /// </summary>
- private List<Form> listForm = new List<Form>();
- public HelpForm(Control control, List<HelpInfo> helpInfo)
- {
- InitializeComponent();
- if (control == null)
- {
- MessageBox.Show("没有获取到相关窗体信息!");
- return;
- }
- this.Width = control.Width;
- this.Height = control.Height;
- this.Location = control.Location;
- this.StartPosition = FormStartPosition.Manual;
- helpImage = new Bitmap(control.Width, control.Height); //创建与参数control同等大小的空白图片
- this.picHelpImage.BackgroundImage = helpImage;
- this.picHelpImage.BackgroundImageLayout = ImageLayout.Center;
- //helpImage添加帮助信息 + private void PictureHandle(List<HelpInfo> helpInfo)
- PictureHandle(helpInfo);
- this.BackColor = Color.Black;
- this.Opacity = 0.7;
- }
- /// <summary>
- /// 处理图片 添加帮助信息
- /// </summary>
- /// <param name="helpInfo">帮助信息</param>
- private void PictureHandle(List<HelpInfo> helpInfo)
- {
- if (helpInfo != null)
- {
- foreach (var currentInfo in helpInfo)
- {
- //helpImage添加说明信息
- helpImage = HelpInfoHandle(currentInfo.HelpRectangle, currentInfo.HelpRectanglePen, currentInfo.HelpExplainStyle, currentInfo.HelpImage, currentInfo.HelpFinger);
- }
- }
- }
- /// <summary>
- /// 将帮助信息添加到图片上
- /// </summary>
- /// <param name="helpRectangle">矩形框</param>
- /// <param name="helpRectanglePen">矩形框画笔</param>
- /// <param name="helpExplainStyle">帮助信息</param>
- /// <param name="imageStyles">帮助图片</param>
- /// <param name="fingers">帮助指导线</param>
- /// <returns>处理后的图片</returns>
- private Image HelpInfoHandle(Rectangle helpRectangle, Pen helpRectanglePen, List<TextStyle> helpExplainStyles, List<ImageStyle> imageStyles, List<HelpFinger> fingers)
- {
- if (helpImage != null)
- {
- Graphics graphice = Graphics.FromImage(helpImage);
- //添加说明性图片
- if (imageStyles != null)
- {
- AddHelpPicture(imageStyles);
- }
- bool noneRectangle = helpRectangle.X.Equals() && helpRectangle.X.Equals(helpRectangle.Y) && helpRectangle.Width.Equals() && helpRectangle.Width.Equals(helpRectangle.Height);
- if (!noneRectangle)
- {
- helpRectanglePen = helpRectanglePen ?? new Pen(Color.Orange);
- DrawRoundRectangle(graphice, helpRectanglePen, helpRectangle, );
- helpRectanglePen.Dispose();
- }
- //画带箭头的线,只对不封闭曲线有用
- if (fingers != null)
- {
- foreach (var finger in fingers)
- {
- if (finger != null)
- {
- Pen pen = new Pen(finger.PenColor);
- pen.Width = finger.Width;
- pen.DashStyle = DashStyle.Solid; //实线
- pen.EndCap = LineCap.ArrowAnchor;//定义线尾的样式为箭头
- graphice.DrawLine(pen, finger.Start, finger.End);
- }
- }
- }
- //将图片添加说明性文字
- if (helpExplainStyles != null)
- {
- foreach (var helpExplainStyle in helpExplainStyles)
- {
- if (helpExplainStyle != null)
- {
- helpExplainStyle.TextSolidBrush = helpExplainStyle.TextSolidBrush ?? new SolidBrush(Color.White);
- helpExplainStyle.TextFont = helpExplainStyle.TextFont ?? new Font("宋体", );
- graphice.DrawString(helpExplainStyle.TextExplain, helpExplainStyle.TextFont, helpExplainStyle.TextSolidBrush,
- helpExplainStyle.TextExplainStartPosition, helpExplainStyle.TextExplainFormat);
- }
- }
- }
- graphice.Dispose();
- }
- return helpImage;
- }
- /// <summary>
- /// 添加帮助图片信息
- /// </summary>
- /// <param name="imageStyles">帮助图片集合</param>
- private void AddHelpPicture(List<ImageStyle> imageStyles)
- {
- foreach (var imageStyle in imageStyles)
- {
- if (imageStyle != null && imageStyle.Image != null)
- {
- Form picForm = new Form();
- picForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
- picForm.MinimumSize = new System.Drawing.Size(,);
- picForm.Width = imageStyle.Image.Width;
- picForm.Height = imageStyle.Image.Height;
- picForm.BackgroundImage = imageStyle.Image;
- picForm.BackgroundImageLayout = ImageLayout.Center;
- picForm.Location = imageStyle.ImagePosition;
- picForm.StartPosition = FormStartPosition.Manual;
- picForm.TopMost = true;
- picForm.Click += new EventHandler(picHelpImage_Click);
- listForm.Add(picForm);
- picForm.Show();
- }
- }
- }
- /// <summary>
- /// 画圆角矩形
- /// </summary>
- /// <param name="graphics">画布</param>
- /// <param name="pen">画笔</param>
- /// <param name="rectangle">矩形</param>
- /// <param name="cornerRadius">角度</param>
- private static void DrawRoundRectangle(Graphics graphics, Pen pen, Rectangle rectangle, int cornerRadius)
- {
- using (GraphicsPath path = CreateRoundedRectanglePath(rectangle, cornerRadius))
- {
- try
- {
- graphics.DrawPath(pen, path);
- }
- catch (ArgumentException argumentException)
- {
- throw new Exception(argumentException.Message);
- }
- catch (Exception exception)
- {
- throw new Exception(exception.Message);
- }
- }
- }
- /// <summary>
- /// 创建圆角矩形框
- /// </summary>
- /// <param name="rectangle">矩形框</param>
- /// <param name="cornerRadius">角度</param>
- /// <returns>圆角矩形框</returns>
- internal static GraphicsPath CreateRoundedRectanglePath(Rectangle rectangle, int cornerRadius)
- {
- GraphicsPath roundedRect = new GraphicsPath();
- roundedRect.AddArc(rectangle.X, rectangle.Y, cornerRadius * , cornerRadius * , , );
- roundedRect.AddLine(rectangle.X + cornerRadius, rectangle.Y, rectangle.Right - cornerRadius * , rectangle.Y);
- roundedRect.AddArc(rectangle.X + rectangle.Width - cornerRadius * , rectangle.Y, cornerRadius * , cornerRadius * , , );
- roundedRect.AddLine(rectangle.Right, rectangle.Y + cornerRadius * , rectangle.Right, rectangle.Y + rectangle.Height - cornerRadius * );
- roundedRect.AddArc(rectangle.X + rectangle.Width - cornerRadius * , rectangle.Y + rectangle.Height - cornerRadius * , cornerRadius * , cornerRadius * , , );
- roundedRect.AddLine(rectangle.Right - cornerRadius * , rectangle.Bottom, rectangle.X + cornerRadius * , rectangle.Bottom);
- roundedRect.AddArc(rectangle.X, rectangle.Bottom - cornerRadius * , cornerRadius * , cornerRadius * , , );
- roundedRect.AddLine(rectangle.X, rectangle.Bottom - cornerRadius * , rectangle.X, rectangle.Y + cornerRadius * );
- roundedRect.CloseFigure();
- return roundedRect;
- }
- /// <summary>
- /// 单击帮助窗体时关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void picHelpImage_Click(object sender, EventArgs e)
- {
- if (listForm != null && listForm.Count > )
- {
- foreach (Form form in listForm)
- {
- form.Close();
- }
- listForm.Clear();
- }
- this.Close();
- }
这样,在其他要添加帮助信息的页面中实例化该窗体后就可以看到帮助信息
winForm帮助信息的更多相关文章
- WinForm员工信息表
先搞一个panel,然后里面放label.
- 循序渐进开发WinForm项目(4)--Winform界面模块的集成使用
随笔背景:在很多时候,很多入门不久的朋友都会问我:我是从其他语言转到C#开发的,有没有一些基础性的资料给我们学习学习呢,你的框架感觉一下太大了,希望有个循序渐进的教程或者视频来学习就好了. 其实也许我 ...
- java笔记整理
Java 笔记整理 包含内容 Unix Java 基础, 数据库(Oracle jdbc Hibernate pl/sql), web, JSP, Struts, Ajax Spring, E ...
- WinForm LED循环显示信息,使用定时器Threading.Timer
原文:WinForm LED循环显示信息,使用定时器Threading.Timer 这里用一个示例来演示timer如何使用.示例:LED屏幕显示描述:这个示例其实很简单,LED屏幕上显示3个信息: ...
- 使用Microsoft.ExceptionMessageBox.dll捕获WinForm程序中异常信息并弹窗显示
WinForm程序开发中,在开发模式下对于异常的处理一般都是通过调试的方式来查找异常发生的未知与原因. 下面以“除数为0”的情况来具体说明. Button按钮事件如下: private void bu ...
- C#Winform实时更新数据库信息Demo(使用Scoket)
最近在贴吧上看到有个提问就是关于怎么在Winform上实时的更新数据 提问者提到的是利用Timer去轮询,但最后经过网上查了下资料,感觉Socket也是可行的, 于是就写了这个Demo 这个Demo的 ...
- winform实现Session功能(保存用户信息)
问题描述:在winform中想实现像BS中类似Session的功能,放上需要的信息,在程序中都可以访问到. 解决方案:由于自己很长时间没有做过winform的程序,一时间竟然手足无措起来.后来发现wi ...
- winform程序捕获全局异常,对错误信息写入日志并弹窗
使用场景:在winform程序中如果没对方法进行try catch操作,若方法内出错,则整个程序报错并退出,如下图 如果程序已在客户手中,若没对错误的详细信息进行拍照,我们则不知道错误原因是什么.我们 ...
- Winform框架中窗体基类的用户身份信息的缓存和提取
在Winform开发中,有时候为了方便,需要把窗体的一些常规性的数据和操作函数进行封装,通过自定义基类窗体的方式,可以实现这些封装管理,让我们的框架统一化.简单化的处理一些常规性的操作,如这里介绍的用 ...
随机推荐
- DIY常用网站
工作: 技术: 学习: 个人十佳博客介绍:http://hedengcheng.com/?p=676
- HDU 4749 Parade Show 2013 ACM/ICPC Asia Regional Nanjing Online
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4749 题目大意:给一个原序列N,再给出一个序列M,问从N中一共可以找出多少个长度为m的序列,序列中的数 ...
- UVA 10557 XYZZY
Problem D: XYZZY ADVENT: /ad�vent/, n. The prototypical computer adventure game, first designed by W ...
- C#中A a=new B()的意义
A a=new B()的意义 前提:A是B的父类. A a = new B(); 或 A a; B b=new B(); a=b; 这一句的过程是这样的, 1)创建一个类A的引用a 2)创建一个类B的 ...
- ASP.NET MVC- VIEW Using the TagBuilder Class to Build HTML Helpers Part 3
The ASP.NET MVC framework includes a useful utility class named the TagBuilder class that you can u ...
- Datediff函数 助你实现不同进制时间之间的运算
在VB开发环境中实现时间之间的加减运算有很多种方法,前不久自己无意中发现了Datediff函数,它能够比较简单.全面地实现我们比较常用的时间之间的运算,今由自己的研究,搞清了它的一些用法,拿来和大家分 ...
- C++中this指针的使用方法.
this指针仅仅能在一个类的成员函数中调用,它表示当前对象的地址.以下是一个样例: void Date::setMonth( int mn ) { month = mn; // 这三句是等价的 thi ...
- Android开发_SharedPreferences
SharedPreferences是Android平台上一个轻量级的存储类,主要是保存一些常用的配置比如窗口状态,一般在Activity中 重载窗口状态onSaveInstanceState保存一般使 ...
- 第一个Xcode项目 - 代码修改布局约束
第一行的选中效果已经有了,那第二行的选中效果怎么做呢?我这里选择改变布局约束来实现选中效果 [我有个用object-c做APP的同事他说,我觉得这个应该去获取色块的位置,然后赋给选中用的View,然后 ...
- IE无法打开internet网站已终止操作的解决的方法
用IE内核浏览器的朋友,或许不经意间会碰到这样滴问题: 打开某个网页时,浏览器“嘣”跳出一个提示框“Internet Explorer无法打开Internet 站点...已终止操作”.而大多数情况下该 ...