GDI object usage

D

davide

In my application I use a large number of panels and textboxes. If I
set the backcolor to each control, the application requires a large
number of GDI objects. They are not freed until Dispose() get called.

for (int i = 0; i<1000; i++)
{
t = new TextBox();
// if I comment this statement, the problem does not occur
t.BackColor = Color.Red;
Controls.Add(t);
}

How can I limit the GDI object usage while the controls are shown (so I
can't dispose them)?

Thanks
Davide
 
S

Steve B.

If possible, try to work with only one control. A control you will have to
write.

The difficulty depends on what you want to do.

Take a look at the DataGrid or GridView Object... It could help you, still
depending of what are trying to do...

Last tip, but it is maybe quite soon, is to use XAML with FinFX application.
There is a new way of programming end user applications that does not
require creating thousands of GDI objects... but it is still in beta


Steve
 
D

davide

Thanks for your reply,
regarding the datagrid, I agree with you. I know quite well that
control.
But I think that my example is miss-understanding. I wrote the example
only to let you notice that if I don't set the BackColor, the problem
does not appear.

In my real scenario, I have to show several windows opened at the same
time, with a lot of controls that require many GDI objects.

My goal is to let all dialogs use less resources. I think that each
control needs a Brush to paint itself, but if 100 control use the same
color, why they don't share a single Brush instance?

Finally, I think that whenever I don't set the backColor, the control
uses the Brush of the parent, so the problem does not occur.

I would appreciate very much if you could tell me how to save GDI
objects whenever there are a lot of controls shown at the same time.

Thanks
Davide
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top