JUANABIBI
Messages postés40Date d'inscriptionmardi 17 mars 2020StatutMembreDernière intervention10 avril 2020
-
6 avril 2020 à 17:57
Whismeril
Messages postés18416Date d'inscriptionmardi 11 mars 2003StatutContributeurDernière intervention 1 juin 2023
-
7 avril 2020 à 12:08
Bonjour à tous,
J'ai un Panel, qui regroupe plusieurs Radiobuttons.
Voici l'image :
L'utilisateur doit cliquer sur un des trois bouton pour chaque ligne.
Le problème est que si je crée des Groupbox, ça va être très laid, et je n'ai pas d'espace pour créer des panels.
J'ai essayé de regrouper les radiobuttons en Groupes.
JUANABIBI
Messages postés40Date d'inscriptionmardi 17 mars 2020StatutMembreDernière intervention10 avril 2020 7 avril 2020 à 09:33
Merci beaucoup de la réponse !
Je ne travaille pas en WPF, malheureusement ...
J'ai essayé de convertir la classe que tu m'as fournie, elle est en C# et si je la passe en VB.net, j'ai plusieurs erreurs.
La voici :
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Diagnostics
Imports System.Windows.Forms.VisualStyles
Imports System.Drawing
Imports System.ComponentModel
Namespace Use.your.own
Public Class AdvancedRadioButton
Inherits CheckBox
Public Enum Level
Parent
Form
End Enum
<Category("AdvancedRadioButton"), Description("Gets or sets the level that specifies which RadioButton controls are affected."), DefaultValue(Level.Parent)>
Public Property GroupNameLevel As Level
<Category("AdvancedRadioButton"), Description("Gets or sets the name that specifies which RadioButton controls are mutually exclusive.")>
Public Property GroupName As String
Protected Overrides Sub OnCheckedChanged(ByVal e As EventArgs)
MyBase.OnCheckedChanged(e)
If Checked Then
Dim arbControls = CType(Nothing, dynamic)
Select Case GroupNameLevel
Case Level.Parent
If Me.Parent IsNot Nothing Then arbControls = GetAll(Me.Parent, GetType(AdvancedRadioButton))
Case Level.Form
Dim form As Form = Me.FindForm()
If form IsNot Nothing Then arbControls = GetAll(Me.FindForm(), GetType(AdvancedRadioButton))
End Select
If arbControls IsNot Nothing Then
For Each control As Control In arbControls
If control <> Me AndAlso (TryCast(control, AdvancedRadioButton)).GroupName = Me.GroupName Then (TryCast(control, AdvancedRadioButton)).Checked = False
Next
End If
End If
End Sub
Protected Overrides Sub OnClick(ByVal e As EventArgs)
If Not Checked Then MyBase.OnClick(e)
End Sub
Protected Overrides Sub OnPaint(ByVal pevent As PaintEventArgs)
CheckBoxRenderer.DrawParentBackground(pevent.Graphics, pevent.ClipRectangle, Me)
Dim radioButtonState As RadioButtonState
If Checked Then
radioButtonState = RadioButtonState.CheckedNormal
If Focused Then radioButtonState = RadioButtonState.CheckedHot
If Not Enabled Then radioButtonState = RadioButtonState.CheckedDisabled
Else
radioButtonState = RadioButtonState.UncheckedNormal
If Focused Then radioButtonState = RadioButtonState.UncheckedHot
If Not Enabled Then radioButtonState = RadioButtonState.UncheckedDisabled
End If
Dim glyphSize As Size = RadioButtonRenderer.GetGlyphSize(pevent.Graphics, radioButtonState)
Dim rect As Rectangle = pevent.ClipRectangle
rect.Width -= glyphSize.Width
rect.Location = New Point(rect.Left + glyphSize.Width, rect.Top)
RadioButtonRenderer.DrawRadioButton(pevent.Graphics, New System.Drawing.Point(0, rect.Height / 2 - glyphSize.Height / 2), rect, Me.Text, Me.Font, Me.Focused, radioButtonState)
End Sub
Private Function GetAll(ByVal control As Control, ByVal type As Type) As IEnumerable(Of Control)
Dim controls = control.Controls.Cast(Of Control)()
Return controls.SelectMany(Function(ctrl) GetAll(ctrl, type)).Concat(controls).Where(Function(c) c.[GetType]() = type)
End Function
End Class
End Namespace
Première erreur :
If Checked Then
Dim arbControls = CType(Nothing, Dynamic)
Type attendu sur "Dynamic".
If control <> Me AndAlso (TryCast(control, AdvancedRadioButton)).GroupName = Me.GroupName Then (TryCast(control, AdvancedRadioButton)).Checked = False
arbControls => L'expression est un type "Dynamic" qui n'est pas une collection.
control <> Me => L'opérateur '<>' n'est pas défini pour les types 'Control' et 'AdvancedRadioButton'.
Then (Trycast => Erreur de syntaxe au niveau de la parenthèse
Je fais des recherches de mon côté, merci beaucoup encore une fois pour votre aide.
JUANABIBI
Messages postés40Date d'inscriptionmardi 17 mars 2020StatutMembreDernière intervention10 avril 2020 7 avril 2020 à 09:57
control <> Me => L'opérateur '<>' n'est pas défini pour les types 'Control' et 'AdvancedRadioButton'.
Then (Trycast => Erreur de syntaxe au niveau de la parenthèse
Correction :
If control IsNot Me AndAlso Equals(TryCast(control, AdvancedRadioButton).GroupName, GroupName) Then TryCast(control, AdvancedRadioButton).Checked = False