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这块的知识,也为了练练自己的写作水平,整理这篇文章.新手上路,多多关照! 本文先 ...
随机推荐
- PHP读取csv文件
<?php //取数据 $f_d = file_get_contents('tpl_import_info.csv'); $f_d = iconv('gbk', 'utf-8', $f_d); ...
- mysql 表空间
开启了Innodb的innodb_file_per_table这个参数之后[innodb_file_per_table = 1],也就是启用InnoDB的独立表空间模式,便于管理.此时,在新建的inn ...
- ubuntu下Tomcat7的安装和配置
和前几个软件一样,Tomcat 同样是由JAVA开发的,所以,在安装前一定要装好JDK. 大家可以到 http://tomcat.apache.org/download-70.cgi 下载最新的Tom ...
- Ubuntu下装QQ2014
1.首先我们需要下载一个 deb的 Wine QQ安装包 qq2014官方下载:http://www.longene.org/download/WineQQ2013SP6-20140102-Longe ...
- css3学习总结5--CSS3文本效果
CSS3 文本效果 1. text-shadow 2. word-wrap text-shadow属性使用方法 text-shadow属性使用方法如下所示. text-shadow:length le ...
- 何时使用hadoop fs、hadoop dfs与hdfs dfs命令(转)
hadoop fs:使用面最广,可以操作任何文件系统. hadoop dfs与hdfs dfs:只能操作HDFS文件系统相关(包括与Local FS间的操作),前者已经Deprecated,一般使用后 ...
- C++ 中 volatile 的使用
一.作用 volatile的作用是: 作为指令关键字,确保本条指令不会因编译器的优化而省略,且要求每次直接读值. 简单地说就是防止编译器对代码进行优化.比如如下程序:XBYTE[2]=0x55;XBY ...
- UML从需求到实现----包图
上接:UML中图出现顺序 上回讲到用例图,UML中各个图之间的关系.接着根据UML建模中图出现的顺序来总结包图. 用例图确定以后.用户的需求基本上就确定了.接下来要根据用户的要求去设计系统.建模的顺序 ...
- php文件上传类
<?php header("Content-Type:text/html; charset=utf-8"); if($_POST['submit']){ $upfiles = ...
- Gym 100637F F. The Pool for Lucky Ones
F. The Pool for Lucky Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...