Paint Method C#
-
Hello, I'm making a windows form app using c#. In one form, I am "Painting" a table in a panel. When a button on the form is clicked, I would like to repaint the panel using specified parameters. Does anybody know how to do this? Here is some of the code: private void goBtn_Click(object sender, EventArgs e) { pltNum = pltList.SelectedIndex; tblPanel_Paint(object sender, PaintEventArgs e); } I guess I'm not sure what parameters I should pass to the tblPanel_Paint method. Thanks for your help! RC
-
Hello, I'm making a windows form app using c#. In one form, I am "Painting" a table in a panel. When a button on the form is clicked, I would like to repaint the panel using specified parameters. Does anybody know how to do this? Here is some of the code: private void goBtn_Click(object sender, EventArgs e) { pltNum = pltList.SelectedIndex; tblPanel_Paint(object sender, PaintEventArgs e); } I guess I'm not sure what parameters I should pass to the tblPanel_Paint method. Thanks for your help! RC
RC, To force the Windows Form to redraw, you should use the
Invalidate
function, rather than calling the paint event handler directly. For information on that function, have a look at Control.Invalidate[^] from MSDN. The important thing to note about the Invalidate function in that article is this sentence: "Calling the Invalidate method does not force a synchronous paint; to force a synchronous paint, call the Update method after calling the Invalidate method. When this method is called with no parameters, the entire client area is added to the update region." This simply means that when the Invalidate function returns, the control has not necessarily been redrawn yet. Thus it is possible that, after the user has clicked your "Go" button, the form does not redraw itself (although in normal usage, you won't really be able to tell). Nevertheless, as the MSDN documentation says, to force the redraw immediately, simply call theUpdate
function after you callInvalidate
. Here is how your code would look:private void goBtn_Click(object sender, EventArgs e)
{
pltNum = pltList.SelectedIndex;
this.Invalidate();
this.Update()
}Let me know if that works for you, or if you still have a difficulty, I will try to help you as best I can. Sincerely, Alexander Wiseman
-
RC, To force the Windows Form to redraw, you should use the
Invalidate
function, rather than calling the paint event handler directly. For information on that function, have a look at Control.Invalidate[^] from MSDN. The important thing to note about the Invalidate function in that article is this sentence: "Calling the Invalidate method does not force a synchronous paint; to force a synchronous paint, call the Update method after calling the Invalidate method. When this method is called with no parameters, the entire client area is added to the update region." This simply means that when the Invalidate function returns, the control has not necessarily been redrawn yet. Thus it is possible that, after the user has clicked your "Go" button, the form does not redraw itself (although in normal usage, you won't really be able to tell). Nevertheless, as the MSDN documentation says, to force the redraw immediately, simply call theUpdate
function after you callInvalidate
. Here is how your code would look:private void goBtn_Click(object sender, EventArgs e)
{
pltNum = pltList.SelectedIndex;
this.Invalidate();
this.Update()
}Let me know if that works for you, or if you still have a difficulty, I will try to help you as best I can. Sincerely, Alexander Wiseman