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

Windows Forms Discussion :

[VB.NET] [#Develop] Label redimensionnable [Trucs & Astuces]


Sujet :

Windows Forms

  1. #1
    En attente de confirmation mail
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    1 249
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 1 249
    Points : 314
    Points
    314
    Par défaut [VB.NET] [#Develop] Label redimensionnable
    Bonjours,

    -j'ai fais un Label qui est deplaçable et redimensionable en hauteur. Le problème est que pendant le redimensionnement, il y a des clignotements qui se fond. Comment faire pour les éviter ?

    -de plus dans mon userform, j'ai créer un label transparent et bizarement il ne l'ai pas. quelqu'un a-t-il une solution ?

    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
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
     
    '
    ' Created by SharpDevelop.
    ' User: 
    ' Date: 12/01/2005
    ' Time: 11:45
    ' 
    ' To change this template use Tools | Options | Coding | Edit Standard Headers.
    '
    Imports System
    Imports System.Drawing
    Imports System.Windows.Forms
     
    Namespace zone1
     
    	Public Class MainForm
    		Inherits System.Windows.Forms.Form
    		Private labelhaut As System.Windows.Forms.Label
    		Private labelmilieu As System.Windows.Forms.Label
    		Private labelbas As System.Windows.Forms.Label
    		Private label1 As System.Windows.Forms.Label
     
    		Public Shared Sub Main
    			Dim fMainForm As New MainForm
    			fMainForm.ShowDialog()
    		End Sub
     
    		Public Sub New()
    			MyBase.New
    			'
    			' The Me.InitializeComponent call is required for Windows Forms designer support.
    			'
    			Me.InitializeComponent
    			'
    			' TODO : Add constructor code after InitializeComponents
    			'
    		End Sub
     
    		#Region " Windows Forms Designer generated code "
    		' This method is required for Windows Forms designer support.
    		' Do not change the method contents inside the source code editor. The Forms designer might
    		' not be able to load this method if it was changed manually.
    		Private Sub InitializeComponent()
    			Me.label1 = New System.Windows.Forms.Label
    			Me.labelbas = New System.Windows.Forms.Label
    			Me.labelmilieu = New System.Windows.Forms.Label
    			Me.labelhaut = New System.Windows.Forms.Label
    			Me.SuspendLayout
    			'
    			'label1
    			'
    			Me.label1.BackColor = System.Drawing.Color.Transparent
    			Me.label1.Location = New System.Drawing.Point(360, 88)
    			Me.label1.Name = "label1"
    			Me.label1.Size = New System.Drawing.Size(184, 136)
    			Me.label1.TabIndex = 3
    			Me.label1.Text = "label1"
    			'
    			'labelbas
    			'
    			Me.labelbas.BackColor = System.Drawing.Color.Gray
    			Me.labelbas.Location = New System.Drawing.Point(160, 216)
    			Me.labelbas.Name = "labelbas"
    			Me.labelbas.Size = New System.Drawing.Size(128, 8)
    			Me.labelbas.TabIndex = 1
    			Me.labelbas.Text = "label2"
    			AddHandler Me.labelbas.MouseUp, AddressOf Me.LabelbasMouseUp
    			AddHandler Me.labelbas.MouseMove, AddressOf Me.LabelbasMouseMove
    			AddHandler Me.labelbas.MouseDown, AddressOf Me.LabelbasMouseDown
    			'
    			'labelmilieu
    			'
    			Me.labelmilieu.BackColor = System.Drawing.SystemColors.ActiveCaption
    			Me.labelmilieu.Location = New System.Drawing.Point(160, 128)
    			Me.labelmilieu.Name = "labelmilieu"
    			Me.labelmilieu.Size = New System.Drawing.Size(128, 88)
    			Me.labelmilieu.TabIndex = 0
    			Me.labelmilieu.Text = "label1"
    			AddHandler Me.labelmilieu.MouseUp, AddressOf Me.LabelmilieuMouseUp
    			AddHandler Me.labelmilieu.MouseMove, AddressOf Me.LabelmilieuMouseMove
    			AddHandler Me.labelmilieu.MouseDown, AddressOf Me.LabelmilieuMouseDown
    			'
    			'labelhaut
    			'
    			Me.labelhaut.BackColor = System.Drawing.Color.IndianRed
    			Me.labelhaut.Location = New System.Drawing.Point(160, 120)
    			Me.labelhaut.Name = "labelhaut"
    			Me.labelhaut.Size = New System.Drawing.Size(128, 8)
    			Me.labelhaut.TabIndex = 2
    			Me.labelhaut.Text = "label3"
    			AddHandler Me.labelhaut.MouseMove, AddressOf Me.LabelhautMouseMove
    			AddHandler Me.labelhaut.MouseDown, AddressOf Me.LabelhautMouseDown
    			'
    			'MainForm
    			'
    			Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    			Me.ClientSize = New System.Drawing.Size(608, 398)
    			Me.Controls.Add(Me.label1)
    			Me.Controls.Add(Me.labelhaut)
    			Me.Controls.Add(Me.labelbas)
    			Me.Controls.Add(Me.labelmilieu)
    			Me.Name = "MainForm"
    			Me.Text = "MainForm"
    			Me.ResumeLayout(false)
    		End Sub
    		#End Region
     
    		Private Xp, Yp As Integer
     
    		Private Sub LabelMilieuMouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs)
    			Xp = e.x
    			Yp = e.y			
    		End Sub
     
    		Private Sub LabelHautMouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs)
    			Xp = e.x
    			Yp = e.y
    		End Sub
     
    		Private Sub LabelBasMouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs)
    			Xp = e.x
    			Yp = e.y
    		End Sub
     
    		Private Sub LabelMilieuMouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs)
    		'deplace le label
     
    			Dim LabelTop, LabelLeft as integer
    			'MessageBox.Show("Bonjour")
     
    			If e.Button	= MouseButtons.Left Then
    				LabelTop = LabelMilieu.Top - Yp + e.y
    				LabelLeft = LabelMilieu.Left - Xp + e.x
     
    				Me.LabelMilieu.Top = LabelTop
    				Me.LabelMilieu.Left = LabelLeft
     
    				Me.LabelHaut.Top = LabelTop - 8
    				Me.LabelHaut.Left = LabelLeft
     
    				Me.LabelBas.Top = LabelTop + LabelMilieu.Height
    				Me.LabelBas.Left = LabelLeft				
    			end if
    		End Sub
     
    		Private Sub LabelHautMouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs)
    		'redimensionne le label
     
    			Dim AgrandissementY as Integer
    			Dim NewHeight As Integer
     
    			If e.Button	= MouseButtons.Left Then
    				AgrandissementY = - Yp + e.y
    				NewHeight = Me.LabelMilieu.Height - AgrandissementY
     
    				if NewHeight < 16 then 'empeche que le label soit inférieur à 16px
    					Me.LabelMilieu.Height = 16
    					Me.LabelMilieu.Top = Me.LabelBas.Top - 16
    					Me.LabelHaut.Top = Me.LabelMilieu.Top - 8
    				Else
    					Me.LabelHaut.Top = Me.LabelHaut.Top + AgrandissementY
    					Me.LabelMilieu.Top = Me.LabelMilieu.Top + AgrandissementY
    					Me.LabelMilieu.Height = NewHeight	
    				end if
    			End if				
    		End Sub
     
    		Private Sub LabelBasMouseMove&#40;sender As System.Object, e As System.Windows.Forms.MouseEventArgs&#41;
    		'redimensionne le label
     
    			Dim AgrandissementY as Integer
    			Dim NewHeight As Integer
     
    			If e.Button	= MouseButtons.Left Then
    				AgrandissementY = - Yp + e.y
    				NewHeight = Me.LabelMilieu.Height + AgrandissementY	
     
    				if NewHeight < 16 then 'empeche que le label soit inférieur à 16px
    					Me.LabelMilieu.Height = 16
    					Me.LabelBas.Top = Me.LabelMilieu.Top + 16
    				Else
    					Me.LabelBas.Top = Me.LabelBas.Top + AgrandissementY				
    					Me.LabelMilieu.Height = NewHeight	
    				End if
    			End if					
    		End Sub
     
    		Private Sub LabelmilieuMouseUp&#40;sender As System.Object, e As System.Windows.Forms.MouseEventArgs&#41;
     
    		End Sub
     
    		Private Sub LabelbasMouseUp&#40;sender As System.Object, e As System.Windows.Forms.MouseEventArgs&#41;
     
    		End Sub
     
    	End Class
    End Namespace

  2. #2
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Essaye de voir du coté de Invalidate pour éviter les clignotements.

  3. #3
    En attente de confirmation mail
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    1 249
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 1 249
    Points : 314
    Points
    314
    Par défaut
    comment ça s'utilise cette propriété (j'ai cherché sur msdn mais j'ai pas compris comment ça fonctionne)?

  4. #4
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    29
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 29
    Points : 29
    Points
    29
    Par défaut
    pour les pb de scintillement tu peux essayer ceci (c'ést du C# mais il ne devrait pas y avoir de raison pour que ça ne marche pas en VBNET)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    SetStyle&#40;ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true&#41;;
    (dans le constructeur du contrôle)

  5. #5
    En attente de confirmation mail
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    1 249
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 1 249
    Points : 314
    Points
    314
    Par défaut
    finalement j'ai réussit à le faire en faisant comme ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    Private Sub MainFormLoad&#40;sender As System.Object, e As System.EventArgs&#41;
     
    			SetStyle&#40;ControlStyles.DoubleBuffer Or ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint , True&#41; 
              	SetStyle&#40;ControlStyles.ResizeRedraw, True&#41; 'le controle est redissiné lors de son redimensionnement 
              	SetStyle&#40;ControlStyles.SupportsTransparentBackColor, True&#41; 'gère les couleurs transparentes 
     
     
    		End Sub
    est-ce que cette méthode te semble bonne ?
    mais les couleurs transparentes ne fonctionnent pas

Discussions similaires

  1. [VB.NET] un label qui ne rends pas son texte
    Par zooffy dans le forum ASP.NET
    Réponses: 6
    Dernier message: 09/01/2007, 13h07
  2. [VB.NET 2.0] redimensionner control
    Par Emcy dans le forum VB.NET
    Réponses: 2
    Dernier message: 21/12/2006, 15h35
  3. [VB.NET][2.0] Redimensionner une image
    Par DotNET74 dans le forum Windows Forms
    Réponses: 4
    Dernier message: 27/06/2006, 10h30
  4. [débutant] [VB.NET] Timer + label + checkbox ...
    Par Amenos dans le forum Windows Forms
    Réponses: 14
    Dernier message: 27/03/2006, 14h26
  5. [VB.NET] - Probleme Label avec Database
    Par codez dans le forum ASP.NET
    Réponses: 4
    Dernier message: 03/06/2004, 18h37

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