Hello new world.

I'm new to C# and very new to GDI and drawing and would really appreciate some help.

I'm trying to draw some boxes (rectangles). I wont put code up as I don't think it's nessesary... but you never know.

As a test I've made a form and every time you click a button it draws a square and increments a counter by 10. This counter is used for the location of the box so each time you click the button the square moves 10 to the right and 10 down, so you can see something is happening.

The problem is, nothing appears on the screen unless I resize the window. If I click the button 10 times, nothing appears, then I resize the window and they all appear.

Do you have any suggestions? I can post code if it's needed, but I'm guessing that it's quite a simple thing to solve.

Thanks for any and all help.

Andrew Smith.

EDIT: The strange thing is though, if I step through it in debug mode step by step it all works fine. Although the application does disappear behind VS so I guess that could be it...

well if you post the code it will be easy to see the problem, but i think the problem is you're drawing the rectangles but windows afterwards draws the form components and you see nothing...
i suggest you to create a bitmap, then draw what you need and display it in a picturebox.

I'm not at home right now so can't get to the code.

What I'm doing is making a mind-map drawing type program with bubbles and connectors.

I think I've worked out the problem, but I don't know how to solve it.

I have a collection called BasicShapes which contains the bubbles and boxes and clicking on the button adds a new shape to this collection, but I don't have any code to refresh the screen.

The override OnPaint(PaintEventArgs e) handles the refreshing and draws all my shapes. Is there any way I can call that from my drawRectange() function?

Sorry for not having the exact code... I'll post it when I get home.

IF you are not using any additional threads besides the main thread. Try adding

this.Refresh();

if you are using multiple threads try:

private delegate void refresh_delegate();
private void refeshWindow()
{
if (this.InvokeRequired) //invoke to main thread
{
object[] args = null;
this.Invoke(new refresh_delegate(this.refeshWindow),args);
return;
}
this.refresh();
}
 
 
then jsut call 
 
refreshWindow() from your function after you draw your boxes
This question has already been answered. Start a new discussion instead.