+ 3

Set the text of a label - WinForms [SOLVED]

Hi there, i'm trying to do some stack-work. There is a method that pops out a bunch of bools and a 2nd one, that pushs some into. Of course ... if the stack is empty, the first method cant take anything out, so there will be an exception. For example, there are 15 bools on the stack, but the method wants to pop out 20 bools, i'll get the exception - the thread should wait until the stack isnt empty anymore. There is a label in this WinForm i'd like to write the exception-text on, how do i realize that? I already changed private to public (public System.Windows.Forms.Label Fehlertext;) to gain access ... ######## this is my label ####### this.Fehlertext.AutoSize = true; this.Fehlertext.Location = new System.Drawing.Point(35, 274); this.Fehlertext.Name = "Fehlertext"; this.Fehlertext.Size = new System.Drawing.Size(0, 20); this.Fehlertext.TabIndex = 0; this.Fehlertext.Enabled = true; ############# #############here is my thread

16th Jun 2019, 10:31 PM
Oliver
3 Réponses
+ 3
I see. I think your answer is in this link https://www.c-sharpcorner.com/UploadFile/1d42da/thread-safe-calls-using-windows-form-controls-in-C-Sharp/ if (this.myTextBox.InvokeRequired) { SetTextCallback d = new SetTextCallback(SetText); this.Invoke(d, new object[] { text + " (Invoke)" }); } else { this.myTextBox.Text = text + " (No Invoke)"; }
1st Jul 2019, 8:49 PM
sneeze
sneeze - avatar
+ 1
You need to use the name of the label. Fehlertext.text = ex.Message;
17th Jun 2019, 2:28 PM
sneeze
sneeze - avatar
+ 1
Sorry, but i wrote that i tought it would be easy as that (see comment in code)... I already tried this and it didnt work. The solution is about threading and parallel programming...
1st Jul 2019, 1:35 PM
Oliver