heinz2511
Goto Top

C Sharp - Refresh von Panel bzw. Grafik

Hallo,

ich benutze Visual Studio 2010 und Windows Forms.

Ich habe eine Form (formSpielfeld) mit einem Panel (panelSpielfeld) das ich mit .CreateGraphics() als Grafikobjekt für ein kleines Spiel benutze.

Nun habe ich das Problem dass wenn ich per MessageBox.Show während dem Spiel eine Meldung anzeige die Grafik des Spiels durch die MessageBox überschrieben wird, d.h wenn ich die MessageBox schliesse dann sehe ich ein graues Rechteck im Spielfeld da wo vorher die Messagebox war.

Ich habe versucht im Paint-Event des Panels ein Refresh zu machen, das hat aber nicht funktioniert.

Meine Frage ist also wie ich sicherstellen kann dass die Grafik (Panel) meines Spiel immer angezeigt\refreshed wird auch wenn zwischenzeitlich Messageboxen oder auch andere Anwendungen über dem Spiel erscheinen ?

Danke

Content-Key: 258359

Url: https://administrator.de/contentid/258359

Printed on: April 19, 2024 at 23:04 o'clock

Mitglied: 114757
114757 Dec 23, 2014 at 13:30:49 (UTC)
Goto Top
Moin,
da kann ich dir folgenden Artikel wärmstens empfehlen:
http://www.codeproject.com/Articles/1355/Professional-C-Graphics-with-G ...
In deinem Fall ist der Abschnitt The Invalidate() Method interessant:

Zitat:
There's an additional performance-related reason. Suppose at about the same time a couple of different requests to draw part of the screen come in. Perhaps, your code has just done something to modify the document and so wants to make sure the updated document is displayed, just as in our example, while at the same time the user has just restored the window or moved another window that was covering part of the client area out of the way. By calling Invalidate(), you are giving windows a chance to notice that this has occurred. Windows can then merge the Paint events if appropriate, combining the invalidated areas, so that the painting is only done once. (Calling a method to do the painting directly from your code might needlessly result in the same area of screen being repainted more than once.) 
Gruß jodel32
Member: Heinz2511
Heinz2511 Dec 23, 2014 at 13:47:54 (UTC)
Goto Top
Danke für die Antwort.
Aber wann bzw. wo sollte ich invalide aufrufen? nach jedem Messagebox.show?
Und wie würde ich wissen wann ich invalide aufrufen muss wenn zum Beispiel eine andere Anwendung (Notepad, Calc etc.) über meiner Spielgrafik stand?