G
Guest
Hi everyone,
First of all, why am I having this problem... I need a REAL transparent
label control. My custom label control needs to be able to be the child of
any other control and must only display text, not a background image or color.
So I created a control derived from System.Windows.Control, the problem is
that the parent control doesn't draw under my custom control, probably
because the parent thinks that the child will do it. However, I need the
parent to completely draw itself. Is there a way to do it?
Any help is appreciated, thanks!
Sylvain Fortin
public class ctrlLabel : Control
{
protected Brush m_brsBlack = null;
....
// OnPaintBackground
protected override void OnPaintBackground(PaintEventArgs pe)
{
}
// OnPaint
protected override void OnPaint(PaintEventArgs pe)
{
RectangleF rcArea = RectangleF.Empty;
// Calling base class OnPaint
base.OnPaint(pe);
try
{
if (m_brsBlack == null)
m_brsBlack = new SolidBrush(Color.Black);
rcArea = new RectangleF(0, 0, this.Width, this.Height);
pe.Graphics.DrawString(this.Text, this.Font, m_brsBlack, rcArea);
}
catch (Exception)
{
}
}
}
First of all, why am I having this problem... I need a REAL transparent
label control. My custom label control needs to be able to be the child of
any other control and must only display text, not a background image or color.
So I created a control derived from System.Windows.Control, the problem is
that the parent control doesn't draw under my custom control, probably
because the parent thinks that the child will do it. However, I need the
parent to completely draw itself. Is there a way to do it?
Any help is appreciated, thanks!
Sylvain Fortin
public class ctrlLabel : Control
{
protected Brush m_brsBlack = null;
....
// OnPaintBackground
protected override void OnPaintBackground(PaintEventArgs pe)
{
}
// OnPaint
protected override void OnPaint(PaintEventArgs pe)
{
RectangleF rcArea = RectangleF.Empty;
// Calling base class OnPaint
base.OnPaint(pe);
try
{
if (m_brsBlack == null)
m_brsBlack = new SolidBrush(Color.Black);
rcArea = new RectangleF(0, 0, this.Width, this.Height);
pe.Graphics.DrawString(this.Text, this.Font, m_brsBlack, rcArea);
}
catch (Exception)
{
}
}
}