画多边形form并填充背景色(可以实现圆角边框 有锯齿)
public Form1()
{
InitializeComponent(); this.BackColor = ColorTranslator.FromHtml("#F7F1F1");
this.TransparencyKey = ColorTranslator.FromHtml("#F7F1F1");
this.label1.Text = "ccccccccccccccccccccccccccccc";
this.label1.BackColor = Color.White;
this.Opacity = ;
} protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
//ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Color.Orange, ButtonBorderStyle.Solid);
//Draw(e.ClipRectangle, e.Graphics, 80);
//Bitmap bitmap = new Bitmap(384, 305);
//for (int i = 0; i < bitmap.Height; i++)
//{
// bitmap.SetPixel(i, i, Color.Black);
//}
//bitmap.SetPixel(2, 2, Color.Black);
//e.Graphics.DrawImage(bitmap, new Point(0, 0));
//bitmap.Save(@"d:\c.png");
SolidBrush solidBrush = new SolidBrush(Color.White);
var gpath = DrawRoundRect(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height, );
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
e.Graphics.FillPath(solidBrush, gpath);
e.Graphics.DrawPath(Pens.White, gpath);
} /// <summary>
/// 设置窗体的Region
/// </summary>
public void SetWindowRegion()
{
GraphicsPath FormPath;
Rectangle rect = new Rectangle(, , this.Width, this.Height);
FormPath = GetRoundedRectPath(rect, );
this.Region = new Region(FormPath); }
/// <summary>
/// 绘制圆角路径
/// </summary>
/// <param name="rect"></param>
/// <param name="radius"></param>
/// <returns></returns>
private GraphicsPath GetRoundedRectPath(Rectangle rect, int radius)
{
int diameter = radius;
Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter));
GraphicsPath path = new GraphicsPath(); // 左上角
path.AddArc(arcRect, , ); // 右上角
arcRect.X = rect.Right - diameter;
path.AddArc(arcRect, , ); // 右下角
arcRect.Y = rect.Bottom - diameter;
path.AddArc(arcRect, , ); // 左下角
arcRect.X = rect.Left;
path.AddArc(arcRect, , );
path.CloseFigure();//闭合曲线
return path;
} /// <summary>
/// 窗体size发生改变时重新设置Region属性
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_Resize(object sender, EventArgs e)
{
//SetWindowRegion();
} //重绘边框
private void Draw(Rectangle rectangle, Graphics g, int radius)
{
SolidBrush solidBrush = new SolidBrush(Color.White);
Pen shadowPen = new Pen(solidBrush, );
g.SmoothingMode = SmoothingMode.HighQuality; g.CompositingQuality = CompositingQuality.HighQuality;
g.DrawPath(shadowPen, DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - , rectangle.Height - , radius));
}
public static GraphicsPath DrawRoundRect(int x, int y, int width, int height, int radius)
{
GraphicsPath gp = new GraphicsPath();
//gp.AddArc(x, y, radius, radius, 180, 90);
//gp.AddArc(width - radius, y, radius, radius, 270, 90);
//gp.AddArc(width - radius, height - radius, radius, radius, 0, 90);
//gp.AddArc(x, height - radius, radius, radius, 90, 90);
//gp.CloseAllFigures();
gp.AddArc(x, y, radius, radius, , );
gp.AddArc(width - , y, radius, radius, , );
gp.AddArc(width - radius, height - radius, radius, radius, , );
gp.AddArc(x, height - radius, radius, radius, , );
gp.CloseAllFigures();
return gp;
}
画多边形form并填充背景色(可以实现圆角边框 有锯齿)的更多相关文章
- 使用Java、Matlab画多边形闭合折线图
由于写论文要将“哈密顿回路问题(TSP)”的求解中间结果表示出来,查了一下使用程序画多边形图形.现在在总结一下,这个图是“由给定节点首尾相连的”闭合多边形. 1.使用matlab作闭合多边形图 没有找 ...
- 【编程漫谈】用JAVA画多边形
一门语言只要带图形库就可以编程画图了,用JAVA画图有两种方式,一是在内存中画好然后生成图片,就可以看到画图的效果了.另一个就是在窗口界面上直接画,可以实时看到程序的运行效果.刚开始学编程的时候,我加 ...
- 最全vue的vue-amap使用高德地图插件画多边形范围
一.在vue-cli的框架下的main.js(或者main.ts)中引入高德插件,代码如下: import Vue from 'vue' import VueAMap from 'vue-amap' ...
- 一个给力的html5 画多边形的例子
只需改变参数就能画出你想要的多边形,代码简单!不得不惊叹canvas的强大! 代码奉上 <!doctype html> <html> <head> <meta ...
- canvas画多边形
<canvas id = "myCanvas" width = '500' height = '500'> Canvas画正多边形 </canvas>< ...
- OpenLayers 根据坐标动态画多边形
找了一上午,发现都是鼠标点击画框的,那为什么不标明了是 “鼠标”点击 呢? 想实现的功能是数据库检索坐标集合,然后根据分组提取4点坐标,最后把多个多边形形成图层放在地图上. 最后的实现: <!D ...
- qt 画多边形(实现鼠标拖动节点)
---恢复内容开始--- 2018-01-06 这个小例子实现了移动鼠标,鼠标的坐标信息跟随鼠标移动,多边形的实现,鼠标点击可以拖动多边形点的位置,(其中有个问题?我在QMainWindow下,用mo ...
- Scratch编程:画多边形(八)
“ 上节课的内容全部掌握了吗?反复练习了没有,编程最好的学习方法就是练习.练习.再练习.一定要记得多动手.多动脑筋哦~~” 01 — 游戏介绍 这节我们将实现:程序提示用户输入数据,然后根据用户的输入 ...
- SDL系列之 - 用SDL动态地画一个圆喽 && 设置背景色
#include <SDL.h> #include <stdlib.h> #include <string.h> #include <math.h> # ...
随机推荐
- JBPM工作流(八)——流程实例(PI)Process Instance
/** * 流程实例 * * 启动流程实例 * * 完成任务 * * 查询 * * 查询流程实例 * * 查询任务 * * 查询正在 ...
- SSIS - 1.简介
一.什么是SSIS? 1)SSIS全称为Microsoft SQL Server Integration Services. 2)ETL全称为Extraction, Transformation an ...
- 如何组织AxTOCControl里面的数据
如何组织AxTOCControl里面的数据,实际上是组织AXMapControl的数据,将添加的数据进行整理.代码在最后面. 思路参考自: https://blog.csdn.net/u0124887 ...
- memcached加固
Memcached服务安全加固 更新时间:2017-06-30 10:07:49 漏洞描述 Memcached是一套常用的key-value缓存系统,由于它本身没有权限控制模块,所以对公网开放的 ...
- SVN百度云服务器安装使用。
安装SVN客户端 此时,必须重启,否则经常出现用不了. 重启后,还是用不了的话,那么就重新安装系统. 网站地址: http://xiaomosheng.bceapp.com/ SVN代码服务器的地址: ...
- APICloud |UIChatTools 模块demo
UIChatTools 模块是一个聊天输入框模块,开发者可自定义该输入框的功能.通过 open 接口可在当前 window 底部打开一个输入框,该输入框的生命属于当前 window 所有.当输入框获取 ...
- 2018-2019-2 20165225『网络对抗技术』Exp2:后门原理与实践
2018-2019-2 20165225『网络对抗技术』Exp2:后门原理与实践 一.实验说明 任务一:使用netcat获取主机操作Shell,cron启动 (0.5分) 任务二:使用socat获取主 ...
- 微信小程序轮播图组件 swiper,swiper-item及轮播图片自适应
官网地址:https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html index.wxml文件 indicator-d ...
- 学习h264 的语法规则,如何才能看懂H264 的官方文档
1. 今天想查h264 的帧率,查找资料如下: 首先要解析sps,得到两个关键的数值: num_units_in_tick, time_scale fps=time_scale/num_units_i ...
- 玩转Vuejs--数组监听
Vue中对数据的监听主要是依靠Object.defineProperty来实现的,这种实现主要是针对key/value形式的对象,对数组中值的变化是无能为力的,那么该如何对数组中的数据进行监听呢,下面 ...