Petit probleme avec le XML svp
Salut à tous, depuis quelque temp, je cherche à créer une form avec ces contrôle depuis un XML. C'est la première fois que je manipule le xml, alors je ram un peu.
Voila, j'ai fais ça:
Code:
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 35 36
| Public Sub CONVERT(ByVal FileName As String)
Dim ctrl As New Control ' variable pour la création d'un contrôle
Dim forms As New Form 'variable pour la création de la form
Dim type_ctrl As Integer = 0 ' 1 = Form et 2 = Contrôle
Dim xr As XmlTextReader = New XmlTextReader(FileName)
Do While xr.Read()
Select Case xr.NodeType
Case XmlNodeType.Element
Select Case xr.Name
Case "Object" ' Ici, on va identifier le type d'objet, un form, un boutton...ect
Select Case xr.GetAttribute("type")
Case "System.Windows.Forms.Form, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" ' Si cest une form
type_ctrl = 1 '1, c'est une form
forms = New Form
forms.Show()
Case "System.Windows.Forms.Button, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" ' Si c'est un bouton
type_ctrl = 2 '2, c'est un contrôle
ctrl = New Button
forms.Controls.Add(ctrl)
End Select
Case "Property"
Select Case xr.GetAttribute("name")
Case "Text" 'Pour la propriété Text du contrôle ou de la Form
If type_ctrl = 1 Then 'Si c'est une form
forms.Text = xr.ReadString
End If
If type_ctrl = 2 Then 'Si c'est un contrôle
ctrl.Text = xr.ReadString
End If
End Select
End Select
End Select
Loop
End Sub |
et dans mon XML, j'ai un truc comme ça:
Code:
1 2 3 4 5 6 7 8
| <Object type="System.Windows.Forms.Form, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="Dialog" children="Controls">
<Object type="System.Windows.Forms.Button, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="Cancel_Button" children="Controls">
<Property name="Text">Le Texte Du Boutton</Property>
</Object>
<Property name="Text">LE Texte De La Form!!!!</Property>
</Object> |
Donc, dans le xml, j'ai une form, avec sa poriété Text, et un bouton, avec aussi sa propriété Text.
Le code VB.Net que j'ai mis ci dessus lis le XML, et doit mettre la propriété Text à la form, et puis ainsi de suite pour tous les autre Object.
Mais voila le problême. Une fois tout ce blabla executé, je me retrouve avec une form ayant un bouton (normal), avec un texte dedans (jusque la, normal), mais pourquoi esqu'il n'y a pas de texte pour la Form? Pourtant, vous verez, j'ai fait en sorte de savoir si c'est la form auquel on doit donner la valeur Text ou pas. Comprend pas ou ça coince... :cry:
Vous pouvez m'aider svp? je ram dessus depuis plusieur semaine, au secour! XD
Merci d'avance à tous, et bonne année
A+