62 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			62 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using System;
 | 
						|
using System.Drawing;
 | 
						|
//using System.Collections;
 | 
						|
using System.ComponentModel;
 | 
						|
using System.Windows.Forms;
 | 
						|
//using System.Data;
 | 
						|
 | 
						|
namespace Volian.Controls.Library
 | 
						|
{
 | 
						|
	/// <summary>
 | 
						|
	/// Summary description for TransPanel.
 | 
						|
	/// </summary>
 | 
						|
	public partial class TransparentPanel : Panel
 | 
						|
	{
 | 
						|
		private string _Caption = "Inactive";
 | 
						|
		public string Caption
 | 
						|
		{
 | 
						|
			get { return _Caption; }
 | 
						|
			set { _Caption = value; InvalidateEx(); }
 | 
						|
		}
 | 
						|
		private int _Alpha = 128;
 | 
						|
		public int Alpha
 | 
						|
		{
 | 
						|
			get { return _Alpha; }
 | 
						|
			set { _Alpha = value; InvalidateEx(); }
 | 
						|
		}
 | 
						|
		public TransparentPanel()
 | 
						|
		{
 | 
						|
			InitializeComponent();
 | 
						|
		}
 | 
						|
		protected override CreateParams CreateParams
 | 
						|
		{
 | 
						|
			get
 | 
						|
			{
 | 
						|
				CreateParams cp = base.CreateParams;
 | 
						|
				cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
 | 
						|
				return cp;
 | 
						|
			}
 | 
						|
		}
 | 
						|
		protected void InvalidateEx()
 | 
						|
		{
 | 
						|
			if (Parent == null)
 | 
						|
				return;
 | 
						|
			Rectangle rc = new Rectangle(this.Location, this.Size);
 | 
						|
			Parent.Invalidate(rc, true);
 | 
						|
		}
 | 
						|
		protected override void OnPaintBackground(PaintEventArgs pevent)
 | 
						|
		{
 | 
						|
			//do not allow the background to be painted 
 | 
						|
		}
 | 
						|
		protected override void OnPaint(PaintEventArgs e)
 | 
						|
		{
 | 
						|
			SizeF txtSize = e.Graphics.MeasureString(_Caption, this.Font);
 | 
						|
			//Use a gray rectangle to show that the underlying control is inactive
 | 
						|
			//using (Brush b2 = new SolidBrush(Color.FromArgb(_Alpha, this.BackColor)))
 | 
						|
			//  e.Graphics.FillRectangle(b2, this.ClientRectangle);
 | 
						|
			using (Brush b = new SolidBrush(Color.FromArgb(_Alpha, this.ForeColor)))
 | 
						|
				e.Graphics.DrawString(_Caption, this.Font, b, this.Width - txtSize.Width, 2);
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 |