• Create Account

## Setting form name with user input

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Malazar  Members

Posted 21 February 2012 - 05:11 AM

So I want my users to be able to create a file, and name it, then while the program is running they can see the name of the file they're using, when creating a new file they're asked to input a name for it, and once accepted, the form will load with their new file, setting the form name (or a label) to the name they've input.

My problem at the moment is that, when I take the text box text and convert to a string, then set the name of the new form to that string, it does nothing. the code compiles and runs without error, but does nothing. I've trawled through the MSDN documentation, however, none of it seems to handle anything remotely like this that I can find - only converting things like integers into strings, etc. If I try to directly input the text box text anywhere it throws errors that it can't be implicitly converted into a string.

Anyway, here's the code:
LeagueView StartNewLeague = new LeagueView();
string NameString;
//NewLeagueName.Text.ToString(); //This line seems to make no difference, moved down one.
//this converts newleaguename.text into a string and makes NameString = that text (i.e. the name the user has input)
NameString = NewLeagueName.Text.ToString();
//this sets the name of the new league to the name the user has input
StartNewLeague.Name = NameString;
//only it actually doesn't, as it does nothing whatsoever.
StartNewLeague.Show();

Does anyone have any ideas about how to set the name of the new form window (or alternatively to set the name of a label within the new form) ?

Posted 21 February 2012 - 05:44 AM

When you create a new form, try going to th Form.Designer.cs and change the property of label into public, that way you should be able to interact with it from other forms. I think the same thing can be done for Form's text (caption) but I haven't tried it. I think what you are trying to do is to pass data between forms - this is the link that explains how to do that. Hope this helps.

### #3meeshoo  Members

Posted 21 February 2012 - 06:22 AM

It is because you are not using the right property. If you are using WinForms, then the property is "Text", so you would have StarNewLeague.Text = "your custom name" in there, here is where I found this answer:
http://stackoverflow.com/questions/5104175/how-do-you-change-the-text-in-the-titlebar-in-winforms

If you are using WPF, then again, the property is "Title" and not Name.

### #4Malazar  Members

Posted 21 February 2012 - 06:22 AM

Thanks, that's exactly the kind of thing I'm looking for.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.