开发者

Drawn rectangle appears only on last instance of my userControl

开发者 https://www.devze.com 2023-02-24 15:11 出处:网络
I hav开发者_StackOverflowe a userControl which has some programmatically drawn rectangles. I need few instances of that userControl on my form (see the image). The problem is that only the last instan

I hav开发者_StackOverflowe a userControl which has some programmatically drawn rectangles. I need few instances of that userControl on my form (see the image). The problem is that only the last instance will show the drawn shapes!

I guess it has something to do with drawing surface or the Paint event handler

In case it might help, here's some of the code I use in my control:

private void MyUserControl_Paint(object sender, PaintEventArgs e)
{
    showHoraireMaitresse();
    Rectangle rec = showDisponibilités();

    var b = new SolidBrush(Color.FromArgb(150, Color.Blue));
           e.Graphics.FillRectangle (b, rec);
    showOccupation();
}

   private void showHoraireMaitresse()
    {
        heureDebut = 8;
        for (int i = 0; i < 14; i++)
        {
            //Label d'heure -> This shows just fine
            addLabel(i, heureDebut);

            //Rectangles d'heure -> This shows only in last instance
            var rectangle = new Rectangle(180 + i * largeurDUneHeure, 14, largeurDUneHeure, 30);
            surface.DrawRectangle(defaultPen, rectangle);
        }
        addLabel(14, heureDebut);
    }

Drawn rectangle appears only on last instance of my userControl

Thank you!


Without further information, I'm going to guess that 'surface' is static.

Trace through OnPaint and check which control is painting, and what the bounds are for 'surface'. Perhaps all the controls are painting the same exact rectangle.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号