方法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学习之----重新绘制边框方法延伸的更多相关文章

  1. iOS学习——Quartz2D学习之UIKit绘制

    iOS学习——Quartz2D学习之UIKit绘制 1.总述 在IOS中绘图技术主要包括:UIKit.Quartz 2D.Core Animation和OpenGL ES.其中Core Animati ...

  2. HTML5学习总结——canvas绘制象棋(canvas绘图)

    一.HTML5学习总结——canvas绘制象棋 1.第一次:canvas绘制象棋(笨方法)示例代码: <!DOCTYPE html> <html> <head> & ...

  3. Winform学习手册(目录)

    一.基础: WINFORM学习笔记——创建Winform项目 WINFORM学习手册——TextBox.Lable.Button WINFORM学习笔记——窗体生命周期 WINFORM学习手册——对话 ...

  4. OpenGL入门学习 课程 (三) 绘制几何图形的一些细节问题

    http://oulehui.blog.163.com/blog/static/79614698201191832753312/ 先回顾一下我们都学习了些什么: 第一课,编写第一个OpenGL程序第二 ...

  5. winform重绘控件边框

    首先添加一个用户控件 对于重绘边框有三个需要考虑的东西 1:是否显示边框 2:边框颜色 3:边框宽度 所以定义三个私有变量 /// <summary>/// 是否显示边框/// </ ...

  6. 转载:WinForm中播放声音的三种方法

    转载:WinForm中播放声音的三种方法 金刚 winForm 播放声音 本文是转载的文章.原文出处:http://blog.csdn.net/jijunwu/article/details/4753 ...

  7. C# Winform中DataGridView的DataGridViewCheckBoxColumn使用方法

    下面介绍Winform中DataGridView的DataGridViewCheckBoxColumn使用方法: DataGridViewCheckBoxColumn CheckBox是否选中 在判断 ...

  8. WPF2D绘制图形方法

    我们先看看效果如何: xaml文件: <Window x:Class="WPF2D绘制图形方法.MainWindow" xmlns="http://schemas. ...

  9. WPF3D学习,立方体的绘制

    原文:WPF3D学习,立方体的绘制 以此为一个好的开始吧!一直都太懒,坚持写文章是个不错的开始!碰巧最近在研究WPF3D这块的知识,也为了练练自己的写作水平,整理这篇文章.新手上路,多多关照! 本文先 ...

随机推荐

  1. linux之eval用法(高级bash程序员的必修之技)

    1. eval command-line 其中command-line是在终端上键入的一条普通命令行.然而当在它前面放上eval时,其结果是shell在执行命令行之前扫描它两次.如: pipe=&qu ...

  2. maven项目,导入的jar包,没有包含在pom文件中,install失败

    [INFO] BUILD FAILURE[INFO] ------------------------------------------------------------------------[ ...

  3. 28. 字符串的全排列之第2篇[string permutation with repeating chars]

    [本文链接] http://www.cnblogs.com/hellogiser/p/string-permutation-with-repeating-chars.html [题目] 输入一个字符串 ...

  4. 设置windows网络连接别名和linux网络连接别名

    windows网络连接别名 C:\Windows\System32\drivers\etc目录下的hosts文件中添加 127.0.0.1 localhost 192.168.1.100 proxy. ...

  5. CI框架初探

    2014年7月3日 17:39:35 简易版: index.php->codeIgniter.php->找到控制器类文件并include->创建实例->执行成员函数 详细版本: ...

  6. 2.saltstack笔记之目标,模块,返回写入数据库

    作者:刘耀 QQ:22102107 一.目标(targeting Minions) 1.匹配Minions Id 匹配所有 (*) [root@node1 salt]# salt '*' test.p ...

  7. Google map测量工具

    启用Google map的测量工具,测量图上的距离. 打开Google map,左下角看到Google 地图实验室,点开,然后enable相应功能即可. 通过Google map lab还能使我们能够 ...

  8. ubuntu 14.04安装mysql server & mysql client

    $ sudo apt-get install mysql-server

  9. [VSTS]让ADO.NET Entity Framework支持Oracle数据库(转载)

    近期由于项目所需不得不研究Oracle数据库,回想上一次用Oracle还是07年的事情,实习时候做华晨宝马的项目简单接触了Oracle.这次的项目需要基于.NET平台,我个人的习惯是能用微软自带的就不 ...

  10. Web Service 其他服务器检测不到查询测试按钮

    1.Web Service 其他服务器检测不到查询测试按钮,config需要修改地方: <system.web> <webServices> <protocols> ...