Hi John,
This is a quick note to let you know that I am performing research on this
issue and will get back to you as soon as possible. I appreciate your
patience.
Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi John,
So far I've only found some example on how to do this in an Add-in instead
of a macro:
#Download details: Visual Studio 2005 Automation Samples
http://www.microsoft.com/downloads/details.aspx?FamilyID=79c7e038-8768-4e1e-
87ae-5bbbe3886de8&displaylang=en
Check out the "WinFormsAutomation" sample add-in.
Please note you will have to get to the designer service by its window, I
don't think it's possible to get it without opening it, which means it's
not possible to simply iterate over the ProjectItems collection and see if
an item is a form: without opening it, it's merely a text file.
When a ProjectItem is opened, you can check if currently opened in a
designer by checking if ActiveWindow.Object is a IDesignerHost object:
If TypeOf _applicationObject.ActiveWindow.Object is IDesignerHost Then
..
After you get the IDesignerHost reference, you can use its
.Container.Components to iterate through the child controls. Here's some
code to print out each control's Name:
Public Sub Exec(ByVal commandName As String, ByVal executeOption As
vsCommandExecOption, ByRef varIn As Object, ByRef varOut As Object, ByRef
handled As Boolean) Implements IDTCommandTarget.Exec
handled = False
If executeOption = vsCommandExecOption.vsCommandExecOptionDoDefault
Then
If commandName =
"RenameControlDemo2.Connect.RenameControlDemo2" Then
If TypeOf _applicationObject.ActiveWindow.Object Is
IDesignerHost Then
Dim designer As IDesignerHost =
CType(_applicationObject.ActiveWindow.Object, IDesignerHost)
Dim i As Integer
For i = 0 To designer.Container.Components.Count - 1
Dim comp As IComponent =
designer.Container.Components.Item(i)
Dim pd As PropertyDescriptor =
TypeDescriptor.GetProperties(comp)("Name")
Debug.Print(CType(pd.GetValue(comp), String))
If CType(pd.GetValue(comp), String) = "Button1" Then
pd.SetValue(comp, "myButton1")
End If
Next
End If
handled = True
Exit Sub
End If
End If
End Sub
You should be able to use pd.SetValue() to change the control's Name.
Changing name this way is supported, the designer will invoke code
refactoring for you when you change the Name property.
Hope this helps.
Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
John - 25 Jun 2007 08:46 GMT
Morning Walter,
Thanks very much for your comprehensive reply. I'll get started on this,
this morning.
Best regards
John
> Hi John,
>
[quoted text clipped - 71 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
John - 25 Jun 2007 18:55 GMT
Hi Walter,
Thanks again for your response to this issue. Your code sample has helped
me make a good deal of headway with it.
A note FYI on the Automation samples is that I got a corrupted cab file
error when trying to install the msi.
The code sample was useful too and it's given me some good insights into the
DTE object model. After all this however I've discovered the Document
Outline tool which allows you to rename controls. I notice it doesn't
refactor the code behind but that's acceptable at the moment as my main task
at the moment is to rename controls prior to the coding taking place.
Anyway, thanks again for a really useful response.
Best regards
John
> Morning Walter,
>
[quoted text clipped - 83 lines]
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
Walter Wang [MSFT] - 26 Jun 2007 02:45 GMT
Hi John,
Thanks for the update.
I just re-downloaded the file and it seems working fine on my side. FYI:
the file VS2005AutomationSamples.msi should have size 1,445,376 bytes, and
md5 checksum is BAF611ED6A969854214657BC322C3455.
Didn't noticed that you only need to find a easier way to batch rename the
controls; anyway, I'm glad that you've found the approach of using the
Document Outline window.
Have a nice day!
Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.