123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Text;
- using System.Drawing;
- using System.Windows.Forms;
- namespace LYFZ.ComponentLibrary
- {
-
-
-
-
- [ToolboxBitmap(typeof(TransparentControl))]
- public class TransparentControl :System.Windows.Forms.Control
- {
- private bool _transparentBG = true;
- private int _alpha = 30;
- private System.ComponentModel.Container components = new System.ComponentModel.Container();
- public TransparentControl()
- : this(30, true)
- {
-
- }
-
- public TransparentControl(int Alpha, bool showLoadingImage)
- {
- try
- {
- this.SetStyle(ControlStyles.DoubleBuffer, true);
- this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
- this.SetStyle(ControlStyles.UserPaint, true);
- this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
- this.SetStyle(ControlStyles.StandardDoubleClick, false);
- this.SetStyle(ControlStyles.Selectable, true);
- this.SetStyle(System.Windows.Forms.ControlStyles.Opaque, true);
- ResizeRedraw = true;
- BackColor = Color.Transparent;
- ForeColor = Color.White;
- Font = new Font("微软雅黑", 9, System.Drawing.FontStyle.Bold);
- base.CreateControl();
- this._alpha = Alpha;
- this.thisAlpha = _alpha;
- this.Width = 60;
- this.Height = 60;
- }
- catch { }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- if (!((components == null)))
- {
- components.Dispose();
- }
- }
- base.Dispose(disposing);
- }
- private int thisAlpha = 0;
-
-
-
-
- protected override void OnMouseDown(MouseEventArgs e)
- {
- base.OnMouseDown(e);
- this._alpha = 20;
- Invalidate(false);
- }
- protected override void OnGotFocus(EventArgs e)
- {
- base.OnGotFocus(e);
- this._alpha = 35;
- Invalidate(false);
- }
-
-
-
-
- protected override void OnLostFocus(EventArgs e)
- {
- base.OnLostFocus(e);
- this._alpha = thisAlpha;
- Invalidate(false);
- }
-
-
-
-
- protected override void OnMouseUp(MouseEventArgs mevent)
- {
- base.OnMouseUp(mevent);
- this._alpha = 35;
- Invalidate(false);
- }
-
-
-
-
- protected override void OnMouseEnter(EventArgs e)
- {
- base.OnMouseEnter(e);
- this._alpha = 35;
- Invalidate(false);
- }
-
-
-
-
- protected override void OnMouseLeave(EventArgs e)
- {
- base.OnMouseLeave(e);
- this._alpha = thisAlpha;
- Invalidate(false);
- }
-
-
-
-
- protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
- {
-
-
-
- float vlblControlWidth;
- float vlblControlHeight;
- base.InvokePaintBackground(this, new PaintEventArgs(e.Graphics, base.ClientRectangle));
- Pen labelBorderPen;
- SolidBrush labelBackColorBrush;
- Color drawColor = Color.FromArgb(this._alpha, this.BackColor);
-
- if (_transparentBG)
- {
- labelBorderPen = new Pen(drawColor, 0);
- labelBackColorBrush = new SolidBrush(drawColor);
- }
- else
- {
- labelBorderPen = new Pen(this.BackColor, 0);
- labelBackColorBrush = new SolidBrush(this.BackColor);
- }
-
- vlblControlWidth = this.Size.Width;
- vlblControlHeight = this.Size.Height;
- Rectangle rele= new Rectangle(0, 0, this.Size.Width, this.Size.Height);
-
-
-
- e.Graphics.DrawRectangle(labelBorderPen, 0, 0, vlblControlWidth, vlblControlHeight);
- e.Graphics.FillRectangle(labelBackColorBrush, 0, 0, vlblControlWidth, vlblControlHeight);
-
-
- }
-
-
-
- protected override CreateParams CreateParams
- {
- get
- {
- CreateParams cp = base.CreateParams;
- cp.ExStyle |= 0x20;
- return cp;
- }
- }
- [Category("TransparentControl"), Description("是否使用透明,默认为True")]
- public bool TransparentBG
- {
- get { return _transparentBG; }
- set
- {
- _transparentBG = value;
- this.Invalidate();
- }
- }
- [Category("TransparentControl"), Description("设置透明度")]
- public int Alpha
- {
- get { return _alpha; }
- set
- {
- if (value <= 255 && value>=0)
- {
- _alpha = value;
- thisAlpha = _alpha;
- }
- this.Invalidate();
- }
- }
- }
- }
|