在项目开发中,由于没更新一块内容,帮助文档都得及时更新,否则将导致最新的应用程序与帮助文档不一致。为此,写了一个帮助页面,这样就可以实时看到帮助信息。

首先,新建了一个帮助信息类,代码如下:

  1. /// <summary>
  2. /// 帮助信息类
  3. /// </summary>
  4. public class HelpInfo
  5. {
  6. #region Properties
  7.  
  8. /// <summary>
  9. /// 矩形框
  10. /// </summary>
  11. public Rectangle HelpRectangle { get; set; }
  12. /// <summary>
  13. /// 矩形框画笔
  14. /// </summary>
  15. public Pen HelpRectanglePen { get; set; }
  16. /// <summary>
  17. /// 描述信息
  18. /// </summary>
  19. public List<TextStyle> HelpExplainStyle { get; set; }
  20. /// <summary>
  21. /// 帮助图片
  22. /// </summary>
  23. public List<ImageStyle> HelpImage { get; set; }
  24. /// <summary>
  25. /// 帮助指导线
  26. /// </summary>
  27. public List<HelpFinger> HelpFinger { get; set; }
  28. #endregion
  29.  
  30. #region ctor
  31.  
  32. public HelpInfo()
  33. {
  34.  
  35. }
  36. #endregion
  37. }
  38.  
  39. /// <summary>
  40. /// 画指导线类
  41. /// </summary>
  42. public class HelpFinger
  43. {
  44. /// <summary>
  45. /// 开始位置
  46. /// </summary>
  47. public Point Start { get; private set; }
  48. /// <summary>
  49. /// 结束位置
  50. /// </summary>
  51. public Point End { get; private set; }
  52. /// <summary>
  53. /// 线条宽度
  54. /// </summary>
  55. public float Width { get; private set; }
  56. /// <summary>
  57. /// 线的颜色
  58. /// </summary>
  59. public Color PenColor { get; private set; }
  60. /// <summary>
  61. /// 画带箭头的线
  62. /// </summary>
  63. /// <param name="start">开始位置</param>
  64. /// <param name="end">结束位置</param>
  65. /// <param name="width">线的宽度</param>
  66. public HelpFinger(Point start, Point end, float width = 1f)
  67. {
  68. this.Start = start;
  69. this.End = end;
  70. this.Width = width;
  71. this.PenColor = Color.YellowGreen;
  72. }
  73. /// <summary>
  74. /// 画带箭头的线
  75. /// </summary>
  76. /// <param name="start">开始位置</param>
  77. /// <param name="end">结束位置</param>
  78. /// <param name="color">线的颜色</param>
  79. /// <param name="width">线的宽度</param>
  80. public HelpFinger(Point start, Point end, Color color, float width = 1f)
  81. {
  82. this.Start = start;
  83. this.End = end;
  84. this.PenColor = color;
  85. this.Width = width;
  86. }
  87. }
  88.  
  89. /// <summary>
  90. /// 帮助图片样式设置
  91. /// </summary>
  92. public class ImageStyle
  93. {
  94. /// <summary>
  95. /// 图片位置
  96. /// </summary>
  97. public Point ImagePosition { get; set; }
  98. /// <summary>
  99. /// 要显示的图片
  100. /// </summary>
  101. public Image Image { get; set; }
  102. /// <summary>
  103. /// 帮助图片
  104. /// </summary>
  105. /// <param name="image">要显示的图片</param>
  106. /// <param name="point">图片位置</param>
  107. public ImageStyle(Image image=null,Point point=new Point() )
  108. {
  109. this.Image = image;
  110. this.ImagePosition = point;
  111. }
  112. }
  113.  
  114. /// <summary>
  115. /// 描述信息文本类
  116. /// </summary>
  117. public class TextStyle
  118. {
  119. #region Properties
  120.  
  121. /// <summary>
  122. /// 文本位置
  123. /// </summary>
  124. public Point TextExplainStartPosition { get; set; }
  125. /// <summary>
  126. /// 文本格式
  127. /// </summary>
  128. public Font TextFont { get; set; }
  129. /// <summary>
  130. /// 文本的颜色和纹理
  131. /// </summary>
  132. public SolidBrush TextSolidBrush { get; set; }
  133. /// <summary>
  134. /// 描述文本
  135. /// </summary>
  136. public string TextExplain { get; set; }
  137. /// <summary>
  138. /// 指定应用于所绘制文本的格式化属性(如行距和对齐方式)
  139. /// </summary>
  140. public StringFormat TextExplainFormat { get; set; }
  141. #endregion
  142.  
  143. #region ctor
  144.  
  145. public TextStyle()
  146. {
  147.  
  148. }
  149. /// <summary>
  150. /// 描述信息
  151. /// </summary>
  152. /// <param name="textExplain">描述文本</param>
  153. /// <param name="textStartPosition">文本位置</param>
  154. /// <param name="textFont">文本格式,包括字体、字号和字形属性</param>
  155. /// <param name="textSolidBrush">定义单色画笔</param>
  156. /// <param name="textExplainFormat">封装文本布局信息</param>
  157. public TextStyle(string textExplain, Point textStartPosition, Font textFont = null, SolidBrush textSolidBrush = null, StringFormat textExplainFormat=null)
  158. {
  159. this.TextExplain = textExplain;
  160. this.TextExplainStartPosition = textStartPosition;
  161. this.TextFont = textFont;
  162. this.TextSolidBrush = textSolidBrush;
  163. this.TextExplainFormat = textExplainFormat;
  164. }
  165. #endregion
  166. }

帮助页面代码如下:

  1. /// <summary>
  2. /// 帮助图片
  3. /// </summary>
  4. private Image helpImage = null;
  5. /// <summary>
  6. /// 存储不透明窗体及关闭按钮窗体
  7. /// </summary>
  8. private List<Form> listForm = new List<Form>();
  9.  
  10. public HelpForm(Control control, List<HelpInfo> helpInfo)
  11. {
  12. InitializeComponent();
  13. if (control == null)
  14. {
  15. MessageBox.Show("没有获取到相关窗体信息!");
  16. return;
  17. }
  18. this.Width = control.Width;
  19. this.Height = control.Height;
  20. this.Location = control.Location;
  21. this.StartPosition = FormStartPosition.Manual;
  22. helpImage = new Bitmap(control.Width, control.Height); //创建与参数control同等大小的空白图片
  23. this.picHelpImage.BackgroundImage = helpImage;
  24. this.picHelpImage.BackgroundImageLayout = ImageLayout.Center;
  25. //helpImage添加帮助信息 + private void PictureHandle(List<HelpInfo> helpInfo)
  26. PictureHandle(helpInfo);
  27. this.BackColor = Color.Black;
  28. this.Opacity = 0.7;
  29. }
  30.  
  31. /// <summary>
  32. /// 处理图片 添加帮助信息
  33. /// </summary>
  34. /// <param name="helpInfo">帮助信息</param>
  35. private void PictureHandle(List<HelpInfo> helpInfo)
  36. {
  37. if (helpInfo != null)
  38. {
  39. foreach (var currentInfo in helpInfo)
  40. {
  41. //helpImage添加说明信息
  42. helpImage = HelpInfoHandle(currentInfo.HelpRectangle, currentInfo.HelpRectanglePen, currentInfo.HelpExplainStyle, currentInfo.HelpImage, currentInfo.HelpFinger);
  43. }
  44. }
  45. }
  46.  
  47. /// <summary>
  48. /// 将帮助信息添加到图片上
  49. /// </summary>
  50. /// <param name="helpRectangle">矩形框</param>
  51. /// <param name="helpRectanglePen">矩形框画笔</param>
  52. /// <param name="helpExplainStyle">帮助信息</param>
  53. /// <param name="imageStyles">帮助图片</param>
  54. /// <param name="fingers">帮助指导线</param>
  55. /// <returns>处理后的图片</returns>
  56. private Image HelpInfoHandle(Rectangle helpRectangle, Pen helpRectanglePen, List<TextStyle> helpExplainStyles, List<ImageStyle> imageStyles, List<HelpFinger> fingers)
  57. {
  58. if (helpImage != null)
  59. {
  60. Graphics graphice = Graphics.FromImage(helpImage);
  61. //添加说明性图片
  62. if (imageStyles != null)
  63. {
  64. AddHelpPicture(imageStyles);
  65. }
  66. bool noneRectangle = helpRectangle.X.Equals() && helpRectangle.X.Equals(helpRectangle.Y) && helpRectangle.Width.Equals() && helpRectangle.Width.Equals(helpRectangle.Height);
  67. if (!noneRectangle)
  68. {
  69. helpRectanglePen = helpRectanglePen ?? new Pen(Color.Orange);
  70. DrawRoundRectangle(graphice, helpRectanglePen, helpRectangle, );
  71. helpRectanglePen.Dispose();
  72. }
  73. //画带箭头的线,只对不封闭曲线有用
  74. if (fingers != null)
  75. {
  76. foreach (var finger in fingers)
  77. {
  78. if (finger != null)
  79. {
  80. Pen pen = new Pen(finger.PenColor);
  81. pen.Width = finger.Width;
  82. pen.DashStyle = DashStyle.Solid; //实线
  83. pen.EndCap = LineCap.ArrowAnchor;//定义线尾的样式为箭头
  84. graphice.DrawLine(pen, finger.Start, finger.End);
  85. }
  86. }
  87. }
  88. //将图片添加说明性文字
  89. if (helpExplainStyles != null)
  90. {
  91. foreach (var helpExplainStyle in helpExplainStyles)
  92. {
  93. if (helpExplainStyle != null)
  94. {
  95. helpExplainStyle.TextSolidBrush = helpExplainStyle.TextSolidBrush ?? new SolidBrush(Color.White);
  96. helpExplainStyle.TextFont = helpExplainStyle.TextFont ?? new Font("宋体", );
  97. graphice.DrawString(helpExplainStyle.TextExplain, helpExplainStyle.TextFont, helpExplainStyle.TextSolidBrush,
  98. helpExplainStyle.TextExplainStartPosition, helpExplainStyle.TextExplainFormat);
  99. }
  100. }
  101. }
  102. graphice.Dispose();
  103. }
  104. return helpImage;
  105. }
  106.  
  107. /// <summary>
  108. /// 添加帮助图片信息
  109. /// </summary>
  110. /// <param name="imageStyles">帮助图片集合</param>
  111. private void AddHelpPicture(List<ImageStyle> imageStyles)
  112. {
  113. foreach (var imageStyle in imageStyles)
  114. {
  115. if (imageStyle != null && imageStyle.Image != null)
  116. {
  117. Form picForm = new Form();
  118. picForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
  119. picForm.MinimumSize = new System.Drawing.Size(,);
  120. picForm.Width = imageStyle.Image.Width;
  121. picForm.Height = imageStyle.Image.Height;
  122. picForm.BackgroundImage = imageStyle.Image;
  123. picForm.BackgroundImageLayout = ImageLayout.Center;
  124. picForm.Location = imageStyle.ImagePosition;
  125. picForm.StartPosition = FormStartPosition.Manual;
  126. picForm.TopMost = true;
  127. picForm.Click += new EventHandler(picHelpImage_Click);
  128. listForm.Add(picForm);
  129. picForm.Show();
  130. }
  131. }
  132. }
  133.  
  134. /// <summary>
  135. /// 画圆角矩形
  136. /// </summary>
  137. /// <param name="graphics">画布</param>
  138. /// <param name="pen">画笔</param>
  139. /// <param name="rectangle">矩形</param>
  140. /// <param name="cornerRadius">角度</param>
  141. private static void DrawRoundRectangle(Graphics graphics, Pen pen, Rectangle rectangle, int cornerRadius)
  142. {
  143. using (GraphicsPath path = CreateRoundedRectanglePath(rectangle, cornerRadius))
  144. {
  145. try
  146. {
  147. graphics.DrawPath(pen, path);
  148. }
  149. catch (ArgumentException argumentException)
  150. {
  151. throw new Exception(argumentException.Message);
  152. }
  153. catch (Exception exception)
  154. {
  155. throw new Exception(exception.Message);
  156. }
  157. }
  158. }
  159.  
  160. /// <summary>
  161. /// 创建圆角矩形框
  162. /// </summary>
  163. /// <param name="rectangle">矩形框</param>
  164. /// <param name="cornerRadius">角度</param>
  165. /// <returns>圆角矩形框</returns>
  166. internal static GraphicsPath CreateRoundedRectanglePath(Rectangle rectangle, int cornerRadius)
  167. {
  168. GraphicsPath roundedRect = new GraphicsPath();
  169. roundedRect.AddArc(rectangle.X, rectangle.Y, cornerRadius * , cornerRadius * , , );
  170. roundedRect.AddLine(rectangle.X + cornerRadius, rectangle.Y, rectangle.Right - cornerRadius * , rectangle.Y);
  171. roundedRect.AddArc(rectangle.X + rectangle.Width - cornerRadius * , rectangle.Y, cornerRadius * , cornerRadius * , , );
  172. roundedRect.AddLine(rectangle.Right, rectangle.Y + cornerRadius * , rectangle.Right, rectangle.Y + rectangle.Height - cornerRadius * );
  173. roundedRect.AddArc(rectangle.X + rectangle.Width - cornerRadius * , rectangle.Y + rectangle.Height - cornerRadius * , cornerRadius * , cornerRadius * , , );
  174. roundedRect.AddLine(rectangle.Right - cornerRadius * , rectangle.Bottom, rectangle.X + cornerRadius * , rectangle.Bottom);
  175. roundedRect.AddArc(rectangle.X, rectangle.Bottom - cornerRadius * , cornerRadius * , cornerRadius * , , );
  176. roundedRect.AddLine(rectangle.X, rectangle.Bottom - cornerRadius * , rectangle.X, rectangle.Y + cornerRadius * );
  177. roundedRect.CloseFigure();
  178. return roundedRect;
  179. }
  180.  
  181. /// <summary>
  182. /// 单击帮助窗体时关闭
  183. /// </summary>
  184. /// <param name="sender"></param>
  185. /// <param name="e"></param>
  186. private void picHelpImage_Click(object sender, EventArgs e)
  187. {
  188. if (listForm != null && listForm.Count > )
  189. {
  190. foreach (Form form in listForm)
  191. {
  192. form.Close();
  193. }
  194. listForm.Clear();
  195. }
  196. this.Close();
  197. }

这样,在其他要添加帮助信息的页面中实例化该窗体后就可以看到帮助信息

winForm帮助信息的更多相关文章

  1. WinForm员工信息表

    先搞一个panel,然后里面放label.

  2. 循序渐进开发WinForm项目(4)--Winform界面模块的集成使用

    随笔背景:在很多时候,很多入门不久的朋友都会问我:我是从其他语言转到C#开发的,有没有一些基础性的资料给我们学习学习呢,你的框架感觉一下太大了,希望有个循序渐进的教程或者视频来学习就好了. 其实也许我 ...

  3. java笔记整理

    Java 笔记整理 包含内容     Unix Java 基础, 数据库(Oracle jdbc Hibernate pl/sql), web, JSP, Struts, Ajax Spring, E ...

  4. WinForm LED循环显示信息,使用定时器Threading.Timer

    原文:WinForm LED循环显示信息,使用定时器Threading.Timer 这里用一个示例来演示timer如何使用.示例:LED屏幕显示描述:这个示例其实很简单,LED屏幕上显示3个信息:  ...

  5. 使用Microsoft.ExceptionMessageBox.dll捕获WinForm程序中异常信息并弹窗显示

    WinForm程序开发中,在开发模式下对于异常的处理一般都是通过调试的方式来查找异常发生的未知与原因. 下面以“除数为0”的情况来具体说明. Button按钮事件如下: private void bu ...

  6. C#Winform实时更新数据库信息Demo(使用Scoket)

    最近在贴吧上看到有个提问就是关于怎么在Winform上实时的更新数据 提问者提到的是利用Timer去轮询,但最后经过网上查了下资料,感觉Socket也是可行的, 于是就写了这个Demo 这个Demo的 ...

  7. winform实现Session功能(保存用户信息)

    问题描述:在winform中想实现像BS中类似Session的功能,放上需要的信息,在程序中都可以访问到. 解决方案:由于自己很长时间没有做过winform的程序,一时间竟然手足无措起来.后来发现wi ...

  8. winform程序捕获全局异常,对错误信息写入日志并弹窗

    使用场景:在winform程序中如果没对方法进行try catch操作,若方法内出错,则整个程序报错并退出,如下图 如果程序已在客户手中,若没对错误的详细信息进行拍照,我们则不知道错误原因是什么.我们 ...

  9. Winform框架中窗体基类的用户身份信息的缓存和提取

    在Winform开发中,有时候为了方便,需要把窗体的一些常规性的数据和操作函数进行封装,通过自定义基类窗体的方式,可以实现这些封装管理,让我们的框架统一化.简单化的处理一些常规性的操作,如这里介绍的用 ...

随机推荐

  1. DIY常用网站

    工作: 技术: 学习: 个人十佳博客介绍:http://hedengcheng.com/?p=676

  2. HDU 4749 Parade Show 2013 ACM/ICPC Asia Regional Nanjing Online

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4749 题目大意:给一个原序列N,再给出一个序列M,问从N中一共可以找出多少个长度为m的序列,序列中的数 ...

  3. UVA 10557 XYZZY

    Problem D: XYZZY ADVENT: /ad�vent/, n. The prototypical computer adventure game, first designed by W ...

  4. 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的 ...

  5. 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 ...

  6. Datediff函数 助你实现不同进制时间之间的运算

    在VB开发环境中实现时间之间的加减运算有很多种方法,前不久自己无意中发现了Datediff函数,它能够比较简单.全面地实现我们比较常用的时间之间的运算,今由自己的研究,搞清了它的一些用法,拿来和大家分 ...

  7. C++中this指针的使用方法.

    this指针仅仅能在一个类的成员函数中调用,它表示当前对象的地址.以下是一个样例: void Date::setMonth( int mn ) { month = mn; // 这三句是等价的 thi ...

  8. Android开发_SharedPreferences

    SharedPreferences是Android平台上一个轻量级的存储类,主要是保存一些常用的配置比如窗口状态,一般在Activity中 重载窗口状态onSaveInstanceState保存一般使 ...

  9. 第一个Xcode项目 - 代码修改布局约束

    第一行的选中效果已经有了,那第二行的选中效果怎么做呢?我这里选择改变布局约束来实现选中效果 [我有个用object-c做APP的同事他说,我觉得这个应该去获取色块的位置,然后赋给选中用的View,然后 ...

  10. IE无法打开internet网站已终止操作的解决的方法

    用IE内核浏览器的朋友,或许不经意间会碰到这样滴问题: 打开某个网页时,浏览器“嘣”跳出一个提示框“Internet Explorer无法打开Internet 站点...已终止操作”.而大多数情况下该 ...