Hello Self,
I believe I have a great solution for you, and it is as follows:
Instead of using Labels to display the text, which require a Color.Transparent background to allow for the Panel's background to show through, simple create a custom control which extends the System.Windows.Forms.Panel class and override the OnPaint method and paint the desired text directly to the custom Panel.
***Be sure to get the exact points for where you want the Text to begin, and the Font you wish to use beforehand.
Here is an example of how I wrote it:
public partial class OpenNewPanel : System.Windows.Forms.Panel
{
#region Members
private const float TITLE_POINT_SIZE = 16;
private const float DESCRIPTION_POINT_SIZE = 9;
private Bitmap gradientBackground { get; set; }
private Point titleLocation = new Point(156, 4);
private Point descriptionLocation = new Point(161, 30);
public string PanelTitle { get; set; }
public string PanelDescription { get; set; }
#endregion // Members
/// <summary>
/// Ctor
/// </summary>
public OpenNewPanel()
{
InitializeComponent();
// Members
this.PanelTitle = string.Empty;
this.PanelDescription = string.Empty;
// Styles
SetStyle(ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
// Misc
InitializeBackgroundGradient();
// Events
this.MouseEnter += new EventHandler(OpenNewPanel_MouseEnter);
this.MouseLeave += new EventHandler(OpenNewPanel_MouseLeave);
}
#region Overrides
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
//
// --- Custom Paint Operations Below ---
//
//e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
Graphics graphics = e.Graphics;
Font titleFont = new Font("Microsoft Sans Serif", TITLE_POINT_SIZE , FontStyle.Bold, GraphicsUnit.Point);
Font descriptionFont = new Font("Microsoft Sans Serif", DESCRIPTION_POINT_SIZE , FontStyle.Regular, GraphicsUnit.Point);
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Near;
this.SuspendLayout();
this.InvokePaintBackground(this, e);
// Draw Title
graphics.DrawString(this.PanelTitle, titleFont, new SolidBrush(Color.Black), (PointF)this.titleLocation);
// Draw Description
graphics.DrawString(this.PanelDescription, descriptionFont, Brushes.Black,
new RectangleF(this.descriptionLocation.X, this.descriptionLocation.Y, this.Width - this.descriptionLocation.X - 10, this.descriptionLocation.Y + 100),
format);
this.ResumeLayout();
}
#endregion // Overrides
#region Events
/// <summary>
/// Fires when the mouse enters the Open New Panel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OpenNewPanel_MouseEnter(object sender, EventArgs e)
{
SuspendLayout();
this.BackgroundImage = this.gradientBackground;
this.BackColor = Color.Transparent;
ResumeLayout();
}
/// <summary>
/// Fires when the mouse leaves the Open New Panel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OpenNewPanel_MouseLeave(object sender, EventArgs e)
{
SuspendLayout();
this.BackgroundImage = null;
this.BackColor = Color.Transparent;
ResumeLayout();
}
#endregion // Events
#region Methods
/// <summary>
/// Creates a Vertical DodgerBlue to White Gradient Bitmap
/// </summary>
private void InitializeBackgroundGradient()
{
System.Drawing.Drawing2D.LinearGradientBrush gradBrush;
gradBrush = new System.Drawing.Drawing2D.LinearGradientBrush(
new Rectangle { Height = this.Height, Width = this.Width }, Color.FromArgb(90, Color.DodgerBlue), Color.White, LinearGradientMode.Vertical);
Bitmap bmp = new Bitmap(this.Width, this.Height);
Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(gradBrush, new Rectangle(0, 0, this.Width, this.Height));
this.gradientBackground = bmp;
}
#endregion // Methods
}