IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langages Discussion :

[Débutant] Gestion RadioButton dans une classe Form


Sujet :

Langages

  1. #1
    Candidat au Club
    Homme Profil pro
    Ingénieur validation
    Inscrit en
    Novembre 2017
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur validation

    Informations forums :
    Inscription : Novembre 2017
    Messages : 5
    Points : 2
    Points
    2
    Par défaut [Débutant] Gestion RadioButton dans une classe Form
    Bonjour je débute en programmation objet et je voudrais faire un formulaire Form avec des Radiobutton
    J'ai le code suivant pour le moment

    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
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
     
    import System
    import time
    import clr
    import sys
    clr.AddReference("System.Windows.Forms")
    clr.AddReference("System.Drawing")
    import System.Windows.Forms as WinForms
    from System.Drawing import Size, Point
    from System.Windows.Forms import Application, Button, Form, Label, TextBox, ComboBox, RadioButton, GroupBox, Panel
    from System.Drawing import Pen, Color, Graphics, Rectangle
     
     
    class Alarm(Form):
     
    	def __init__ (self):
     
    		self.Text = "Gestion Alarmes"
    		self.Height = 800
    		self.Width = 500
    		self.CenterToScreen()
     
    		label = Label()
    		label.Text = "TC_ALARM"
    		label.Location = Point(180, 5)
    		label.Size = Size(100,15)
    		label.Parent = self
     
    		self.button1 = Button()
    		self.button1.Text = "Ok"
    		self.button1.Location = Point(25, 500)
    		self.button1.Click += self.ok
     
    		self.button2 = Button()
    		self.button2.Text = "Cancel"
    		self.button2.Location = Point(125, 500)
    		self.button2.Click += self.cancel
     
    		self.Controls.Add(self.button1)
    		self.Controls.Add(self.button2)
     
     
    	def ok(self, sender, event):
    		self.sts = RadioButton1bis.Checked
    		self.Close()
    	def cancel(self, sender, event):
    		dr = showYesNo("Etes vous sur de vouloir quitter le module en cours ?", "Message operateur")
    		if dr == True:
    			self.Close()
     
    toto = Alarm()
    Application.Run(toto)
    J'aimerai récupérer quand je clique sur OK les valeurs des radio button que j'ai crée et que j'ai relié 2 à 2 (via une GroupBox)...
    Je ne trouve pas la propriété qui renvoie la valeur si le radiobutton est "Checked" ou pas ...
    De plus j'ai l'impression que dans ma fonction ok, il ne connais pas les objet RadioButton de ma classe ... ?

    Merci de votre aide et suggestion à ce propos !!

  2. #2
    Membre expert Avatar de jopopmk
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2011
    Messages
    1 856
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2011
    Messages : 1 856
    Points : 3 570
    Points
    3 570
    Par défaut
    Salut,

    Je suis pas sûr que beaucoup de helpers ici fassent du .NET avec ce langage.
    Peut-être que tu auras plus de chance sur le forum python
    Plus je connais de langages, plus j'aime le C.

  3. #3
    Candidat au Club
    Homme Profil pro
    Ingénieur validation
    Inscrit en
    Novembre 2017
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur validation

    Informations forums :
    Inscription : Novembre 2017
    Messages : 5
    Points : 2
    Points
    2
    Par défaut
    yep je connais ce probleme... c'est du Ironpython que personne n'utilise ...
    mais bon j'ai pas trop le choix.
    Par contre des gens qui utilisent le FW .NET avec d'autres languages (C# par exple) peuvent quand meme m'aider je pense car mes soucis sont plus dus à l'utilisation de la librairie .NET que des soucis de python...

  4. #4
    Membre expert Avatar de jopopmk
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2011
    Messages
    1 856
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2011
    Messages : 1 856
    Points : 3 570
    Points
    3 570
    Par défaut
    D'un point de vue général c'est bien la propriété Checked qu'il faut regarder pour savoir si un RadioButton est sélectionné.

    As-tu ajouté ces RadioButton dynamiquement ?
    Jes les vois pas dans ton __init__ (qui je suppose correspond au InitializeComponent).
    Plus je connais de langages, plus j'aime le C.

  5. #5
    Candidat au Club
    Homme Profil pro
    Ingénieur validation
    Inscrit en
    Novembre 2017
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur validation

    Informations forums :
    Inscription : Novembre 2017
    Messages : 5
    Points : 2
    Points
    2
    Par défaut
    Bon j'ai reussi à faire ce que je voulais, peut etre pas au mieux mais ça marche

    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
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
     
    class GroupeAlrmBox(Control):
    	def __init__ (self):
     
    		self.labelAlarm = Label()
    		self.labelAlarm.Size = Size(100,20)
    		self.labelAlarm.Location = Point(0,20)
     
    		self.ResetBox = GroupBox()
    		self.ResetBox.Size = Size(260,30)
    		self.ResetBox.Location = Point(150,0)
     
     
    		self.RadioButton1 = RadioButton()
    		self.RadioButton1.Text = "Reset Alarm"
    		self.RadioButton1.Parent = self.ResetBox
    		self.RadioButton1.Location = Point(5, 10)
    		self.RadioButton1.Size = Size(90,15)
     
    		self.RadioButton1bis = RadioButton()
    		self.RadioButton1bis.Text = "No Reset"
    		self.RadioButton1bis.Parent = self.ResetBox
    		self.RadioButton1bis.Location = Point(150, 10)
    		self.RadioButton1bis.Size = Size(80,15)
    		self.RadioButton1bis.Checked = True
     
    		self.ResetBox2 = GroupBox()
    		self.ResetBox2.Size = Size(260,30)
    		self.ResetBox2.Location = Point(150,30)
     
    		self.RadioButton2 = RadioButton()
    		self.RadioButton2.Text = "Unmask"
    		self.RadioButton2.Parent = self.ResetBox2
    		self.RadioButton2.Location = Point(5, 10)
    		self.RadioButton2.Size = Size(90,15)
     
    		self.RadioButton2bis = RadioButton()
    		self.RadioButton2bis.Text = "Mask"
    		self.RadioButton2bis.Parent = self.ResetBox2
    		self.RadioButton2bis.Location = Point(150, 10)
    		self.RadioButton2bis.Size = Size(80,15)
    		self.RadioButton2bis.Checked = True
     
     
    		self.Controls.Add(self.labelAlarm)
    		self.Controls.Add(self.ResetBox)
    		self.Controls.Add(self.ResetBox2)
     
     
    class Alarm_ICE(Form):
     
    	def __init__ (self):
     
    		self.Text = "Gestion Alarmes ICE"
    		self.Height = 800
    		self.Width = 500
    		self.CenterToScreen()
    		PanneauHeight = 65
    		self.ResetAlarm = []
    		self.AlarmEna = []
     
    		label = Label()
    		label.Text = "TC_ALARM_ICE"
    		label.Location = Point(180, 5)
    		label.Size = Size(100,15)
    		label.Parent = self
     
    		### Alarme 1 ICE ###
    		self.Panneau1 = Panel()
    		self.Panneau1.Location = Point(0,30)
    		self.Panneau1.Size = Size(self.Width,PanneauHeight)
    		self.Panneau1.BorderStyle = BorderStyle.FixedSingle
     
    		# GroupeAlrmBox 1
    		self.c1 = GroupeAlrmBox()
    		self.c1.Size = Size(self.Panneau1.Width,self.Panneau1.Height)
    		self.c1.Parent = self.Panneau1
    		self.c1.labelAlarm.Text = "Alarme 1 ICE"
     
    		### Alarme 2 ###
    		self.Panneau2 = Panel()
    		self.Panneau2.Location = Point(0,30+PanneauHeight)
    		self.Panneau2.Size = Size(self.Width,PanneauHeight)
    		self.Panneau2.BorderStyle = BorderStyle.FixedSingle
     
    		# GroupeAlrmBox 2
    		self.c2 = GroupeAlrmBox()
    		self.c2.Size = Size(self.Panneau2.Width,self.Panneau2.Height)
    		self.c2.Parent = self.Panneau2
    		self.c2.labelAlarm.Text = "Alarme 2 ICE"
     
    		### Alarme 3 ICE ###
    		self.Panneau3 = Panel()
    		self.Panneau3.Location = Point(0,30+2*PanneauHeight)
    		self.Panneau3.Size = Size(self.Width,PanneauHeight)
    		self.Panneau3.BorderStyle = BorderStyle.FixedSingle
     
    		# GroupeAlrmBox 3
    		self.c3 = GroupeAlrmBox()
    		self.c3.Size = Size(self.Panneau3.Width,self.Panneau3.Height)
    		self.c3.Parent = self.Panneau3
    		self.c3.labelAlarm.Text = "Alarme 3 ICE"
     
    		### Alarme 4 ICE ###
    		self.Panneau4 = Panel()
    		self.Panneau4.Location = Point(0,30+3*PanneauHeight)
    		self.Panneau4.Size = Size(self.Width,PanneauHeight)
    		self.Panneau4.BorderStyle = BorderStyle.FixedSingle
     
    		# GroupeAlrmBox 4
    		self.c4 = GroupeAlrmBox()
    		self.c4.Size = Size(self.Panneau4.Width,self.Panneau4.Height)
    		self.c4.Parent = self.Panneau4
    		self.c4.labelAlarm.Text = "Alarme 4 ICE"		
     
    		### Alarme 5 ICE ###
    		self.Panneau5 = Panel()
    		self.Panneau5.Location = Point(0,30+4*PanneauHeight)
    		self.Panneau5.Size = Size(self.Width,PanneauHeight)
    		self.Panneau5.BorderStyle = BorderStyle.FixedSingle
     
    		# GroupeAlrmBox 5
    		self.c5 = GroupeAlrmBox()
    		self.c5.Size = Size(self.Panneau5.Width,self.Panneau5.Height)
    		self.c5.Parent = self.Panneau5
    		self.c5.labelAlarm.Text = "Alarme 5 ICE"
     
    		### Alarme 6 ICE ###
    		self.Panneau6 = Panel()
    		self.Panneau6.Location = Point(0,30+5*PanneauHeight)
    		self.Panneau6.Size = Size(self.Width,PanneauHeight)
    		self.Panneau6.BorderStyle = BorderStyle.FixedSingle
     
    		# GroupeAlrmBox 6
    		self.c6 = GroupeAlrmBox()
    		self.c6.Size = Size(self.Panneau5.Width,self.Panneau5.Height)
    		self.c6.Parent = self.Panneau6
    		self.c6.labelAlarm.Text = "Alarme 6 ICE"
     
    		# Bouton OK/Cancel
    		self.button1 = Button()
    		self.button1.Text = "Ok"
    		self.button1.Location = Point(100, 500)
    		self.button1.Click += self.ok
     
    		self.button2 = Button()
    		self.button2.Text = "Cancel"
    		self.button2.Location = Point(200, 500)
    		self.button2.Click += self.cancel
     
    		self.Controls.Add(self.button1)
    		self.Controls.Add(self.button2)
    		self.Controls.Add(self.Panneau1)		
    		self.Controls.Add(self.Panneau2)
    		self.Controls.Add(self.Panneau3)
    		self.Controls.Add(self.Panneau4)
    		self.Controls.Add(self.Panneau5)
    		self.Controls.Add(self.Panneau6)
     
    	def ok(self, sender, event):
    		res1 = int(self.c1.RadioButton1.Checked)
    		res2 = int(self.c2.RadioButton1.Checked)
    		res3 = int(self.c3.RadioButton1.Checked)
    		res4 = int(self.c4.RadioButton1.Checked)
    		res5 = int(self.c5.RadioButton1.Checked)
    		res6 = int(self.c6.RadioButton1.Checked)
    		ena1 = int(self.c1.RadioButton2.Checked)
    		ena2 = int(self.c2.RadioButton2.Checked)
    		ena3 = int(self.c3.RadioButton2.Checked)
    		ena4 = int(self.c4.RadioButton2.Checked)
    		ena5 = int(self.c5.RadioButton2.Checked)
    		ena6 = int(self.c6.RadioButton2.Checked)
    		self.ResetAlarm = [res1,res2,res3,res4,res5,res6]
    		self.AlarmEna = [ena1,ena2,ena3,ena4,ena5,ena6]
    		self.Close()
     
    	def cancel(self, sender, event):
    		dr = showYesNo("Etes vous sur de vouloir quitter le module en cours ?", "Message operateur")
    		if dr == True:
    			self.Close()
    j'appelle ensuite ma classe avec un Application.Run(Alarm_ICE())
    et je récupère mes variables AlarmAna et ResetAlarm...

Discussions similaires

  1. [Débutant] Re-masquer la sub New dans une class Form
    Par noftal dans le forum Visual Studio
    Réponses: 2
    Dernier message: 23/10/2013, 17h07
  2. [Tableaux] Gestion tableau dans une classe
    Par lolodev dans le forum Langage
    Réponses: 5
    Dernier message: 06/08/2007, 13h19
  3. Réponses: 5
    Dernier message: 25/07/2007, 15h34
  4. Gestion clavier dans une form avec dbgrid
    Par albedo dans le forum C++Builder
    Réponses: 3
    Dernier message: 25/04/2006, 15h42
  5. Réponses: 13
    Dernier message: 25/03/2005, 11h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo