![]() |
|
[C#] Change Form title from another Form. - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] Change Form title from another Form. (/showthread.php?tid=4618834) |
Change Form title from another Form. - Shedletsky - Jan 3, 2015 (Using WinForms btw) Alright so I made Options.cs open From Form1 using a toolStripButton with this code: Code namespace Applicationand on the Options form I have this: Code namespace ApplicationAnd 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# 😊 * - +Haze - Jan 3, 2015 There's no need to instantiate form 1. Just do. Form1.Text = "balh blah blah"; * - Shedletsky - Jan 3, 2015 (Jan 3, 2015 08:05 PM)+Haze Wrote: There's no need to instantiate form 1. 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? Huh? 😧 * - Odus - Jan 3, 2015 (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. * - Shedletsky - Jan 3, 2015 (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)* - Dialog - Jan 4, 2015 (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: ![]() 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: ![]() Form1.cs:
* - Shedletsky - Jan 4, 2015 (Jan 4, 2015 02:02 AM)Dialog Wrote: There is, in C#. Thankfully. Ah thanks! :D I managed to get it working! 👍 |