昨天分享了一个环形滚动条控件,今天分享一个提示框风格的窗体。代码如下:

/// <summary>
/// 继承自Form,但将FormBorderStyle设置为None
/// </summary>
public partial class TipForm : Form
{
public TipForm()
{
InitializeComponent();
} /// <summary>
/// 鼠标按下位置,方便移动窗体
/// </summary>
private Point ptMouseDown; /// <summary>
/// 窗体下部分尖头的坐标位置
/// </summary>
private Point position;
public Point Position
{
get { return position; }
set
{
position = value;
SetPosition(position);
}
} /// <summary>
/// 设置窗口的圆角半径
/// </summary>
private int radius = ;
public int Radius
{
get { return radius; }
set { radius = value; }
} /// <summary>
/// 重写OnPaint方法以绘制窗体边框
/// </summary>
/// <param name="e"></param>
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics graph = e.Graphics;
graph.SmoothingMode = SmoothingMode.AntiAlias;
GraphicsPath path = GetTipPath(ClientRectangle);
Rectangle rect = new Rectangle(ClientRectangle.X, ClientRectangle.Y,
ClientRectangle.Width, ClientRectangle.Height);
rect.Inflate(-, -);
GraphicsPath border = GetTipPath(rect);
GraphicsPath curve = new GraphicsPath();
graph.DrawPath(new Pen(Color.Black,), border);
this.Region = new Region(path);
} /// <summary>
/// 根据窗体下部的顶点位置设置窗体位置
/// </summary>
/// <param name="pos">屏幕坐标点</param>
public void SetPosition(Point pos)
{
this.Location = new Point(pos.X - Size.Width / ,
pos.Y - Size.Height);
} /// <summary>
/// 根据当前窗体的ClientRectangle属性获取Tip风格路径
/// </summary>
/// <param name="rect"></param>
/// <returns></returns>
private GraphicsPath GetTipPath(Rectangle rect)
{
GraphicsPath path = new GraphicsPath();
int height = rect.Height - Radius;
path.StartFigure();
path.AddArc(rect.X, rect.Y, Radius, Radius, , -);
path.AddArc(rect.X, rect.Y + height - Radius, Radius, Radius,
, -);
path.AddLine(
new Point(rect.X + Radius / , rect.Y + height),
new Point(rect.X + rect.Width / - Radius / ,
rect.Y + height));
path.AddLine(
new Point(rect.X + rect.Width / - Radius / ,
rect.Y + height),
new Point(rect.X + rect.Width / , rect.Y + height + Radius));
path.AddLine(
new Point(rect.X + rect.Width / , rect.Y + height + Radius),
new Point(rect.X + rect.Width / + Radius / ,
rect.Y + height));
path.AddLine(
new Point(rect.X + rect.Width / + Radius / ,
rect.Y + height),
new Point(rect.X + rect.Width - Radius / ,
rect.Y + height));
path.AddArc(rect.X + rect.Width - radius,
rect.Y + height - Radius, Radius, Radius, , -);
path.AddArc(rect.X + rect.Width - Radius, rect.Y,
Radius, Radius, , -);
path.AddLine(new Point(rect.X + rect.Width - Radius / , rect.Y),
new Point(rect.X + Radius / , rect.Y)); path.CloseFigure();
return path;
} private void button1_Click(object sender, EventArgs e)
{
Close();
} /// <summary>
/// 鼠标移动事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TipForm_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point pt = e.Location;
Location = new Point(Location.X + pt.X - ptMouseDown.X,
Location.Y + pt.Y - ptMouseDown.Y);
}
} /// <summary>
/// 鼠标按下事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TipForm_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ptMouseDown = e.Location;
}
} private void btnClose_Click(object sender, EventArgs e)
{
Close();
} private void TipForm_SizeChanged(object sender, EventArgs e)
{
Point pt = new Point(ClientRectangle.X + ClientRectangle.Width - Radius / - ,
ClientRectangle.Y + Radius / );
btnClose.Location = pt;
}
}

主要是通过创建一个表示窗体轮廓的路径,然后根据这个路径设置窗体的Region属性来完成的。下面是效果截图:

winform下自绘提示框风格窗体的更多相关文章

  1. winform下的智能提示框

    winform下的智能提示框 最近在搞winform的程序,接触到有些可能以后还会用到的功能,所以写到博客园里去,第一可以加深自己的印象,第二可以在以后再遇到同样问题的时候忘记了可以马上回来看看,第三 ...

  2. WinForm下增加声音提示

    在WinForm平台下播放声音,一般有两种方式:第一种是调用系统自带声音: [代码] 申明定义: [DllImport("kernel32.dll")] public static ...

  3. UIWebView 自定义网页中的alert和confirm提示框风格

    .h #import <UIKit/UIKit.h> @interface UIWebView (JavaScriptAlert) -(void)webView:(UIWebView *) ...

  4. (十八)c#Winform自定义控件-提示框

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  5. 重绘DevExpress的XtraMessageBox消息提示框控件

    先来看提示框,可以看到框其实是一个去掉最大化.最小化按钮后的窗体,窗体的内容就是我们想要提示的内容,重绘提示框其实就是重绘窗体以及中间部分的内容. 首先重绘窗体,消息提示框的窗体不是XtraForm而 ...

  6. Android 代码库(自定义一套 Dialog通用提示框 )

          做Android开发五年了,期间做做停停(去做后台开发,服务器管理),当回来做Android的时候,发现很生疏,好些控件以前写得很顺手,现在好像忘记些什么了,总要打开这个项目,打开那个项目 ...

  7. 漂亮的提示框SweetAlert使用教程

    一.简介 所使用过的弹出框插件,SweetAlert是最好用的.发展至今,已经有两个版本,一个是原版 t4t5/sweetalert , 一个是分支版 limonte/sweetalert2 ,更新相 ...

  8. 关于winform窗体关闭时弹出提示框,选择否时窗体也关闭的问题

    在窗体中有FormClosing这个事件,这个事件是在窗体关闭时候运行的.如果要取消某个事件的操作,那么就在该事件中写上e.Cancel=true就能取消该事件,也就是不执行该事件.所以,你要在窗体关 ...

  9. c#winform程序,修改MessageBox提示框中按钮的文本

    用winform的MessageBox是实现不了的,这里我用的是DevExpress控件的XtraMessageBoxForm 例如如果想在一个提示框里修改"是","否& ...

随机推荐

  1. 转载:ODS简介

    什么是ODS? 信息处理的多层次要求导致了一种新的数据环境——DB-DW的中间层ODS(操作型数据存储)的出现.ODS是“面向主题的.集成的.当前或接近当前的.不断变化的”数据.通过统一规划,规范框架 ...

  2. c#新手之1-如何组织类及相互调用

    不知道这个文章的名字起的对不对,姑且这么叫吧.我在这之前用c语言写程序几乎很少用函数调用来解决问题,都是用全局变量然后面向过程对数据做简单的处理,这就造成了我在学习c@之后仍有这个毛病,好点的时候有个 ...

  3. Ubuntu user switch

    To list all users you can use: cut -d: -f1 /etc/passwd To add a new user you can use: sudo adduser n ...

  4. Data storage on the batch layer

    4.1 Storage requirements for the master dataset To determine the requirements for data storage, you ...

  5. 基于NodeJS的全栈式开发

    前言 为了解决传统Web开发模式带来的各种问题,我们进行了许多尝试,但由于前/后端的物理鸿沟,尝试的方案都大同小异.痛定思痛,今天我们重新思考了“前后端”的定义,引入前端同学都熟悉的 NodeJS,试 ...

  6. Web页中table导出到execl(带模板)

    1.将excel另存为html,将其复制到aspx文件中 2.输出格式为excel InitData(); Response.Clear(); Response.Buffer = true; Resp ...

  7. 用VS2010+Qt4.6.4编译QtAV

    http://blog.csdn.net/trustguan/article/details/45623891 如果在链接的过程中,出现以上错误: 1>MSVCRTD.lib(MSVCR100D ...

  8. 2、JS中的表达式和运算符

    一.表达式 1.原始表达式:2.14,“test”,true/false,null……复合表达式:10*20…… 2.数组.对象的初始化表达式:new Array(1,2),[1,undefined, ...

  9. C#中的var类型

    var关键字是C#3.0开始新增的特性,称为推断类型(其实也就是弱化类型的定义) . VAR可代替任何类型,编译器会根据上下文来判断你到底是想用什么类型,类似 OBJECT,但是效率比OBJECT高点 ...

  10. springmvc工作原理以及源码分析(基于spring3.1.0)

    springmvc是一个基于spring的web框架.本篇文章对它的工作原理以及源码进行深入分析. 一.springmvc请求处理流程 二.springmvc的工作机制 三.springmvc核心源码 ...