Bonjour voici mon problème,
je lit un fichier .INIT qui me permet de changer la valeur ".text" de mes
controles ( bouton , checkbox et menu )
tout fonctionne correctement sauf pour le menu ou tout ce qui est a rapport avec : ToolStripXXX
finchier INIT:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 [MainMenu] ToolStripMenuItem1 = "&Fichier" ToolStripButton1 = "enregistrer" ToolStripButton2 = "fermer" lireINI(Me, "MainMenu", "ToolStripMenuItem1") '--> "&File"
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 Public Function lireINI(ByVal MyForm As Form, ByVal Entete As String, ByVal Variable As String) As String Dim StrBuild As New System.Text.StringBuilder(32768) Dim defval As String Try Dim Ret As Integer = GetPrivateProfileString(Entete, Variable, defval, StrBuild, 32768, fichier) Dim oCtrl As System.Windows.Forms.Form ' 1er function oCtrl = DirectCast(GetControlByName(MyForm, Variable), System.Windows.Forms.Control) 2iem function oCtrl = DirectCast(GetControlByName(Variable, MyForm), System.Windows.Forms.Control) If oCtrl IsNot Nothing And String.IsNullOrEmpty(StrBuild.ToString) = False Then oCtrl.Text = StrBuild.ToString oCtrl.Refresh() End If Return StrBuild.ToString Catch Return defval End Try End Function [j'ai essayer avec cette methode permettant de verifier les "sous classe" mais toujours rien
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 Private Function GetControlByName(ByRef oForm As Control, ByVal sControlName As String) As System.Windows.Forms.Control Dim oCtrl As System.Windows.Forms.Control oCtrl = oForm.Controls(sControlName) If oCtrl Is Nothing Then For Each oCtrl In oForm.Controls.Find(sControlName, True) If oCtrl.Name.Equals(sControlName) Then Return oCtrl End If Next Else Return oCtrl End If Return Nothing End Function
Merci d'avance pour votre aide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 Public Function GetControlByName(ByVal inControlName As String, ByVal inForm As Control) As Control Dim ctrl As Control = Nothing Dim VretControl As Control VretControl = Nothing Try For Each ctrl In inForm.Controls ' Add this control to the result. If UCase(ctrl.Name) = UCase(inControlName) Then VretControl = ctrl End If ' Recursively call this method to add all child controls as well. If ctrl.HasChildren Then Dim vr As Control vr = GetControlByName(inControlName, ctrl) If Not vr Is Nothing Then VretControl = vr End If End If Next Catch ex As Exception MessageBox.Show(ex.Message) End Try If VretControl Is Nothing Then Return Nothing Else Return VretControl End If End Function
Partager