wanna figured out how to use EllipseLabel_Paint beside other trouble

Joined
Jan 2, 2014
Messages
13
Reaction score
0
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

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;
            }
        }

        
    }
 
Joined
Jan 2, 2014
Messages
13
Reaction score
0
it works like that:
Code:
 this.Paint += new PaintEventHandler(this.OnPaint);  
 private void OnPaint(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);
        }
It works like that(without declaration of new eventhandler), I Have no Idea why
Code:
protected override void OnPaint(PaintEventArgs e)
       {

           base.OnPaint(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);
       }

But this, what a surprise is not working, no idea why?
Code:
this.Resize += new EventHandler(VerticalLabel_Resize);
  private void VerticalLabel_Resize(object sender, EventArgs e)
        {
            Invalidate();
        }
 
Joined
Jan 2, 2014
Messages
13
Reaction score
0
I got a little step,
this:
Code:
this.Resize += new EventHandler(VerticalLabel_Resize);   private void VerticalLabel_Resize(object sender, EventArgs e)         {             Invalidate();         }

is working.
But of cource, it has to be put in a form. Without, 'Initialize' will never happen
Thats simple, but first steps are mostly presented with a base of 'Usercontrol' and will be initialize for reasons of those helper.




is working
 
Last edited:
Top