Answer the question
In order to leave comments, you need to log in
How to change an element from another class?
I set the modifier to Public, it does not give any errors. But still nothing happens
public void detects() {
string TT = null;
int score=0;
label2.Text = "хоть что то";
while (score <= 0) {
score = textBox1.TextLength;
richTextBox1.Text += score;
if(score>0)
label2.Text = score.ToString();
}
}
Answer the question
In order to leave comments, you need to log in
1) Which element of this class do you want to change?
2)
> "But nothing happens either"
And as you try, give a piece of code. What error are you getting?
1 - show where and how it is declared label2
2 - and where, in relation to it, is the code that tries to change it label2
3 - provide convincing evidence that this code is actually called at all (yes, such errors do happen. but break point is enough here put in the studio)
.. you need to show the whole picture. by the fact that, according to the general description, you are catching a problem that really should not be in WinForms
free fantasy - perhaps you hung a modifier public
on the method that is trying to change label2
, but perhaps managed to label2
make it inaccessible. by default of the visual constructor, it is most likely so public
, but maybe this is a secondary form? which you have made allprivate
?... (although here the compiler would have cursed ..) nevertheless - without a complete picture, a qualitative answer is impossible
int score=0;
label2.Text = "хоть что то";
while (score <= 0)
{
score = textBox1.TextLength;
richTextBox1.Text += score;
if(score>0)
label2.Text = score.ToString();
}
score
has a negative value. but ... int score=0;
, moreover, we initialize the initial one with label2
a non-empty value, and this will only add kerosene to the fire , but already in the body of the cycle score = textBox1.TextLength;
, only this value can never be negative (and judging by the rest cycle code, even hardly zero at least ever) while (score <= 0)
break;
according to some meaningful condition that can actually occur in a fairly short time .. and not in years, otherwise a rabid dog is seven miles away (s)Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question