Panel_paint method
-
Hi, I'm trying to use the paint method to draw a table on a panel in a windows form. For some reason, the paint method is being called over and over again (I don't even know how many times!) when the form is opened. Does anybody know why this is happening? I'm fairly new to all this, so any insight is much appreciated. Thanks! RC
-
Hi, I'm trying to use the paint method to draw a table on a panel in a windows form. For some reason, the paint method is being called over and over again (I don't even know how many times!) when the form is opened. Does anybody know why this is happening? I'm fairly new to all this, so any insight is much appreciated. Thanks! RC
reshsilk wrote:
the paint method is being called over and over again
This will happen if you put a breakpoint in the paint method, which causes focus to transfer back to Visual Studio, thereby invalidating the panel. The process will repeat ad infinitum. To verify the paint method is being called more times than it should, replace the breakpoint with a
Debug.Trace()
call and inspect the contents of the Output window. Another reason for the paint method being called repeatedly may be programmer error - eg: invalidating the panel (in code) from within the paint method. Hope this helps! /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com -
Hi, I'm trying to use the paint method to draw a table on a panel in a windows form. For some reason, the paint method is being called over and over again (I don't even know how many times!) when the form is opened. Does anybody know why this is happening? I'm fairly new to all this, so any insight is much appreciated. Thanks! RC
-
reshsilk wrote:
the paint method is being called over and over again
This will happen if you put a breakpoint in the paint method, which causes focus to transfer back to Visual Studio, thereby invalidating the panel. The process will repeat ad infinitum. To verify the paint method is being called more times than it should, replace the breakpoint with a
Debug.Trace()
call and inspect the contents of the Output window. Another reason for the paint method being called repeatedly may be programmer error - eg: invalidating the panel (in code) from within the paint method. Hope this helps! /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)comhi ravi, i did have a breakpoint in the paint method, which i removed. but it still appears to be firing multiple times. i am trying to redraw a panel in a windows form when a particular button is clicked. here is part of the code...
private void srchPlatesBtn_Click(object sender, EventArgs e) { getPlates(); split.Panel2.Invalidate(); } private void split_Panel2_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; drawPlateResults(g); } private void drawPlateResults(Graphics g) { // code to draw the table in the panel goes here }
Do you know of any other way to force the panel to redraw? Thanks for all your help, RC -
hi ravi, i did have a breakpoint in the paint method, which i removed. but it still appears to be firing multiple times. i am trying to redraw a panel in a windows form when a particular button is clicked. here is part of the code...
private void srchPlatesBtn_Click(object sender, EventArgs e) { getPlates(); split.Panel2.Invalidate(); } private void split_Panel2_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; drawPlateResults(g); } private void drawPlateResults(Graphics g) { // code to draw the table in the panel goes here }
Do you know of any other way to force the panel to redraw? Thanks for all your help, RCreshsilk wrote:
Do you know of any other way to force the panel to redraw?
You are principally doing this right. Put somethin like a Console.WriteLine statement into your drawing code to really check if your Panel gets painted multiple times (which I don`t think seeing your code). Like already stated the Panel might not only redraw when you call Invalidate but for example also whenever you move a window on top of your app.