Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Change Form title from another Form.

(Using WinForms btw)
Alright so I made Options.cs open From Form1 using a toolStripButton with this code:
Code
namespace Application
{
    public partial class Form1 : Form
    {
        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            Options Options = new Options();
            Options.ShowDialog();
        }
    }
}

and on the Options form I have this:

Code
namespace Application
{
    public partial class Options : Form
    {
        public void button1_Click(object sender, EventArgs e)
        {
            Form1 f1 = new Form1();
            f1.Text = textBox1.Text;
            f1.Refresh();
            this.Hide();
        }
    }
}

And this is where the problem arises. There isn't any errors and Form1.Text remains the same, the reason I have a Refresh in there is because I noticed that if I did ShowDialog then on the second Form1 the title changed. Any suggestions?

Sorry I'm a new to C# 😊
There's no need to instantiate form 1.
Just do.

Form1.Text = "balh blah blah";
(Jan 3, 2015 08:05 PM)+Haze Wrote:  There's no need to instantiate form 1.
Just do.

Form1.Text = "balh blah blah";

Can you give me an example? I'm trying to make it that whatever the user inputs into the textbox, form1.text is changed to that.

(Jan 3, 2015 08:12 PM)Odus Wrote:  Use a sledgehammer to crack a nut why don't you?

Code
Form1.Text = textBox1.Text;

Huh? 😧
(Jan 3, 2015 08:25 PM)Shedletsky Wrote:  Can you give me an example? I'm trying to make it that whatever the user inputs into the textbox, form1.text is changed to that.

The line I just gave you does exactly that.
(Jan 3, 2015 08:30 PM)Odus Wrote:  The line I just gave you does exactly that.

I receive "An object reference is required for the non-static field, method, or property 'System.Windows.Forms.Control.Text.get' c:\users\.."

My code:
Code
public void button1_Click(object sender, EventArgs e)
      {
      Form1.Text = textBox1.Text;
      }
(Jan 3, 2015 08:05 PM)+Haze Wrote:  There's no need to instantiate form 1.

There is, in C#. Thankfully.

(Jan 3, 2015 09:28 PM)Odus Wrote:  My bad, hadn't touched C# in a while.
This would mean OP has to create a new form every time he wants different text on it.
Just set its text by keeping a reference to the parent form.

Options.cs:
[Image: 3QH0jY6.png]

Now use this in Form1 (or any other form):
Options options = new Options(this);

I'd rather use a sort of "input box" for this nonetheless.

E.g.

Options.cs:
[Image: SjWMyMB.png]

Form1.cs:
[Image: Dp71gL2.png]
(Jan 4, 2015 02:02 AM)Dialog Wrote:  There is, in C#. Thankfully.

This would mean OP has to create a new form every time he wants different text on it.
Just set its text by keeping a reference to the parent form.

Options.cs:
[Image: 3QH0jY6.png]

Now use this in Form1 (or any other form):
Options options = new Options(this);

I'd rather use a sort of "input box" for this nonetheless.

E.g.

Options.cs:
[Image: SjWMyMB.png]

Form1.cs:
[Image: Dp71gL2.png]

Ah thanks! :D I managed to get it working! 👍


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by Exodus.Feb 13, 2016 05:55 AM 10 327 Feb 13, 2016 05:55 AM
Last Post: Ninja
[C#] by Ðr1psNov 9, 2015 03:56 PM 19 416 Nov 9, 2015 03:56 PM
Last Post: Ðr1ps
[.NET] by WildElephantApr 21, 2015 10:48 AM 7 180 Apr 21, 2015 10:48 AM
Last Post: nuk