Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Buttons being very slow - Need to Override Painting?

Status
Not open for further replies.

Dannybe2

Programmer
Jan 31, 2001
136
GB
Hi,

My app is very slow and I am trying to make it more efficient but can't seem to work out which method to override.

I have a lot of buttons (100 - 200) added to a panel and wish to resize the panel so that the buttons resize themselves in the window. The buttons are quite long (200 pixels or so) and so if they reach the end of the page they split into two buttons, one starting on the next line.

This works very well, but it is terribly slow. Every time I resize, it removes all the buttons from the panel one at a time and then adds them back one at a time. (this cannot be changed due to the purpose of my app). The panel is drawn on every add or remove.

This is a considerable amount of redrawing, but I can't work out which method to overload. I wish the buttons to be removed and added again without performing a redraw until the end.

I have tried double buffering but cant get it to draw to just this panel.

I thought that I could just catch paint events in the panel and then ignore them until all the buttons had been removed and added, but these events are not created as I expected.

Does anyone have any idea how to prevent all this excessive drawing?

Thanks,
Dan
 
this cannot be changed due to the purpose of my app

oh yes it can; try thinking sideways.

howsoever, look at the InitializeComponent method of your form, it does just what you're asking.

mr s. <;)

 
Because you are using a lot of controls, you are sucking up a lot of memory and causing the system to work really hard in managing so many controls.

I don't know the purpose of your app but you might want to consider drawing on the panel in GDI+ to make it look like there's buttons and when the panel is clicked, you locate the mouse position and which button would have been pressed.

This solution takes a little bit of time but would make your app move very quickly!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top