欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#通過(guò)重寫Panel改變邊框顏色與寬度的方法

 更新時(shí)間:2015年08月21日 15:29:48   作者:我心依舊  
這篇文章主要介紹了C#通過(guò)重寫Panel改變邊框顏色與寬度的方法,涉及C#針對(duì)Panel控件的重寫與屬性設(shè)置技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了C#通過(guò)重寫Panel改變邊框顏色與寬度的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
namespace ImageStudio
{
 public class PanelEx : System.Windows.Forms.Panel
 {
  [DllImport("user32.dll")]
  private static extern IntPtr GetWindowDC(IntPtr hwnd);
  [DllImport("user32.dll")]
  private static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc);
  private Color _borderColor = Color.Black;
  private int _borderWidth = 1;
  //
  // 摘要:
  //  獲取或設(shè)置控件的邊框顏色。
  //
  // 返回結(jié)果:
  //  控件的邊框顏色 System.Drawing.Color。默認(rèn)為 System.Drawing.Color.Black
  //  屬性的值。
  [Description("組件的邊框顏色。"), Category("Appearance")]
  public Color BorderColor
  {
   get
   {
    return _borderColor;
   }
   set
   {
    _borderColor = value;
    this.Invalidate();
   }
  }
  //
  // 摘要:
  //  獲取或設(shè)置控件的邊框?qū)挾取?
  //
  // 返回結(jié)果:
  //  控件的邊框?qū)挾?int。默認(rèn)為 1
  //  屬性的值。
  [Description("組件的邊框?qū)挾取?), Category("Appearance")]
  public int BorderWidth
  {
   get
   {
    return _borderWidth;
   }
   set
   {
    _borderWidth = value;
    this.Invalidate();
   }
  }
  public PanelEx()
  {
   SetStyle(ControlStyles.DoubleBuffer, true);
   SetStyle(ControlStyles.AllPaintingInWmPaint, false);
   SetStyle(ControlStyles.ResizeRedraw, true);
   SetStyle(ControlStyles.UserPaint, true);
   SetStyle(ControlStyles.SupportsTransparentBackColor, true);
   this.Paint+=new PaintEventHandler(PanelEx_Paint);
  }
  private void PanelEx_Paint(object sender, PaintEventArgs e)
  {
   if (this.BorderStyle == BorderStyle.FixedSingle)
   {
    IntPtr hDC = GetWindowDC(this.Handle);
    Graphics g = Graphics.FromHdc(hDC);
    ControlPaint.DrawBorder(
     g,
     new Rectangle(0, 0, this.Width, this.Height),
     _borderColor,
     _borderWidth,
     ButtonBorderStyle.Solid,
     _borderColor,
     _borderWidth,
     ButtonBorderStyle.Solid,
     _borderColor,
     _borderWidth,
     ButtonBorderStyle.Solid,
     _borderColor,
     _borderWidth,
     ButtonBorderStyle.Solid);
    g.Dispose();
    ReleaseDC(Handle, hDC);
   }
  }
 }
}

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • 利用WPF窗口程序設(shè)計(jì)簡(jiǎn)單計(jì)算器

    利用WPF窗口程序設(shè)計(jì)簡(jiǎn)單計(jì)算器

    這篇文章主要為大家詳細(xì)介紹了利用WPF窗口程序設(shè)計(jì)簡(jiǎn)單計(jì)算器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-11-11
  • C#心跳機(jī)制服務(wù)器的示例代碼

    C#心跳機(jī)制服務(wù)器的示例代碼

    心跳機(jī)制出現(xiàn)在tcp長(zhǎng)連接中,客戶端和服務(wù)器之見(jiàn)定時(shí)發(fā)送一種特殊的數(shù)據(jù)包,本文主要介紹了C#心跳機(jī)制服務(wù)器的示例代碼,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-06-06
  • C#使用二分查找法判斷指定字符的方法

    C#使用二分查找法判斷指定字符的方法

    這篇文章主要介紹了C#使用二分查找法判斷指定字符的方法,結(jié)合實(shí)例形式分析了C#二分查找法進(jìn)行字符串查找的定義與使用技巧,需要的朋友可以參考下
    2016-06-06
  • C#查找素?cái)?shù)實(shí)現(xiàn)方法

    C#查找素?cái)?shù)實(shí)現(xiàn)方法

    這篇文章主要介紹了C#查找素?cái)?shù)實(shí)現(xiàn)方法,程序中有很多使用的功能模塊,非常適合C#初學(xué)者學(xué)習(xí)借鑒,需要的朋友可以參考下
    2014-08-08
  • 設(shè)計(jì)模式速記

    設(shè)計(jì)模式速記

    本文主要介紹了設(shè)計(jì)模式:創(chuàng)建型模式;結(jié)構(gòu)型模式;行為型模式三大類。具有很好的參考價(jià)值,相信有助于大家記憶與學(xué)習(xí),下面跟著小編一起來(lái)看下吧
    2017-02-02
  • C#實(shí)現(xiàn)讀取DataSet數(shù)據(jù)并顯示在ListView控件中的方法

    C#實(shí)現(xiàn)讀取DataSet數(shù)據(jù)并顯示在ListView控件中的方法

    這篇文章主要介紹了C#實(shí)現(xiàn)讀取DataSet數(shù)據(jù)并顯示在ListView控件中的方法,涉及C#操作DataSet及ListView控件的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-10-10
  • C#中委托的進(jìn)一步理解

    C#中委托的進(jìn)一步理解

    這篇文章主要介紹了C#中委托的進(jìn)一步理解,本文講解了委托類型、建立委托鏈、移除委托鏈等內(nèi)容,需要的朋友可以參考下
    2015-02-02
  • 輕松學(xué)習(xí)C#的密封類

    輕松學(xué)習(xí)C#的密封類

    輕松學(xué)習(xí)C#的密封類,對(duì)C#的密封類感興趣的朋友可以參考本篇文章,幫助大家更靈活的運(yùn)用C#的密封類
    2015-11-11
  • C#模擬實(shí)現(xiàn)QQ窗體功能

    C#模擬實(shí)現(xiàn)QQ窗體功能

    這篇文章主要為大家詳細(xì)介紹了如何通過(guò)C#實(shí)現(xiàn)類似QQ窗體的功能,當(dāng)窗體放置到屏幕的邊緣,可以將窗體隱藏,當(dāng)鼠標(biāo)再次放置到屏幕邊緣時(shí),窗體可再次顯示,需要的可以參考一下
    2022-12-12
  • C#獲取所有SQL Server數(shù)據(jù)庫(kù)名稱的方法

    C#獲取所有SQL Server數(shù)據(jù)庫(kù)名稱的方法

    這篇文章主要介紹了C#獲取所有SQL Server數(shù)據(jù)庫(kù)名稱的方法,涉及C#針對(duì)sql server數(shù)據(jù)庫(kù)的簡(jiǎn)單查詢技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-08-08

最新評(píng)論