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

/// <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 = 50;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(-1, -1);GraphicsPath border = GetTipPath(rect);GraphicsPath curve = new GraphicsPath();graph.DrawPath(new Pen(Color.Black,2), 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 / 2,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, 270, -90);path.AddArc(rect.X, rect.Y + height - Radius, Radius, Radius, 180, -90);path.AddLine(new Point(rect.X + Radius / 2, rect.Y + height),new Point(rect.X + rect.Width / 2 - Radius / 2,rect.Y + height));path.AddLine(new Point(rect.X + rect.Width / 2 - Radius / 2,rect.Y + height),new Point(rect.X + rect.Width / 2, rect.Y + height + Radius));path.AddLine(new Point(rect.X + rect.Width / 2, rect.Y + height + Radius),new Point(rect.X + rect.Width / 2 + Radius / 2,rect.Y + height));path.AddLine(new Point(rect.X + rect.Width / 2 + Radius / 2,rect.Y + height),new Point(rect.X + rect.Width - Radius / 2,rect.Y + height));path.AddArc(rect.X + rect.Width - radius, rect.Y + height - Radius, Radius, Radius, 90, -90);path.AddArc(rect.X + rect.Width - Radius, rect.Y, Radius, Radius, 0, -90);path.AddLine(new Point(rect.X + rect.Width - Radius / 2, rect.Y), new Point(rect.X + Radius / 2, 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 / 4 - 32,ClientRectangle.Y + Radius / 4);btnClose.Location = pt;}}

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

转载于:https://www.cnblogs.com/lvniao/p/4156182.html

winform下自绘提示框风格窗体相关推荐

  1. ajax弹出提示框,Ajax环境下弹出提示框

    在普通的ASP.NET环境中,我们要想在WEB窗体上弹出一个对话框,经常用到的是如下代码: Response.Write(""); 然而在Ajax的环境中却不能使用上述的代码,否则 ...

  2. Winform下ToolStrip承载自定义控件或 Windows 窗体控件。

     如题,使用ToolStripControlHost. 先看MSDN上介绍的: ToolStripControlHost  是 ToolStripComboBox.ToolStripTextBox ...

  3. swal 弹窗html页面,SweetAlert - 演示6种不同的提示框效果

    SweetAlert是一款不需要jQuery支持的原生js提示框,风格类似bootstrap.它的提示框不仅美丽动人,并且允许自定义,支持设置提示框标题.提示类型.内容展示图片.确认取消按钮文本.点击 ...

  4. 21、高级工具--来电归属地提示框的位置设置

    创建设置提示框位置的activity:DragViewActivity以及布局文件. 代码: package com.example.mobilesafe;import android.app.Act ...

  5. ECharts 提示框组件Tooltip属性大全(包含文本注释)

    tooltip: { // 提示框组件:可以设置在全局(tooltip),可以设置在坐标系中(grid.tooltip.polar.tooltip.single.tooltip),可以设置在系列中(s ...

  6. 编程语言详细介绍c#消息提示框messagebox的使用

    编程语言详细介绍c#消息提示框messagebox的使用 这篇文章主要介绍了c#消息提示框messagebox的详解及使用的相关资料,需要的朋友可以参考下 C#消息提示框messagebox的详解及使 ...

  7. Winform的消息提示框帮助类

    一.Winform的消息提示框帮助类初衷 通常在C#的Winform项目开发中,我们也会经常需要使用提示框用于用户操作的提示确认,起到一个确认,警示的作用,由于这也是一个十分常见的功能,因此该帮助类就 ...

  8. ios numlock_从“提示”框:默认情况下启用NumLock,无广告的iOS应用和立体声供电的派对灯...

    ios numlock Once a week we round up some of the great tips readers have sent into the tip box. This ...

  9. 三、bootstrap4 组件(警告和提示框、徽章和面包屑、按钮按钮组、卡片、列表组、导航和选项卡、分页和进度条、巨幕和旋转图标、轮播图、折叠菜单、下拉菜单、导航条、滚动监听、轻量弹框、模态框、表单)

    1.1 警告提示框 1.2 徽章和面包屑 1.3 按钮和按钮组 1.4 卡片 1.5 列表组 1.6 导航和选项卡 1.7 分页和进度条 1.8 巨幕和旋转图标 1.9 轮播图 1.10 折叠菜单 1 ...

最新文章

  1. 【转】matlab函数_连通区域
  2. C++知识点26——使用C++标准库(常用的泛型算法1)
  3. Ubuntu设置root密码
  4. (已加马赛克)10 行代码判定色*情*图片——Python 也可以系列之二
  5. zend studio配置mysql_Zend studio for eclipse中使php可以调用mysql相关函数的设置方法
  6. 【LeetCode】LeetCode之删除并获得点数——动态规划、排序+动态规划
  7. python缩进格式作用_关于自动缩进格式问题,高手帮忙!
  8. android 自定义switch控件,Android中switch自定义样式
  9. arcgis 属性表 汇总_Arcgis中遥感影像地理配准、矢量化与地图制作
  10. GooglePerformanceTools--tcmalloc
  11. 街头霸王背景_街头霸王与摇滚明星:开放式领导的艺术
  12. Aptana 开发环境执行时默认的工作路径
  13. ehlib的DBGridEh控件中使用过滤功能的方法
  14. Linux硬链接和符号链接(转)
  15. linux iptables服务及相关命令
  16. SQL Server表空间碎片化回收
  17. html中calc属性什么意思,CSS3中新属性calc()的详细介绍
  18. 2021-09-16收集一些可以发外链的网站
  19. IntelliJ IDEA 单词表--01
  20. iis7 下php 环境配置文件,Win7下在IIS7中配置PHP的环境

热门文章

  1. Redis之Ubuntu开机启动
  2. 每天一个linux 命令 find命令
  3. Postgres_XL 简要安装配置说明
  4. 在Google使用Borg进行大规模集群的管理 5-6
  5. 后续:为LAMP添加XCache加速。
  6. 很经典的独白,搞网络的童鞋们,你们懂得
  7. [Case] “凭心而论,在这家公司很敬业的工作了3年多,老板最后给我下的评语,大家都看看吧,千万别和我走同一条路!”(摘自csdn)...
  8. 将SublimeText加入右键菜单
  9. python批量裁剪图片_用Python写了一个图片格式批量处理工具
  10. rfc 查看工具_用于系统管理员的杀手级工具,Skype替代品,提高Linux技能,6个必读的RFC等