Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Static TextBoxt that keeps disappearing

Static TextBoxt that keeps disappearing

Scheduled Pinned Locked Moved C#
helpquestioncsharpvisual-studiographics
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    laphijia
    wrote on last edited by
    #1

    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

    F 1 Reply Last reply
    0
    • L laphijia

      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

      F Offline
      F Offline
      FruitBatInShades
      wrote on last edited by
      #2

      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;

      L 1 Reply Last reply
      0
      • F FruitBatInShades

        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;

        L Offline
        L Offline
        laphijia
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups