方法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. sublime text多文件夹查找关键字

    Ctrl+shift+F 快捷键在文件夹内查找,与普通编辑器不同的地方是sublime允许添加多个文件夹进行查找 转自:http://www.douban.com/note/362268947/

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

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

  3. 18.用两个栈实现队列[2StacksToImplementQueue]

    [题目] 某队列的声明如下:  C++ Code  123456789101112131415   template<typename T> class CQueue { public: ...

  4. Cocos2d 初学基本知识

    1. 纹理(Texture) 游戏角色的图像文件在使用前必须解压缩,并转换成 iPhone 和 iPad 的 GPU 可以理解的 格式,同时要加载进 RAM(随机存储器),这样的图像称为纹理.GPU ...

  5. iOS xib中TableView创建的2种模式

    在xcode 5.0中 用xib编辑tableview有2种模式,见下图 其中,dynamic prototype 动态原型 表示tableview会询问它指定的 data source获取数据,如果 ...

  6. 8.python笔记之面向对象基础

    title: 8.Python笔记之面向对象基础 date: 2016-02-21 15:10:35 tags: Python categories: Python --- 面向对象思维导图 (来自1 ...

  7. javascript类的类比详解-大白话版

    转载请注明出处:水车 如果有误,还望指出,谢谢 -----------------正文分割线---------------------- 类:类太抽象,要想弄明白就该用现实的东西来类比 在我看来类就是 ...

  8. java 格式化时间

    java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); form ...

  9. 在eclipse中打开项目所在的目录

    展开如下菜单: Run ---- External Tools ---- External Tools Configurations   在 program 下面新建一个工具 program--右击- ...

  10. Linux开发cocos2dx程序环境搭建

    安装linux系统,ubuntu 14.04 64位 安装支持软件 sudo apt-get update sudo apt-get install git ssh vim ctags qt-sdk ...