siddhartha
Member
- Joined
- Jan 6, 2010
- Messages
- 6
- Programming Experience
- 10+
I am writing a simple control translation function that reads an XML file containing control names and their localized text. Within the application, each time a form is loaded, it iterates through every control and tests to see if that control is defined in the XML file. If it is, it then sets the control text to whatever localized text is defined in the XML file.
There are some tests and additional requirements (i.e. nested loops) for TabControl and MenuStrip etc., but the control that is giving me the most trouble is the ContextMenuStrip.
frmForm.Contains(cmuContextualMenu) returns False. It seems that contextual menus are not part of the Form.Controls collection.
From the form.Designer.vb, I can see that it creates a contextual menu as follows:
So, I could reference the contextual menu by first changing "Private components..." to "Public components..." then:
But two problems arise:
1) It would be nice to be able to do something like:
2) I would like to have the frmForm.components a standard Form property so I could access the property from any generic Form object and not a specific, named form. If this can't be done, it would be nice to be able to test the existence of the .components property on any Form object.
The best possible solution is to change:
To:
So that the ContextualMenu is now part of the controls collection of the Form object and not in some mysterious private components IContainer. Alas, this does not work.
Any help is appreciated.
There are some tests and additional requirements (i.e. nested loops) for TabControl and MenuStrip etc., but the control that is giving me the most trouble is the ContextMenuStrip.
frmForm.Contains(cmuContextualMenu) returns False. It seems that contextual menus are not part of the Form.Controls collection.
From the form.Designer.vb, I can see that it creates a contextual menu as follows:
VB.NET:
Private components As System.ComponentModel.IContainer
Me.components = New System.ComponentModel.Container
Me.cmuContextualMenu = New System.Windows.Forms.ContextMenuStrip(Me.components)
So, I could reference the contextual menu by first changing "Private components..." to "Public components..." then:
VB.NET:
For Each ctl_control As Control In frmForm.components.Components
MessageBox.Show(ctl_control.Name)
Next ctl_control
But two problems arise:
1) It would be nice to be able to do something like:
VB.NET:
MessageBox.Show(CType(frmForm.components.Components("cmuContextualMenu"), Control).Name)
2) I would like to have the frmForm.components a standard Form property so I could access the property from any generic Form object and not a specific, named form. If this can't be done, it would be nice to be able to test the existence of the .components property on any Form object.
The best possible solution is to change:
VB.NET:
Me.cmuContextualMenu = New System.Windows.Forms.ContextMenuStrip(Me.components)
To:
VB.NET:
Me.cmuContextualMenu = New System.Windows.Forms.ContextMenuStrip
So that the ContextualMenu is now part of the controls collection of the Form object and not in some mysterious private components IContainer. Alas, this does not work.
Any help is appreciated.