469,275 Members | 1,515 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

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

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

May 17 '07 #1
2 2133

"Ole Mercano" <om***@yahoo.co.ukwrote in message
news:46**********************@newsspool2.arcor-online.net...
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.
May 17 '07 #2
On Thu, 17 May 2007 08:24:58 -0700, Ole Mercano <om***@yahoo.co.ukwrote:
[...]
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
May 17 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Maellic | last post: by
2 posts views Thread by Jason | last post: by
7 posts views Thread by HeroinNO.4 | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.