winform下自绘提示框风格窗体
昨天分享了一个环形滚动条控件,今天分享一个提示框风格的窗体。代码如下:
/// <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下自绘提示框风格窗体的更多相关文章
- winform下的智能提示框
winform下的智能提示框 最近在搞winform的程序,接触到有些可能以后还会用到的功能,所以写到博客园里去,第一可以加深自己的印象,第二可以在以后再遇到同样问题的时候忘记了可以马上回来看看,第三 ...
- WinForm下增加声音提示
在WinForm平台下播放声音,一般有两种方式:第一种是调用系统自带声音: [代码] 申明定义: [DllImport("kernel32.dll")] public static ...
- UIWebView 自定义网页中的alert和confirm提示框风格
.h #import <UIKit/UIKit.h> @interface UIWebView (JavaScriptAlert) -(void)webView:(UIWebView *) ...
- (十八)c#Winform自定义控件-提示框
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- 重绘DevExpress的XtraMessageBox消息提示框控件
先来看提示框,可以看到框其实是一个去掉最大化.最小化按钮后的窗体,窗体的内容就是我们想要提示的内容,重绘提示框其实就是重绘窗体以及中间部分的内容. 首先重绘窗体,消息提示框的窗体不是XtraForm而 ...
- Android 代码库(自定义一套 Dialog通用提示框 )
做Android开发五年了,期间做做停停(去做后台开发,服务器管理),当回来做Android的时候,发现很生疏,好些控件以前写得很顺手,现在好像忘记些什么了,总要打开这个项目,打开那个项目 ...
- 漂亮的提示框SweetAlert使用教程
一.简介 所使用过的弹出框插件,SweetAlert是最好用的.发展至今,已经有两个版本,一个是原版 t4t5/sweetalert , 一个是分支版 limonte/sweetalert2 ,更新相 ...
- 关于winform窗体关闭时弹出提示框,选择否时窗体也关闭的问题
在窗体中有FormClosing这个事件,这个事件是在窗体关闭时候运行的.如果要取消某个事件的操作,那么就在该事件中写上e.Cancel=true就能取消该事件,也就是不执行该事件.所以,你要在窗体关 ...
- c#winform程序,修改MessageBox提示框中按钮的文本
用winform的MessageBox是实现不了的,这里我用的是DevExpress控件的XtraMessageBoxForm 例如如果想在一个提示框里修改"是","否& ...
随机推荐
- DEV控件,PopupContainerEdit,PopupContainerControl,TreeList,弹出控制问题
功能描述 PopupContainerEdit的PopupControl设置为PopupContainerControl, PopupContainerControl的里面放一个TreeList, T ...
- python分割字符串split,filter函数用法
现有字符串,需要取出用空格分隔的第一段,操作如下 >>> product_model = ‘WS-C2960G-24TC-L – Fixed Module 0′>>> ...
- Ubuntu中添加eclipse
环境:Ubuntu 14.04 步骤: 1.安装配置JDK,详见 http://my.oschina.net/u/1407116/blog/227084 2.下载eclipse 从官网http://w ...
- cocos2dx 3.8版关于#include "GB2ShapeCache-x.h"
关于coco2d-x 3.8版的PhysicsEditor.exe1.09版的GB2ShapeCache-x.h.cpp中有些方法更新了和容器的使用方法,还有就是头文件include "CC ...
- equals 与 ==
Object类中,方法equals():boolean equals(Object obj) { return this==obj;} == 比较两个变量的值是否相等,对于基本类型,==直接比较变 ...
- BZOJ 3809 莫队+(分块|BIT)
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> ...
- Xcode与OX 版本对照表
xcode1.0-xcode2.x 版本 OS X运行版本 OS X SDK(s) 1.0 OS X Panther(10.3.x) OS X Puma(10.1.x),OS X Jaguar(10. ...
- (实用篇)PHP中unset,array_splice删除数组中元素的区别
php中删除数组元素是非常的简单的,但有时删除数组需要对索引进行一些排序要求我们会使用到相关的函数,这里我们来介绍使用unset,array_splice删除数组中的元素区别吧 如果要在某个数组中删除 ...
- “__doPostBack”未定义
项目中发现IE10等高级浏览器报错 ASP.NET无法检测IE10,导致_doPostBack未定义JavaScript错误 为此微软工程师解释如果发布asp2.0 asp4.0发布时,这些浏览器还未 ...
- js 函数和变量的提升
js 函数和变量的提升 1. 函数的作用域: js中 ,函数的作用域为函数,而不是大括号. var hei = 123;if(true){ hei = 456;}console.log(hei);// ...