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

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

  /// <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帮助信息的更多相关文章

  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. JDBC_demo:java连接mysql过程

    1.任何数据库驱动程序都提供对java.sql.Driver接口的驱动类,mysql-connector-java-5.1.39-bin.jar中Driver: package com.mysql.j ...

  2. JAVA基础英语单词表(上)

    action                            / 'ækʃən /          动作,行为 active                           / 'ækti ...

  3. SSL安全解决方案(转)

    http://blog.csdn.net/photnman/article/details/388853 背景及部分安全知识在高度保证应用程序安全的过程中我们不免会考虑到如下的安全需求,然后根据这些安 ...

  4. Javascript从入门到精通(一)

    第一篇   基础知识 一.JavaScript的主要特点:1.解释性:不同于一些编译性的程序语言(如C.C++等),它是一种解释性的程序语言,它的源代码不需要经过编译,而是直接在浏览器中运行时被解释. ...

  5. VS扩展CodeMaid代码整理插件

    本文章转载:http://www.cnblogs.com/wintersun/p/3577039.html 官方地址:http://www.codemaid.net/ 开源VS扩展CodeMaid介绍 ...

  6. Android仿微信UI布局视图(圆角布局的实现)

    圆角button.或布局能够在xml文件里实现,但也能够使用图片直接达到所需的效果,曾经版本号的微信就使用了这样的方法. 实现效果图:    watermark/2/text/aHR0cDovL2Js ...

  7. careercup-栈与队列 3.2

    3.2 请设计一个栈,除pop与push方法,还支持min方法,可返回栈元素中的最小值.push.pop和min三个方法的时间复杂度必须为O(1). 我们假设除了用一个栈s1来保存数据,还用另一个栈s ...

  8. GUI编程笔记(java)02:java.awt和java.swing包的区别

    1. java.awt和java.swing两者的概述 java.awt:(java的标准包)             Abstract Window ToolKit (抽象窗口工具包),需要调用本地 ...

  9. [转载]js中__proto__和prototype的区别和关系

          首先,要明确几个点:1.在JS里,万物皆对象.方法(Function)是对象,方法的原型(Function.prototype)是对象.因此,它们都会具有对象共有的特点.即:对象具有属性_ ...

  10. android 5.0 创建多用户 双开多开应用(2)

    上一讲 讲了如何创建一个user android 5.0 创建多用户 双开多开应用(1) 为什么要创建User  例如window 系统创建了一个user 会在当前用户下进行操作,而android 多 ...