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. Changing textBox from Method

Changing textBox from Method

Scheduled Pinned Locked Moved C#
helpannouncementworkspace
4 Posts 3 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.
  • O Offline
    O Offline
    ormonds
    wrote on last edited by
    #1

    I'm having trouble getting a textBox to accept a string from within a method. Start with:-

       private static Form1 form = null;
    
        public Form1()
        {
            InitializeComponent();
            form = this;
        }
    
        private void Form1\_Load(object sender, EventArgs e)
        {
            textBox2.Text = "Initialising.....";
            this.Show();
            Refresh();
    

    textBox2 shows up OK. However

           form.UpDateText("Checking validity of " + FileName);
    

    and

       public void UpDateText(string ThisText)
        {
            using (StreamWriter logfile = new StreamWriter("D:\\\\TeklaZipping.log", true))
            {
                logfile.WriteLine(ThisText);
                logfile.Close();
            }
            Form1 frm1 = new Form1();
            frm1.textBox1.Text += ThisText + System.Environment.NewLine;
            frm1.Refresh();
        }
    

    runs, and writes to logfile, but doesn't update textBox1. Any help appreciated.

    ormonds

    L M 2 Replies Last reply
    0
    • O ormonds

      I'm having trouble getting a textBox to accept a string from within a method. Start with:-

         private static Form1 form = null;
      
          public Form1()
          {
              InitializeComponent();
              form = this;
          }
      
          private void Form1\_Load(object sender, EventArgs e)
          {
              textBox2.Text = "Initialising.....";
              this.Show();
              Refresh();
      

      textBox2 shows up OK. However

             form.UpDateText("Checking validity of " + FileName);
      

      and

         public void UpDateText(string ThisText)
          {
              using (StreamWriter logfile = new StreamWriter("D:\\\\TeklaZipping.log", true))
              {
                  logfile.WriteLine(ThisText);
                  logfile.Close();
              }
              Form1 frm1 = new Form1();
              frm1.textBox1.Text += ThisText + System.Environment.NewLine;
              frm1.Refresh();
          }
      

      runs, and writes to logfile, but doesn't update textBox1. Any help appreciated.

      ormonds

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      It is updating textBox1 in a new instance of frm1. Try something like below;

       //Form1 frm1 = new Form1();
       this.textBox1.Text += ThisText + System.Environment.NewLine;
      

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

      1 Reply Last reply
      0
      • O ormonds

        I'm having trouble getting a textBox to accept a string from within a method. Start with:-

           private static Form1 form = null;
        
            public Form1()
            {
                InitializeComponent();
                form = this;
            }
        
            private void Form1\_Load(object sender, EventArgs e)
            {
                textBox2.Text = "Initialising.....";
                this.Show();
                Refresh();
        

        textBox2 shows up OK. However

               form.UpDateText("Checking validity of " + FileName);
        

        and

           public void UpDateText(string ThisText)
            {
                using (StreamWriter logfile = new StreamWriter("D:\\\\TeklaZipping.log", true))
                {
                    logfile.WriteLine(ThisText);
                    logfile.Close();
                }
                Form1 frm1 = new Form1();
                frm1.textBox1.Text += ThisText + System.Environment.NewLine;
                frm1.Refresh();
            }
        

        runs, and writes to logfile, but doesn't update textBox1. Any help appreciated.

        ormonds

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        ormonds wrote:

        Form1 frm1 = new Form1();

        This creates a new instance of Form1 and updates the textbox on the new instance. Remove the line and change frm1.textbox1 to this.textbox1 (this is not required but will help you to identify the source of the control).

        Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

        O 1 Reply Last reply
        0
        • M Mycroft Holmes

          ormonds wrote:

          Form1 frm1 = new Form1();

          This creates a new instance of Form1 and updates the textbox on the new instance. Remove the line and change frm1.textbox1 to this.textbox1 (this is not required but will help you to identify the source of the control).

          Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

          O Offline
          O Offline
          ormonds
          wrote on last edited by
          #4

          Thank you, appreciated.

          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