Home > DeveloperSection > Forums > How to call Form_Paint event on button click event?
Tanuj Kumar

Total Post:134

Points:940
Posted on    July-16-2012 4:23 AM

 C# C# 
Ratings:


 1 Reply(s)
 3287  View(s)
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.

 

 



Arun Singh

Total Post:68

Points:476
Posted on    July-21-2012 1:17 AM

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.

Don't want to miss updates? Please click the below button!

Follow MindStick