문제

Its a simple and straightforward question. I couldn't draw a rectangle inside a groupbox. Any answer will be really helpful.

    private void groupBox_Paint(object sender, PaintEventArgs e)
    {
        Graphics g = this.CreateGraphics();
        Brush b = new SolidBrush(Color.Gray);
        g.FillRectangle(b, 800, 70, 360, 440);
    }

I think there was sth wrong with my ide. I had tried Graphics g = e.Graphics before. I tried again after restarting my computer. Now its working. I think something happened to my computer or visual studio. Thanks for your support.

도움이 되었습니까?

해결책

Instead of this.CreateGraphics() you have to use e.Graphics

Example:

private void groupBox_Paint(object sender, PaintEventArgs e)
{
    Graphics g = e.Graphics;
    using (Brush b = new SolidBrush(Color.Gray))
    {
        g.FillRectangle(b, 800, 70, 360, 440);
    }
}

다른 팁

Graphics g = this.CreateGraphics();

Instead of this statement use your groupBoxName you want to draw on, like this

Graphics g = groupBox.CreateGraphics();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top