12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace IntelligentControlForsx.MyControls
- {
- public class TransparentPanel : Panel
- {
- public TransparentPanel()
- {
- SetStyle(ControlStyles.SupportsTransparentBackColor
- | ControlStyles.Opaque,
- true);
- BackColor = Color.Transparent;
- }
- protected override CreateParams CreateParams
- {
- get
- {
- CreateParams cp = base.CreateParams;
- /* Window extended styles
- #define WS_EX_DLGMODALFRAME 0x00000001L
- #define WS_EX_DRAGDETECT 0x00000002L
- #define WS_EX_NOPARENTNOTIFY 0x00000004L
- #define WS_EX_TOPMOST 0x00000008L
- #define WS_EX_ACCEPTFILES 0x00000010L
- #define WS_EX_TRANSPARENT 0x00000020L*/
- cp.ExStyle = cp.ExStyle | 0x20;
- return cp;
- }
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- if (BackColor != Color.Transparent)
- {
- var bounds = new Rectangle(0, 0, Width - 1, Height - 1);
- //const int alpha = 165;
- using (var bckColor = new SolidBrush(Color.FromArgb(_alpha, BackColor)))
- {
- e.Graphics.FillRectangle(bckColor, bounds);
- }
- }
- base.OnPaint(e);
- }
- protected override void OnBackColorChanged(EventArgs e)
- {
- Parent.Invalidate(this.Bounds, true);
- base.OnBackColorChanged(e);
- }
- protected override void OnParentBackColorChanged(EventArgs e)
- {
- Invalidate();
- base.OnParentBackColorChanged(e);
- }
- private int _alpha = 168;
- [Browsable(true), Category("Data")]
- public int Alpha
- {
- get
- {
- return _alpha;
- }
- set
- {
- _alpha = value;
- this.Invalidate();
- }
- }
- }
- }
|