C#实现渐变颜色的Windows窗体控件
生活随笔
收集整理的這篇文章主要介紹了
C#实现渐变颜色的Windows窗体控件
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
C#實(shí)現(xiàn)漸變顏色的Windows窗體控件!
1,定義一個(gè)BaseFormGradient,繼承于System.Windows.Forms.Form
2,定義三個(gè)變量:
????????private?Color?_Color2?=?Color.White;
????????private?float?_ColorAngle?=?0f;
3,重載OnPaintBackground方法
????????{
????????????//?Getting?the?graphics?object
????????????Graphics?g?=?pevent.Graphics;
????????????//?Creating?the?rectangle?for?the?gradient
????????????Rectangle?rBackground?=?new?Rectangle(0,?0,?this.Width,?this.Height);
????????????//?Creating?the?lineargradient
????????????System.Drawing.Drawing2D.LinearGradientBrush?bBackground?
????????????????=?new?System.Drawing.Drawing2D.LinearGradientBrush(rBackground,?_Color1,?_Color2,?_ColorAngle);
????????????//?Draw?the?gradient?onto?the?form
????????????g.FillRectangle(bBackground,?rBackground);
????????????//?Disposing?of?the?resources?held?by?the?brush
????????????bBackground.Dispose();
????????}
4,定義一個(gè)新窗體GradientForm,繼承BaseFormGradient.
public class GradientForm : BaseFormGradient
5,在窗體GradientForm中,設(shè)置_Color1,_Color2,_ColorAngle
轉(zhuǎn)載于:https://www.cnblogs.com/xyqCreator/archive/2012/08/18/2645628.html
總結(jié)
以上是生活随笔為你收集整理的C#实现渐变颜色的Windows窗体控件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Struts1 tag
- 下一篇: 【unity3d--初始学习五--c#脚