D
D
DD-var2019-12-26 05:54:16
C++ / C#
DD-var, 2019-12-26 05:54:16

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

2 answer(s)
A
AlexV, 2019-12-26
@Av-IT

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?

#
#, 2019-12-27
@mindtester

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 publicon the method that is trying to change label2, but perhaps managed to label2make 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();
}

it's a 100% infinite loop. it has a chance to exit only if it scorehas a negative value. but ...
- we have initialization int score=0;, moreover, we initialize the initial one with label2a non-empty value, and this will only add kerosene to the fire , but already in the body of the cycle
- then it’s infinite score = textBox1.TextLength;, only this value can never be negative (and judging by the rest cycle code, even hardly zero at least ever)
- and let me remind you of the condition of the cycle (that is, equality to zero is permissible by the will of the author initially) only a negative value can interrupt this bacchanalia .. well, orwhile (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)
it seems that everything is happening with you, only the name for this is freezing (according to the abstruse - endless cycle )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question