.NET Framework - Steuerelement ausblenden
Asked By Dirk Herwig
20-Nov-09 10:07 AM
Hallo,
ich habe ein Usercontrol, abgeleitet von Label ?ber anderen Usercontrols
angeordnet. Nun soll das Usercontrol (von Label abgeleitet) nur an
bestimmten Zeiten angezeigt werden. Ich hatte es so versucht:
if (showtime == 0)
{
this.Visible = false;
}
Das ganze hat aber nichts gebracht. Der Text und die Hintergrundfarbe werden
zwar nicht angezeigt, jedoch verdeckt das Usercontrol doch (schwarz) meine
anderen Controls, welche darunter liegen und zu sehen sein sollen.
K?nnt ihr mir hier weiterhelfen?
mfg
Dirk
Application.DoEvents
(1)
Application
(1)
DoEvents
(1)
Refresh
(1)
Hintergrundfarbe
(1)
Steuerelement
(1)
Neuzeichnen
(1)
Usercontrol
(1)
Uwe Hercksen replied to Dirk Herwig
Dirk Herwig schrieb:
Hallo,
eventuell hilft schon ein Application.DoEvents
Jedenfalls mu? das Neuzeichnen der bisher verdeckten Controls angesto?en
werden wenn das Steuerelement unsichtbar gesetzt wird. Also ein .Refresh
f?r die bisher verdeckten Controls.
Bye
Herfried K. Wagner [MVP] replied to Uwe Hercksen
Uwe Hercksen schrieb:
... worum sich Windows aber ohne Dein Zutun k?mmern sollte.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

VB 2008] Warum dispose aller Fenster bei exit Application.run? .NET Framework Hi, ich bin heute auf ein Verhalten gestossen, das ich f?r Form With {.Text = "f2"} f1.Show() f2.Show() fMain = New Form With {.Text = "fMain #1"} Application.Run(fMain) End Sub End Class Festgestellt habe ich, dass _in_ Application.Run, nachdem fMain geschlossen wurde, die Dispose-Methode _aller_ ge?ffneten Fenster aufgerufen wird. Ich finde das nicht richtig. Deutlich wird das, wenn man nach dem Application.Run diese Zeilen einf?gt: fMain = New Form With {.Text = "fMain #2"} Application.Run(fMain) Schlie?t man nun die erste Instanz von fMain werden f1 und f2 Dispose(Boolean) System.dll!System.ComponentModel.Component.Dispose() System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadWindows.Dispose() System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.DisposeThreadWindows() System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int, int, int) System.Windows.Forms.dll!System
thread operation button1.Text = "Completed"; / / <- cross-thread operation } [STAThread] public static void Main(string[] args) { Application.Run(new MyForm()); } } } Yes, it will throw exception when running inside IDE / debugger, but if why WPF raises a exception is to prevent unpredictable behavior. You do not want a application that could go wrong sometimes. Here is is some information why you should not update thread operation button1.Text = "Completed"; / / <- cross-thread operation } [STAThread] public static void Main(string[] args) { Application.Run(new MyForm()); } } } Yes, it will throw exception when running inside IDE / debugger, but if 100; i++) { textBox1.Text + = " " + i; / / <- cross-thread operation } } [STAThread] public static void Main(string[] args) { Application.Run(new MyForm()); } } } I spawn four thread and as expected, the textbox does not display created on the same thread where your message pump is running (i.e. your Form application's main thread), it will get any window message sent to it, as long as thread that owns it is dispatching messages in a message pump (in a .NET Forms application you get a message pump by calling Application.Run() or Form.ShowDialog()). The examples of incorrect code (or rather, the ones that do var isClosed = false; form.FormClosed + = (o, e) = > isClosed = true; while(!isClosed) { Thread.Sleep(1000); form.Refresh(); / / Application.DoEvents(); } } I had put a button on a form and when I call Refresh
DoEvents .NET Framework Hallo, braucht man in den heutigen Zeiten des Multitaskings eigentlich in lang laufenden Schleifen noch ein Applcation.DoEvents? - - Mit freundlichen Gruessen Wolfgang Wienke VB.NET - German Discussions Application.DoEvents (1) Applcation.DoEvents (1) BackgroundWorker (1) ProgressBar (1) WPF (1) VB (1) Application (1 DoEvents (1) Hallo Wolfgang, Wenn Du Deine "lang laufende Schleife" in einen separaten Thread auslagerst, wird Frage w?re eher: Braucht man in Zeiten von Multicore und Parallelisierung / Multithreading ?berhaupt noch Application.DoEvents? Nein. Das Betriebssystem interessiert sich nicht f?r die Belange Deiner Anwendung, sondern versucht
1) Create X BackgroundWorkers and put it into an array Workers[] 2) Then have a DoEvents loop: int done = 0; while (done < X) { done = 0; for (int i = 0; i < X; i++) { if (!Workers[i].IsBusy) done++; } Application.DoEvents(); } / / THREADS WE DONE - do whatever I only used a Thread Pool. But I do not but in practice this is almost always a GUI thread). Your example is a console application and as such is completely irrelevant to my code example and my comments. Pete Please internal local scope change is asking for trouble and would be contention in a real application using that piece of code. Sleep or not sleep, I saw it immediately. Its extremely case where it was NEVER intended to work. You created the "bug" in a console application - the BackgroundWorker (to my knowledge) is designed solely to function within a Windows Forms application (maybe WPF?? Not sure on that one - I will just stick with Windows Forms since you used Application.DoEvents() in your initial example). The threading behaves VERY differently between the two environments. In
wenn der Main-Thread gerade busy ist. Du k = F6nntest im Main-Thread dann ggf. Application.DoEvents() oder die in meinn Links angegebene best practice benutzen. 2) Da Du die Rows im Thread gemarshallt werden, weil dieser busy ist. ( wenn man nicht, wie ich schrieb, Dinge wie Application.DoEvents() oder andere Thread- Synchronisations-Ma?nahmen s. meine Links benutzt). ciao Frank - - Dipl.Inf. Frank die Freigabe der UI-Threads warten) aber w = FCrde immer dann, wenn zum Beispiel ein Application.DoEvents(), wie schon ein paar mal von mir beschrieben) wieder aktiv werden k = F6nnen, weiterlaufen. Deswegen rthread zu antworten. Invoke() wartet. Sobald der UI-Thread weitermacht (z.B. durch Aufruf von Application.DoEvents() auf dem UI-Thread), wird die Arbeit von Invoke() fortgesetzt. Und: Es ist nicht meine