Recherche un tuto simple et complet sur les forms et/ou un solution

moimatthieu Messages postés 68 Date d'inscription jeudi 17 juillet 2008 Statut Membre Dernière intervention 6 mars 2010 - 9 oct. 2008 à 11:06
moimatthieu Messages postés 68 Date d'inscription jeudi 17 juillet 2008 Statut Membre Dernière intervention 6 mars 2010 - 9 oct. 2008 à 14:02
Bonjour

Je recherche un tutoriel simple et complet sur les formes parce que j'y comprnd vraiment rien à leur fonctionnement alors ça me prend la tête.
J'ai récupéré ce bout de code il y a environ 2h sur msdn mais je n'ai tjs pas réussi à trouver comment on récupère la valeur des boutons. Tout ce que le programme veut bien faire pour l'instant c'est fermer la fenêtre par appui sur annuler ou la croix.

Option

Compare
BinaryOption

Explicit
OnOption

Strict
OnImports

System.Windows.Forms
Imports

System.Drawing

Public
Class MyForm

Inherits System.Windows.Forms.Form

Public
Sub CreateMyForm()

' Create a new instance of the form.

Dim form1
As
New Form()

' Create two buttons to use as the accept and cancel buttons.

Dim button1
As
New Button()

Dim button2
As
New Button()

' Dim LstTestA As New ListBox

' LstTestA.Dock = DockStyle.Fill

' LstTestA.CheckedBox = True

' Set the text of button1 to "OK".button1.Text =

"OK"

' Set the position of the button on the form.button1.Location =

New Point(10, 10)

' Set the text of button2 to "Cancel".button2.Text =

"Cancel"

' Set the position of the button based on the location of button1.button2.Location =

New Point(button1.Left, button1.Height + button1.Top + 10)

' button2.Location = _

' New Point(button1.Left, button1.Height + button1.Top + 10)

' Set the caption bar text of the form. form1.Text =

"My Dialog Box"

' Display a help button on the form.form1.HelpButton =

True

' Define the border style of the form to a dialog box.form1.FormBorderStyle = FormBorderStyle.FixedDialog

' Set the MaximizeBox to false to remove the maximize box.form1.MaximizeBox =

True

' Set the MinimizeBox to false to remove the minimize box.form1.MinimizeBox =

True

' Set the accept button of the form to button1.form1.AcceptButton = button1

' Set the cancel button of the form to button2.form1.CancelButton = button2

' Set the start position of the form to the center of the screen.form1.StartPosition = FormStartPosition.CenterScreen

' Add button1 to the form.form1.Controls.Add(button1)

' Add button2 to the form.form1.Controls.Add(button2)

' button2.Location = New Point(button1.Left, button1.Height + button1.Top + 10)

Dim instance
AsNew CheckBoxinstance.Location New Point(button1.Right + 40, button1.Top)instance.Text

"Toto"
' Texte … droite de la case … cocherform1.Controls.Add(instance)

form1.ShowDialog()

Dim val1
As DialogResult = Windows.Forms.DialogResult.OK

If (val1 = Windows.Forms.DialogResult.OK)
Thenform1.Close()

End
If

' AcceptButton.DialogResult

' Dim val11 As DialogResult = Windows.Forms.DialogResult.Cancel

Dim val2
As DialogResult = button1.DialogResultform1.Close()

If (val2 = Windows.Forms.DialogResult.OK)
ThenMsgBox(

"Vous avez press‚ OK")

End
If

Dim valeur
As CheckState = instance.CheckState

' Display the form as a modal dialog box.form1.ShowDialog()

End
Sub

7 réponses

gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
9 oct. 2008 à 11:20
utilise l'ide de vb c'est beaucoup plus simple

Bonjour chez vous !
0
moimatthieu Messages postés 68 Date d'inscription jeudi 17 juillet 2008 Statut Membre Dernière intervention 6 mars 2010
9 oct. 2008 à 11:25
Je ne vois pas de différences, les codes proposés en exemples sont les mêmes donc ça ne m'avance pas du tout  :
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.fr/fxref_system.windows.forms/html/9d5fbf76-f508-bd48-f172-1f9c3d94871b.htm
0
gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
9 oct. 2008 à 12:41
pour interragir avec des composants il vaut mieux utiliser l ide de vb pour créer les form et controles
la création dynamique ça vient après , quand on a compris comment ça fonctionne
autrement dit ne mets pas la charrette devant les boeufs

Bonjour chez vous !
0
NHenry Messages postés 15113 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 22 avril 2024 159
9 oct. 2008 à 13:14
Bonjour,

Qu'entends-tu par "la valeur des boutons" ?

http://nhen0039.chez-alice.fr/index.php
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
moimatthieu Messages postés 68 Date d'inscription jeudi 17 juillet 2008 Statut Membre Dernière intervention 6 mars 2010
9 oct. 2008 à 13:45
Ce que je veux faire c'est une fenêtre, où par la suite j'afficherai des checkbox pour des choix, qui a 2 boutons ok et annuler. Pour créer la fom j'ai récupéré le code que j'ai mis ci-dessus mais là où je bloque c'est que je ne sais pas comment savoir sur quel bouton l'utilisateur à cliqué (ok ou cancel). Dans le cas de OK, je lance l'analyse des choix qu'il a effectué alors que dans le cas de Annuler, c'est tout le programme qui s'arrête, un arrêt d'urgence.
Si je n'es toujours pas été clair, redemandez moi.
0
NHenry Messages postés 15113 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 22 avril 2024 159
9 oct. 2008 à 13:53
Bonjour,

à la place de :
Dim button1
As New Button()

Dim button2
As New Button()

mets :
Dim WithEvents button1
As New Button()


Dim
WithEvents
button2
As New Button()

Puis pour gérer :

private sub Button1(...) handles button1.click

Pour button1, utilises un nom plus explicite.
(...) est à remplacer par la convention d'appel de l'event.

http://nhen0039.chez-alice.fr/index.php
0
moimatthieu Messages postés 68 Date d'inscription jeudi 17 juillet 2008 Statut Membre Dernière intervention 6 mars 2010
9 oct. 2008 à 14:02
Euh .... erreur :( : "WithEvents" n'est pas valide dans une déclaration de variable locale.
Je galère vraiment en VB.NET :(
0
Rejoignez-nous