HOW TO CALL FORM_PAINT EVENT ON BUTTON CLICK EVENT?

Tanuj Kumar

Total Post:134

Points:940
Posted by  Tanuj Kumar
C# 
C#
 3832  View(s)
Ratings:
Rate this:

Hi All,

I'm facing a problem since last night actually I want to invoke Form_Paint event on button click event but I didn't getting a proper solution so far. Please resolve my problem as soon as possible.

 

 

  1. Arun Singh

    Post:68

    Points:476
    Re: How to call Form_Paint event on button click event?

    Hi Tanuj Kumar,
    If you want to invoke Form_Paint event on button click event then you have to write code in such way:
    public void draw(object sender, PaintEventArgs e)
            {
                try
                {
                    using (LinearGradientBrush brush = new LinearGradientBrush(ClientRectangle, Color colr1, Color colr2, LinearGradientMode.Vertical))
                    {
                        e.Graphics.FillRectangle(brush, ClientRectangle);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
    private void btnApply_Click(object sender, EventArgs e)
            {
                Paint += draw;
                Invalidate();
            }

    I hope it might be resolve your problem.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!