Hi this is albert,
this code works, no error, but EllipseLabel_Paint does not fire anywhere.
I've found those example as VB-Code as well, it works, even there is no inherit of "UserControl", makes me confused more than before.
I wachd other examples which carring about making an owen control, using "Usercontrol"
When those examples override OnPaint event like that:
protected override void OnPaint(PaintEventArgs e)
its understandable, OnPaint got from Control, fine.
Than I saw example of Resize,
this.Resize += new EventHandler(VerticalLabel_Resize);
so I thought, thats might be the solution for EllipseLabel_Paint and put it like that
this.Paint+= new EventHandler(EllipseLabel_Paint);
but was at last a stupid Idea?
So I wanna please you to help me out here, thanks albert
this code works, no error, but EllipseLabel_Paint does not fire anywhere.
I've found those example as VB-Code as well, it works, even there is no inherit of "UserControl", makes me confused more than before.
I wachd other examples which carring about making an owen control, using "Usercontrol"
When those examples override OnPaint event like that:
protected override void OnPaint(PaintEventArgs e)
its understandable, OnPaint got from Control, fine.
Than I saw example of Resize,
this.Resize += new EventHandler(VerticalLabel_Resize);
so I thought, thats might be the solution for EllipseLabel_Paint and put it like that
this.Paint+= new EventHandler(EllipseLabel_Paint);
but was at last a stupid Idea?
So I wanna please you to help me out here, thanks albert
Code:
public partial class EllipseLabelNew : UserControl
{
protected Label label1;
protected SolidBrush fillColor = new SolidBrush(Color.Blue);
public EllipseLabelNew()
{
InitializeComponent();
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.SupportsTransparentBackColor |
ControlStyles.ResizeRedraw, true);
this.BackColor = Color.Transparent;
}
private void EllipseLabel_Paint(object sender, PaintEventArgs e)
{
Graphics graph = e.Graphics;
// Rechteckbeschreibung
Rectangle rect = new Rectangle(0, 0, this.ClientSize.Width,
this.ClientSize.Height);
graph.FillEllipse(fillColor, rect);
int x = (this.ClientSize.Width - label1.ClientSize.Width) / 2;
int y = (this.ClientSize.Height - label1.ClientSize.Height) / 2;
label1.Location = new Point(x, y);
// Festlegen des dem Steuerelement zugeordneten Fensterbereichs
GraphicsPath graphPath = new GraphicsPath();
graphPath.AddEllipse(rect);
this.Region = new Region(graphPath);
}
// öffentliche Eigenschaft des ShapeLabels
// Eigenschaft soll im Eigenschaftsfenster angezeigt werden
[Browsable(true)]
[DesignerSerializationVisibility(
DesignerSerializationVisibility.Visible)]
public override string Text
{
get
{
return this.label1.Text;
}
set
{
this.label1.Text = value;
}
}
}