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

/// <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. hdu 1041 (OO approach, private constructor to prevent instantiation, sprintf) 分类: hdoj 2015-06-17 15:57 25人阅读 评论(0) 收藏

    a problem where OO seems more natural to me, implementing a utility class not instantiable. how to p ...

  2. SQL实践中的50句

    一个项目涉及到的50个Sql语句(整理版)--1.学生表Student(S,Sname,Sage,Ssex) --S 学生编号,Sname 学生姓名,Sage 出生年月,Ssex 学生性别--2.课程 ...

  3. 如何取消win10电脑自动更新

    windows 10系统中关闭windows自动更新步骤如下:1.按键盘上的“Windows徽标键+R”组合键,可以调出“运行”窗口. 2.输入gpedit.msc,单击“确定”,可以打开“本地组策略 ...

  4. git merge 和 rebase 区别

    git pull  超级不推荐使用git pull 有坑,谨慎使用,pull底层是merge git pull 是 git fetch + git merge FETCH_HEAD 的缩写.所以,默认 ...

  5. SqlServer性能优化 手工性能收集动态管理视图(三)

    动态管理视图: 具体的实例语句:  --关于语句执行的基本情况 select * from sys.dm_exec_query_stats --动态管理函数  需要提供参数  select top 1 ...

  6. Spring利器之包扫描器

    在学习Spring这门技术中为了大大减少applicationContext.xml配置的代码量于是有了包扫描器. 闲话不多说我们马上来实现一下吧 示例架构如下: 第一步我们先来修改我们的配置appl ...

  7. Android FM模块学习之三 FM手动调频

    前一章主要是FM的自动调频, 接下来我们就看看FM手动调频是如何进行的.如果不清楚FM自动调频的过程,请打开超链接查看FM搜索频率流程. 首先来看一下流程图: 2.滑动刻度盘HorizontalNum ...

  8. day13_API第三天

    1.StringBuffer类(掌握) 1.概念      字符串缓冲区类 2.机制      StringBuffer采用的是缓冲区机制. 一开始,首先开辟一些空间,然后,随着数据的增多,还可以继续 ...

  9. JAVA入门第二季 第一章 类和对象

    面向对象编程 Object Oriented Programming OOP 第一.什么是类和对象 在具体说明类和对象之前,先说说别的. 眼睛在人类身体上最为有用的器官.如果一个没有了眼睛,这个人与世 ...

  10. LintCode Binary Tree Level Order Traversal

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...