How to rename "button1" in Form source code to "but_change_set" ?

  • Thread starter Thread starter Ole Mercano
  • Start date Start date
O

Ole Mercano

When I create in Designer a new button on my Form it is automatically
named e.g. "button1".

When I doubleclick on it I am directed to the Form.cs where the following
procedure is automatcially generated:

private void button1_Click(Object sender, EventArgs e) {
}

To improve readability I want to rename now "button1" to "but_change_set".
Back in Desinger pane I changed the name in the properties pane accordingly.

When I doubleclick now on the same button again I am directed to the source
again. But much to my surprise neither a new procudure

private void but_change_set_Click(Object sender, EventArgs e) {
}

is created nor the old existing procedure is renamed.

Hmmm, How can I achieve a renaming in the source code as well ?

Ole
 
Ole Mercano said:
When I create in Designer a new button on my Form it is automatically
named e.g. "button1".

When I doubleclick on it I am directed to the Form.cs where the following
procedure is automatcially generated:

private void button1_Click(Object sender, EventArgs e) {
}

To improve readability I want to rename now "button1" to "but_change_set".
Back in Desinger pane I changed the name in the properties pane
accordingly.

When I doubleclick now on the same button again I am directed to the
source
again. But much to my surprise neither a new procudure

private void but_change_set_Click(Object sender, EventArgs e) {
}

is created nor the old existing procedure is renamed.

Hmmm, How can I achieve a renaming in the source code as well ?

Ole

If this is VS 2005 and the naming didn't happen, which it did for me when I
double clicked the button in form design, then go to InitializeComponent on
the FormName.cs,which is located in the drop down box at top right.

In the InitializeComponent(), you'll see the Button-Click Event-Handler
which is pointing to the Sub for the event, rename the Sub there and rename
the Sub that it's pointing to, for the event.

If it's VS 2003, then it's the same thing find InitializeComponent() in code
and change the Event-Handler event name that it points too.
 
[...]
When I doubleclick now on the same button again I am directed to the
source again. But much to my surprise neither a new procudure

private void but_change_set_Click(Object sender, EventArgs e) {
}

is created nor the old existing procedure is renamed.

Hmmm, How can I achieve a renaming in the source code as well ?

When you change the name of the control, all that you are doing is
changing the field name in the form. So the only automatic renaming that
occurs is anywhere that field name is used. If you want the name of the
method to change, you have to do that manually.

If all you want is a brand new method to be created, just delete the old
reference in the event in the designer and double-click the event again.

As for why this would be: consider the situation where you have a method
that doesn't follow the designer's naming strategy. For example, you
wanted your own custom name, or you're sharing a single event handler
among many controls. Obviously automatic renaming wouldn't work in those
cases, and so the designer is just making sure its behavior is consistent.

Pete
 
Back
Top