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开发中,有时候为了方便,需要把窗体的一些常规性的数据和操作函数进行封装,通过自定义基类窗体的方式,可以实现这些封装管理,让我们的框架统一化.简单化的处理一些常规性的操作,如这里介绍的用 ...
随机推荐
- opencv Installation in Linux and hello world
http://opencv.org/quickstart.html Installation in Linux These steps have been tested for Ubuntu 10.0 ...
- liunx shell数字相加
#!/bin/bash num1= num2= num3= #echo $($num1+$num2+$num3)#错误写法 echo $[$num1+$num2+$num3] echo $(($num ...
- hdoj 3665 Seaside【最短路】
Seaside Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- oc学习之路-----搞死指针之内存存储int类型
关于每个数据类型个字节在内存中的存储地址(以int为例) 先上图 如题,为什么说好的*p = &c是1啊,为什么是513呢,一开始,我也觉得挺惊讶的,后面听老师分析了一下才知道怎么回事,但是还 ...
- Gof-23种设计模式名称列表
工欲善其事,必先利其器. 在真正使用设计模式之前,必须知道各个设计模式对应的场景.设计模式是针对某种固定的场景下产生的固定解决方案.只有明确的场景,才会有明确的设计方式和方法. 设计模式全集: Abs ...
- tomcat部署web项目的方式 转
JavaWeb开发Tomcat中三种部署项目的方法,开始Java web开发必不可少的步骤,经过查找,觉得有篇文章介绍的不错 1.在conf目录中新建Catalina\localhost目录,在该目录 ...
- SAP HANA STRING_AGG
HANA Version 1.00.73.00.389160 不支持STRING_AGG,所以只能,,,,,,,, DROP PROCEDURE ""."ZCONCAT_ ...
- Excel中如何查找并列出所有链接(外部数据链接)?
在 Excel 中,有时会需要创建外部链接来引用其他工作簿的单元格内容,但是如果想要找出所有链接并且还要将这些外部数据链接列在一个工作簿当中是有点难度的.下面我会介绍一些快捷方法,不仅能够快速帮你找出 ...
- SpringNote02.Blog系统迁移到Linux下
基于SpringMVC-Hibernate的博客系统还在继续开发中 . 项目地址:https://github.com/defshine/SpringBlog 整个项目迁移到linux下开发,安装in ...
- Linux kernel驱动相关抽象概念及其实现 之“bus,device,driver”
bus,device,driver三个很重要的概念贯穿Linux内核驱动架构,特转载一篇博文: (转载自http://blog.csdn.net/gdt_a20/article/details/642 ...