Sign in to follow this  
Malazar

Setting form name with user input

Recommended Posts

Malazar    152
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:
[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();[/code]

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) ?

Share this post


Link to post
Share on other sites
NDraskovic    447
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 - [url="http://www.codeproject.com/Articles/14122/Passing-Data-Between-Forms"]this[/url] is the link that explains how to do that. Hope this helps.

Share this post


Link to post
Share on other sites
meeshoo    512
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:
[url="http://stackoverflow.com/questions/5104175/how-do-you-change-the-text-in-the-titlebar-in-winforms"]http://stackoverflow.com/questions/5104175/how-do-you-change-the-text-in-the-titlebar-in-winforms[/url]

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this