Jon said:
Well, the first is that Form1.cs really *isn't* a nice source file
name. Surely it's quite rare that anyone *would* want a form really
called "Form1". If only VS asked you for the name of the main form, or
gave you an option to cancel... even "MainForm" would be better than
"Form1". (I know, I could change the templates - but it's a shame that
I have to.)
No disagreement there. I think the initial default form should have the
same name as the project at a minimum, if VS isn't going to ask you for
a specific name.
But that's not really what I was asking about.
Given that I'd always want to rename the source file, in my test I did
exactly that to start with - and it gave me the option of renaming the
class as well. I accepted. Sure enough, the name was changed. The name
of the form (as on the designer) wasn't though.
You mean the Text property of the form instance?
Okay, I can see that as being an example of "doesn't get everything
right" in the sense that a brand new form would inherit the actual name.
On the other hand, I can't think of a single application I've written
in .NET where the Text property of the form was left being identical to
the in-code name of the form (ie, the default value assigned to it).
Or do you mean something else?
Is this a huge blow? No... but it *is* about as much effort as deleting
the form and starting again, and more effort than if the project
started without the form at all.
If you delete the only form in the project and then create a new one,
does the Main() method get updated properly so that the
Application.Run() statement instantiates your new form class instead of
the original one?
I have to admit, it never occurred to me to do this rather than just
renaming the form, and I agree that deleting and creating a new one is
slightly easier than renaming both the class and the .cs file
individually. But as you noted above, if you rename the file first, the
class can be renamed automatically. And if you still need to go back
and fix up the Main() method, I'm not sure that deleting the form and
starting a new one is easier.
If you refactor using the refactor menu, it doesn't (IIRC) offer to
change the name of the source file, so that has to be done separately.
Is this also the "doesn't get everything right" you were talking about?
If I understand it correctly, to sum up:
-- rename the .cs file, and the form instance's Text property isn't
updated
-- rename the class first, and you still need to rename the .cs
file, and the form instance's Text property isn't updated
As I say, asking the developer up-front would have been a much nicer
solution, IMO.
I agree. Just wanted to make sure I wasn't overlooking some subtle "hey
this didn't get changed" bug in code where I've renamed my form classes
and .cs files.
Thanks,
Pete