[2005] Help With VS Add-IN Updating control Text property is not applying properly
Ok, I am in the middle of writing an Add-IN for VS. Basically what it is is a spell checker for controls. It loops through all controls in a solution and spell checks the text in them. Well It appears to be working except that the changes are not being committed to the controls. I can visually see them change as it runs, however after closing and reopening the project none of the changes have stuck. I don't know if anyone has had any experience with creating Add-Ins and run into this, but I am pretty much at my wits end with this one. Any help would be appreciated.
Here is some of the code
This is the function that walks the documents
Code:
If IO.Path.GetExtension(fileName).ToLower = ".vb" Then
Dim control As System.Windows.Forms.Control = Nothing
Dim designerHost As System.ComponentModel.Design.IDesignerHost = Nothing
Dim window As EnvDTE.Window = Nothing
Dim wasOpen As Boolean = False
If _applicationObject.ItemOperations.IsFileOpen(fileName, EnvDTE.Constants.vsViewKindDesigner) Then
wasOpen = True
End If
window = PItem.Open(EnvDTE.Constants.vsViewKindDesigner)
Try
designerHost = CType(window.Object, System.ComponentModel.Design.IDesignerHost)
control = CType(designerHost.RootComponent, System.Windows.Forms.Control)
WalkControls(control, window)
window.Close(vsSaveChanges.vsSaveChangesYes)
Catch ex As AbortException
Throw
Catch
If wasOpen Then
window.Close(vsSaveChanges.vsSaveChangesNo)
End If
End Try
End If
HEre is the code that walks the controls, I have checked this and it is getting the corrected text and replacing the Control.Text with it, however as I said above, it is just not sticking.
Code:
Private Sub WalkControls(ByVal control As System.Windows.Forms.Control, ByVal Window As EnvDTE.Window)
If control Is Nothing Then
Return
End If
Dim replacedString As String = SpellCheckString(control.Text)
If replacedString <> control.Text Then
control.Text = replacedString
Window.Document.Saved = False
End If
If control.Controls Is Nothing Then
Return
End If
For Each subControl As System.Windows.Forms.Control In control.Controls
WalkControls(subControl, Window)
Next
End Sub
Re: [2005] Help With VS Add-IN
Ok, I have done some more testing on this and found out some interesting stuff. It seems that I can change the text of the controls, however, it is not changing the text value in the Designer. Also if I move the control on the form afterwards then the changes are committed to the designer. This is weird. I am going to do some more testing with this later this evening and hopefully someone else has seen this before.