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

VB.NET Discussion :

orientation d'un rectangle dans une classe


Sujet :

VB.NET

  1. #1
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2018
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2018
    Messages : 274
    Points : 237
    Points
    237
    Par défaut orientation d'un rectangle dans une classe
    Bonsoir,

    je voudrais savoir comment orienter vertical ou Horizontal d'un rectangle dans un classe. j'arrive pas a orienter en vertical mon rectangle. pouvez-vous m'aider à orienter le rectangle en verticale.

    mon code :
    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
    Imports System.Drawing.Drawing2D
     
    Public Class RotationRectangle
        Inherits Control
     
        Private _Orientation As position
     
        Property Orientation As position
            Get
                Return _Orientation
            End Get
            Set(ByVal value As position)
                _Orientation = value
                Invalidate()
            End Set
        End Property
     
        Public Sub New()
            SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or _
                    ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer, True)
            Me.Size = New Size(200, 20)
            Me.DoubleBuffered = True
        End Sub
     
        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
            MyBase.OnPaint(e)
            Dim rect As New Rectangle(0, 0, Width - 1, Height - 1)
            With e.Graphics
                .SmoothingMode = SmoothingMode.HighQuality
                Select Case _Orientation
                    Case position.Horizontal
                        e.Graphics.ResetTransform()
                        Exit Select
                    Case position.Vertical
                        e.Graphics.TranslateTransform(0, rect.Height)
                        e.Graphics.RotateTransform(-90)
                        Exit Select
                End Select
                .DrawRectangle(New Pen(New SolidBrush(Color.Black)), rect)
            End With
        End Sub
     
        Enum position
            Horizontal = 0
            Vertical = 1
        End Enum
    End Class
    merci de votre aide.

  2. #2
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour

    Ton rectangle s'oriente en vertical maos le "hic" avec un rectangle dont les dimensions sont celles du Rectangle Client du control c'est qu'apres rotation une partie de celui-ci ne sera pas visible ,puisque le control est lui-meme un "rectangle" qui a une orientation donnée...
    il faut plus de precision sur ce que tu veux obtenir au juste...

  3. #3
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2018
    Messages
    274
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2018
    Messages : 274
    Points : 237
    Points
    237
    Par défaut
    Bonjour,

    j'ai trouver la solution en mode Horizontal / Vertical pour mon rectangle. j'ai ajouter dans mon rectangle une couleur bleu mais j'arrive pas à obtenir à 50 % de la couleur comme un progressbar.

    mon code modifier :
    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
    Imports System.Drawing.Drawing2D
     
    Public Class RotationRectangle
        Inherits Control
     
        Private Horz As Boolean = True
        Private barColor As Color = Color.Blue
        Public Property Horizontal() As Boolean
            Get
                Return Horz
            End Get
            Set(ByVal Value As Boolean)
                If Value <> Horz Then
                    Dim tmp As Integer = Me.Width
                    Me.Width = Me.Height
                    Me.Height = tmp
                End If
                Horz = Value
            End Set
        End Property
        Private _Maximum As Integer = 100
        Public Property Maximum As Integer
            Get
                Return _Maximum
            End Get
            Set(ByVal v As Integer)
                If v < 1 Then v = 1
                If v < _Value Then _Value = v
                _Maximum = v
                Invalidate()
            End Set
        End Property
     
        Private _Value As Integer = 0
        Public Property Value As Integer
            Get
                Return _Value
            End Get
            Set(ByVal v As Integer)
                If v > _Maximum Then v = Maximum
                _Value = v
                Invalidate()
            End Set
        End Property
        Public Sub New()
            MyBase.New()
            SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or _
                    ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer, True)
            Me.Size = New Size(200, 20)
            Me.DoubleBuffered = True
        End Sub
     
        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
            MyBase.OnPaint(e)
            Dim rect As New Rectangle(0, 0, Width - 1, Height - 1)
            Dim brush As SolidBrush = New SolidBrush(barColor)
            e.Graphics.SmoothingMode = SmoothingMode.HighQuality
            With Me.ClientRectangle
                If Horz Then
                    Dim barRect As New Rectangle(0, 0, CInt(((Width / _Maximum) * _Value) - 1), Height - 1) '...Horizental
                    e.Graphics.FillRectangle(brush, barRect)
                Else
                    Dim barRect As New Rectangle(0, 0, CInt(((Height / _Maximum) * _Value) - 1), Width - 1) '...vertical
                    e.Graphics.FillRectangle(brush, barRect)
                End If
            End With
            e.Graphics.DrawRectangle(New Pen(New SolidBrush(Color.Black)), rect)
        End Sub
     
        Protected Overrides Sub OnResize(ByVal e As EventArgs)
            MyBase.OnResize(e)
            Me.Invalidate()
        End Sub
    End Class
    voici en image en mode vertical :
    Nom : Capture.PNG
Affichages : 118
Taille : 529 octets

    mon problème c'est en mode vertical. Quand je tape une valeur 50 j'arrive pas à obtenir la moitié de la couleur comme un progressbar en vertical?
    Pouvez-vous m'aider à résoudre avec fillrectangle en mode vertical.
    Merci

  4. #4
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour

    ha ,ha les petits les gros nagent bien
    les gros ,les petits nagent aussi bien (j'ai mon petit fils de 2 ans à coté de moi...
    C'est donc un progressbar !!!
    Ton code est pipé car:
    - la prop Minimum manque...
    - la restriction de la prop Value courante dans les limites Minimum -Maximum est "absconse"(incomprehensible)...
    - le rectangle "barre" à peindre est faux et hideux...

    Voici un usercontrol "smoothing" progressbar (que tu peux essayer avec un timer sur le form user)...

    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
     
    Imports System.Drawing.Drawing2D
    Imports System.ComponentModel
     
     
    Public Class RotationRectangle
        Inherits Control
        Private min As Integer = 0               ' Minimum value for progress range
        Private max As Integer = 100             ' Maximum value for progress range
        Private val As Integer = 0               ' Current progress
     
        Private Horz As Boolean = True
        Private m_barColor As Color = Color.Blue
        <Browsable(True)>
        Public Property BarColor() As Color
            Get
                Return m_barColor
            End Get
            Set(ByVal Value As Color)
                If Value <> m_barColor Then
                    m_barColor = Value
                    Me.Invalidate()
                End If
            End Set
        End Property
        <Browsable(True)>
        Public Property Horizontal() As Boolean
            Get
                Return Horz
            End Get
            Set(ByVal Value As Boolean)
                If Value <> Horz Then
                    Dim tmp As Integer = Me.Width
                    Me.Width = Me.Height
                    Me.Height = tmp
                End If
                Horz = Value
            End Set
        End Property
        <Browsable(True)>
        Public Property Maximum As Integer
            Get
                Return max
            End Get
            Set(ByVal value As Integer)
                ' Make sure that the maximum value is never set lower than the minimum value.
                If (value < min) Then
                    min = value
                End If
     
                max = value
     
                ' Make sure that the value is still in range.
                If (val > max) Then
                    val = max
                End If
     
                Invalidate()
            End Set
        End Property
        <Browsable(True)>
        Public Property Minimum As Integer
            Get
                Return min
            End Get
            Set(ByVal value As Integer)
                ' Prevent a negative value.
                If (value < 0) Then
                    min = 0
                End If
     
                ' Make sure that the minimum value is never set higher than the maximum value.
                If (value > max) Then
                    min = value
                End If
     
                ' Make sure that the value is still in range.
                If (val < min) Then
                    val = min
                End If
     
     
                Invalidate()
            End Set
        End Property
        <Browsable(True)>
        Public Property Value As Integer
            Get
                Return val
            End Get
            Set(ByVal value As Integer)
                ' Make sure that the value does not stray outside the valid range.
                If (value < min) Then
                    val = min
                ElseIf (value > max) Then
                    val = max
                Else
                    val = value
                End If
     
                Invalidate()
            End Set
        End Property
        Public Sub New()
            InitializeComponent()
            SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or _
                    ControlStyles.ResizeRedraw Or ControlStyles.OptimizedDoubleBuffer, True)
            Me.Size = New Size(200, 20)
            Me.DoubleBuffered = True
        End Sub
     
        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
            MyBase.OnPaint(e)
            Dim percent As Decimal = (Value - min) / (max - min)
            Dim rect As New Rectangle(0, 0, Me.ClientRectangle.Width - 1, Me.ClientRectangle.Height - 1)
            Dim gr As Graphics = e.Graphics
     
            Dim brush As SolidBrush = New SolidBrush(m_barColor)
            e.Graphics.SmoothingMode = SmoothingMode.HighQuality
            With Me.ClientRectangle
                If Horz Then
                    Dim bar As New Rectangle(0, 0, rect.Width, rect.Height)   'Horizental
     
                    ' Calculate area for drawing the progress.
                    bar.Width = rect.Width * percent
                    gr.FillRectangle(brush, bar)
                Else
                    Dim bar As New Rectangle(0, 0, rect.Height, rect.Width) ' vertical
                    ' Calculate area for drawing the progress.
                    bar.Height = rect.Height * percent
                    gr.FillRectangle(brush, bar)
                End If
            End With
            gr.DrawRectangle(New Pen(New SolidBrush(Color.Red)), rect)
        End Sub
     
        Protected Overrides Sub OnResize(ByVal e As EventArgs)
            MyBase.OnResize(e)
            Me.Invalidate()
        End Sub
    End Class
    les petits les gros nagent bien
    les gros ,les petits nagent aussi bien (j'ai mon petit fils de 2 ans à coté de moi...
    Surtout par temps de canicule (chez moi on est à 44 degres depuis 4 jours & 30 degres de nuit)...
    Je m'alimente à peine et je bois des tonnes d'eau minerale !!!
    Allah peut nous faire disparaitre illico presto comme des moustiques...
    bon code...

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 0
    Dernier message: 18/03/2012, 15h33
  2. Réponses: 8
    Dernier message: 09/07/2005, 23h10
  3. [Thread] Erreur dans une classe interne
    Par totof2308 dans le forum Général Java
    Réponses: 5
    Dernier message: 03/06/2004, 08h15
  4. Thread dans une classe ?
    Par Sephi dans le forum Threads & Processus
    Réponses: 7
    Dernier message: 07/03/2004, 18h16
  5. Fonction callback dans une classe
    Par julian_ross dans le forum MFC
    Réponses: 8
    Dernier message: 02/03/2004, 11h42

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