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并填充背景色(可以实现圆角边框 有锯齿)的更多相关文章

  1. 使用Java、Matlab画多边形闭合折线图

    由于写论文要将“哈密顿回路问题(TSP)”的求解中间结果表示出来,查了一下使用程序画多边形图形.现在在总结一下,这个图是“由给定节点首尾相连的”闭合多边形. 1.使用matlab作闭合多边形图 没有找 ...

  2. 【编程漫谈】用JAVA画多边形

    一门语言只要带图形库就可以编程画图了,用JAVA画图有两种方式,一是在内存中画好然后生成图片,就可以看到画图的效果了.另一个就是在窗口界面上直接画,可以实时看到程序的运行效果.刚开始学编程的时候,我加 ...

  3. 最全vue的vue-amap使用高德地图插件画多边形范围

    一.在vue-cli的框架下的main.js(或者main.ts)中引入高德插件,代码如下: import Vue from 'vue' import VueAMap from 'vue-amap' ...

  4. 一个给力的html5 画多边形的例子

    只需改变参数就能画出你想要的多边形,代码简单!不得不惊叹canvas的强大! 代码奉上 <!doctype html> <html> <head> <meta ...

  5. canvas画多边形

    <canvas id = "myCanvas" width = '500' height = '500'> Canvas画正多边形 </canvas>< ...

  6. OpenLayers 根据坐标动态画多边形

    找了一上午,发现都是鼠标点击画框的,那为什么不标明了是 “鼠标”点击 呢? 想实现的功能是数据库检索坐标集合,然后根据分组提取4点坐标,最后把多个多边形形成图层放在地图上. 最后的实现: <!D ...

  7. qt 画多边形(实现鼠标拖动节点)

    ---恢复内容开始--- 2018-01-06 这个小例子实现了移动鼠标,鼠标的坐标信息跟随鼠标移动,多边形的实现,鼠标点击可以拖动多边形点的位置,(其中有个问题?我在QMainWindow下,用mo ...

  8. Scratch编程:画多边形(八)

    “ 上节课的内容全部掌握了吗?反复练习了没有,编程最好的学习方法就是练习.练习.再练习.一定要记得多动手.多动脑筋哦~~” 01 — 游戏介绍 这节我们将实现:程序提示用户输入数据,然后根据用户的输入 ...

  9. SDL系列之 - 用SDL动态地画一个圆喽 && 设置背景色

    #include <SDL.h> #include <stdlib.h> #include <string.h> #include <math.h> # ...

随机推荐

  1. jsp 自定义标签解决jsp页面中int时间戳的时间格式化问题

    jsp 自定义标签解决jsp页面中int时间戳的时间格式化问题 之前在项目中根据需求,需要自定义标签,经过查询w3c文档,自己也踩了一些坑,特此记录自定义标签的步骤,下面就以我之前的一个例子中的定义一 ...

  2. Linux命令 file

    查看文件类型:

  3. C#获取项目程序及运行路径的方

    1.asp.net webform用“Request.PhysicalApplicationPath获取站点所在虚拟目录的物理路径,最后包含“\”:   2.c# winform用 A:“Applic ...

  4. ide phpStorm 配置PHP路径并本地执行PHP脚本

    1.打开设置(File - Settings) 2. 3. 4.到需要执行脚本的文件处,右击 - Run 5.如果本地还未安装PHP,可以下载Xampp,并将PHP目录新增至系统环境变量Path处,重 ...

  5. python摸爬滚打之day28----黏包处理

    1.缓冲区和subprocess模块 1.1  缓冲区( 当send()内容超过输入缓冲区大小或recv()接收内容超过输出缓冲区大小时旧版本(py3.5以前)是会直接报错的, py3.5以后如果出错 ...

  6. Elasticsearch学习笔记(十)批量查询mget、批量增删改bulk

    一.批量查询  mget             GET /_mget {   "docs":[       {         "_index":" ...

  7. lnmp 切换PHP版本,并且安装swoole

    lnmp 切换php版本 进入 lnmp 安装的目录,进入install.sh 的目录执行: sudo ./install.sh mphp 备注: find / -name install.sh 备注 ...

  8. note_The Top Risks of Requirements Engineering

    The risk is greatest at several points: 1. Overlooking a crucial requirement This one the greatest r ...

  9. AES加密解密 助手类 CBC加密模式

    "; string result1 = AESHelper.AesEncrypt(str); string result2 = AESHelper.AesDecrypt(result1); ...

  10. Go 初体验 - 并发与锁.1 - sync.Mutex 与 sync.RWMutex

    ==== Mutex为互斥锁,顾名思义,被Mutex锁住的代码同时只允许一个协程访问,其它协程进来就要排队 如何使用?看代码: 输出: 释义: 并发1000个协程同时更改m的元素,这样会有一部分更改成 ...