winform学习之----重新绘制边框方法延伸
方法1、
Pen pen1 = new Pen(Color.FromArgb(233, 149, 87));
e.Graphics.DrawRectangle(pen1, new Rectangle(0, 0, this.Width - 1, this.Height - 1));
方法2、
Rectangle myRectangle = new Rectangle(0, 0, this.Width, this.Height);
ControlPaint.DrawBorder(e.Graphics, myRectangle,
Color.FromArgb(0, 0, 0), 2, ButtonBorderStyle.Solid,
Color.FromArgb(0, 0, 0), 2, ButtonBorderStyle.Solid,
Color.FromArgb(0, 0, 0), 2, ButtonBorderStyle.Solid,
Color.FromArgb(0, 0, 0), 2, ButtonBorderStyle.Solid
);
对比:
一、Winform Panel边框方法一:每边能设置不同的颜色、宽度和样式
1、拖一个 Panel控件到主窗体中,保持默认名称 panel1,BorderStyle 选择 Fixed3D。
2、双击 Panel1,打开后台代码文件,在 panel1_Paint(object sender, PaintEventArgs e) 方法中添加如下代码:
private void panel1_Paint(object sender, PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics, panel1.ClientRectangle,
Color.White, 1, ButtonBorderStyle.Solid, //左边
Color.White, 1, ButtonBorderStyle.Solid, //上边
Color.DimGray, 1, ButtonBorderStyle.Solid, //右边
Color.DimGray, 1, ButtonBorderStyle.Solid);//底边
}
每边共有三个参数,分别为:边框颜色、宽度和样式;如果把 1 改为 0,则覆盖原来的边框,否则颜色搭配得当将出现凹凸边框效果,示例运行效果如图1所示:

图1
如果 BorderStyle 选择 None,则又是另外一种效果(边框内突起)。
二、Winform Panel边框方法二:每边样式一样
步骤跟方法一一样,只是在 panel1_Paint(object sender, PaintEventArgs e) 方法中添加如下代码:
private void panel1_Paint(object sender, PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.Ivory, ButtonBorderStyle.Solid);
}
每边都设置为同一风格,即相同的颜色、宽度和样式。
三、推荐重绘边框的方法
private void panelAll_Paint(object sender, PaintEventArgs e)
{
Rectangle myRectangle = new Rectangle(0, 0, this.panelAll.Width, this.panelAll.Height);
ControlPaint.DrawBorder(e.Graphics, myRectangle,
System.Drawing.Color.FromArgb(((int)(((byte)(245)))), ((int)(((byte)(145)))), ((int)(((byte)(28))))), 2, ButtonBorderStyle.Solid,
System.Drawing.Color.FromArgb(((int)(((byte)(245)))), ((int)(((byte)(145)))), ((int)(((byte)(28))))), 2, ButtonBorderStyle.Solid,
System.Drawing.Color.FromArgb(((int)(((byte)(245)))), ((int)(((byte)(145)))), ((int)(((byte)(28))))), 2, ButtonBorderStyle.Solid,
System.Drawing.Color.FromArgb(((int)(((byte)(245)))), ((int)(((byte)(145)))), ((int)(((byte)(28))))), 2, ButtonBorderStyle.Solid
);
}此方法可以避免一些重绘时发生的错误。
winform学习之----重新绘制边框方法延伸的更多相关文章
- iOS学习——Quartz2D学习之UIKit绘制
iOS学习——Quartz2D学习之UIKit绘制 1.总述 在IOS中绘图技术主要包括:UIKit.Quartz 2D.Core Animation和OpenGL ES.其中Core Animati ...
- HTML5学习总结——canvas绘制象棋(canvas绘图)
一.HTML5学习总结——canvas绘制象棋 1.第一次:canvas绘制象棋(笨方法)示例代码: <!DOCTYPE html> <html> <head> & ...
- Winform学习手册(目录)
一.基础: WINFORM学习笔记——创建Winform项目 WINFORM学习手册——TextBox.Lable.Button WINFORM学习笔记——窗体生命周期 WINFORM学习手册——对话 ...
- OpenGL入门学习 课程 (三) 绘制几何图形的一些细节问题
http://oulehui.blog.163.com/blog/static/79614698201191832753312/ 先回顾一下我们都学习了些什么: 第一课,编写第一个OpenGL程序第二 ...
- winform重绘控件边框
首先添加一个用户控件 对于重绘边框有三个需要考虑的东西 1:是否显示边框 2:边框颜色 3:边框宽度 所以定义三个私有变量 /// <summary>/// 是否显示边框/// </ ...
- 转载:WinForm中播放声音的三种方法
转载:WinForm中播放声音的三种方法 金刚 winForm 播放声音 本文是转载的文章.原文出处:http://blog.csdn.net/jijunwu/article/details/4753 ...
- C# Winform中DataGridView的DataGridViewCheckBoxColumn使用方法
下面介绍Winform中DataGridView的DataGridViewCheckBoxColumn使用方法: DataGridViewCheckBoxColumn CheckBox是否选中 在判断 ...
- WPF2D绘制图形方法
我们先看看效果如何: xaml文件: <Window x:Class="WPF2D绘制图形方法.MainWindow" xmlns="http://schemas. ...
- WPF3D学习,立方体的绘制
原文:WPF3D学习,立方体的绘制 以此为一个好的开始吧!一直都太懒,坚持写文章是个不错的开始!碰巧最近在研究WPF3D这块的知识,也为了练练自己的写作水平,整理这篇文章.新手上路,多多关照! 本文先 ...
随机推荐
- WebSite和WebApplication的区别
1. WebApplication(Web应用程序)和WebSite(网站)的区别:WebSite是为了兼容从ASP转过来的开发人员的习惯而存在的,用起来简单,例如:不需要创建命名控件.C#代码修改以 ...
- Hydra---Linux下的暴力美学
引自:http://www.cnblogs.com/mchina/archive/2013/01/01/2840815.html 安装:http://www.91ri.org/2867.html yu ...
- C++ traits
[本文链接] http://www.cnblogs.com/hellogiser/p/cplusplus-traits.html [分析] 什么是traits?其实它并不是一个新的概念,上个世纪90年 ...
- iOS 和 Android 触摸事件传递
先看文章,写得很好 ios 触摸事件传递 http://www.cnblogs.com/Quains/p/3369132.html 另外一篇 http://blog.csdn.net/yongyinm ...
- Java for LeetCode 152 Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- 【VirtualBox】端口转发,ssh
端口转发 VirualBox的设置 - 网络 - 端口转发 里面有主机IP.主机端口.子系统IP.子系统端口 设置后的含义是:当外部访问主机IP:主机端口后,将会把访问映射到虚拟机的子系统IP和子系统 ...
- google maps js v3 api教程(2) -- 在地图上添加标记
原文链接 google maps javascript官方文档:https://developers.google.com/maps/documentation/javascript/ 我们在创建地图 ...
- 铺地毯(luogu 1003)
题目描述 为了准备一个独特的颁奖典礼,组织者在会场的一片矩形区域(可看做是平面直角坐标系的第一象限)铺上一些矩形地毯.一共有 n 张地毯,编号从 1 到n .现在将这些地毯按照编号从小到大的顺序平行于 ...
- mysql 主主复制(双主复制)+ 配置KEEPALIVED实现热备
binlog-do-db和replicate-do-db表示需要同步的数据库 binlog-ignore-db和replicate-ignore-db表示不需要同步的数据库 云端服务器为master配 ...
- [原]AppPoolService-IIS应用程序池辅助类(C#控制应用程序池操作)
using System.Collections.Generic; using System.DirectoryServices; using System.Linq; using Microsoft ...