Static TextBoxt that keeps disappearing
-
Hi folks, I'm just beginning with C#. I am doing an RPN calculator and it seems to work pretty well. However I have a problem. I have a class that manages the stack, and a class that manages the displaying of numbers on the display, that actually is a TextBox, tbDisplay. Since the TextBox in on the main form, the one that gets created automatically when you use the form designer, I have to access it from the display class. How do I do it? What I did is declaring the TextBox public static. After from the display class I access it using Form1.tbDisplay. It works! The problem is that everytime I add a control, or do "something", something being I don't know exactly what, the TextBox disappears. It seems that VisualStudio removes the lines of code. What VS does is not removing the declarations of the control, public static etc..., but it removes the lines in the initialization. It removes the line from the this.Controls.AddRange. It also removes these lines: Calc.tbDisplay = new System.Windows.Forms.TextBox(); // tbDisplay // Calc.tbDisplay.Location = new System.Drawing.Point(136, 56); Calc.tbDisplay.Name = "tbDisplay"; Calc.tbDisplay.Size = new System.Drawing.Size(208, 20); Calc.tbDisplay.TabIndex = 18; Calc.tbDisplay.Text = "0"; Calc.tbDisplay.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; This happens all the times. It's the tenth time I add the lines back by hand, it's a mess. What's the problem here? I suspect that my approach of declaring it static.. etc it's not the right solution? How should it work??? How do I, from inside Z class, control an istance of a X class that is declared into Y class? Thanks for any help. I hope to finish my calc so maybe I can post my first arcticle on CodeProject. It uses a nice stack class. And it behaves exactly like the calculator I am emulating, the HP 12C.:-D Edward
-
Hi folks, I'm just beginning with C#. I am doing an RPN calculator and it seems to work pretty well. However I have a problem. I have a class that manages the stack, and a class that manages the displaying of numbers on the display, that actually is a TextBox, tbDisplay. Since the TextBox in on the main form, the one that gets created automatically when you use the form designer, I have to access it from the display class. How do I do it? What I did is declaring the TextBox public static. After from the display class I access it using Form1.tbDisplay. It works! The problem is that everytime I add a control, or do "something", something being I don't know exactly what, the TextBox disappears. It seems that VisualStudio removes the lines of code. What VS does is not removing the declarations of the control, public static etc..., but it removes the lines in the initialization. It removes the line from the this.Controls.AddRange. It also removes these lines: Calc.tbDisplay = new System.Windows.Forms.TextBox(); // tbDisplay // Calc.tbDisplay.Location = new System.Drawing.Point(136, 56); Calc.tbDisplay.Name = "tbDisplay"; Calc.tbDisplay.Size = new System.Drawing.Size(208, 20); Calc.tbDisplay.TabIndex = 18; Calc.tbDisplay.Text = "0"; Calc.tbDisplay.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; This happens all the times. It's the tenth time I add the lines back by hand, it's a mess. What's the problem here? I suspect that my approach of declaring it static.. etc it's not the right solution? How should it work??? How do I, from inside Z class, control an istance of a X class that is declared into Y class? Thanks for any help. I hope to finish my calc so maybe I can post my first arcticle on CodeProject. It uses a nice stack class. And it behaves exactly like the calculator I am emulating, the HP 12C.:-D Edward
I don't think declaring a control as static is valid!:~ The code you show is generated by (and deleted by) the form designer. If it doesn't like your declaration it will probably strip the control on code generation. i.e. the code that the form designer creates.
Calc.tbDisplay = new System.Windows.Forms.TextBox(); // tbDisplay // Calc.tbDisplay.Location = new System.Drawing.Point(136, 56); Calc.tbDisplay.Name = "tbDisplay"; Calc.tbDisplay.Size = new System.Drawing.Size(208, 20); Calc.tbDisplay.TabIndex = 18; Calc.tbDisplay.Text = "0"; Calc.tbDisplay.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
-
I don't think declaring a control as static is valid!:~ The code you show is generated by (and deleted by) the form designer. If it doesn't like your declaration it will probably strip the control on code generation. i.e. the code that the form designer creates.
Calc.tbDisplay = new System.Windows.Forms.TextBox(); // tbDisplay // Calc.tbDisplay.Location = new System.Drawing.Point(136, 56); Calc.tbDisplay.Name = "tbDisplay"; Calc.tbDisplay.Size = new System.Drawing.Size(208, 20); Calc.tbDisplay.TabIndex = 18; Calc.tbDisplay.Text = "0"; Calc.tbDisplay.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
Thanks for the hint, I was pretty sure that there was something wron, even if it actually worked! :( But it seems that now I have a problem that I don't know how to solve. I have a class Display that I use to perform all the stuff related to the display, that actually is my control box. For example I need this class because it keeps track whether when the user pushed a button he's beginning a new number or adding a digit to the number currently onscreen. Things like that. The problem is that I don't know how to access the control that is on the form. You know they are in two different classes. Of course I cannot inside class Display write tbDisplay.Text = "whatever"; nor Form1.tbDisplay; etc. How this is supposed to work? Thanky you a lot! Edward