Bonjours,
j'ai créer dans un userform, un label deplaçable et redimensionnable en hauteur : je voudrais pouvoir créer simplement autant d'element de ce type que je veux. Comment faire ? je crois qu'il faut que je crée un controle mais je n'y arrive pas : pouvez-vous m'aidez ?
voici le code complet de mon userfrom :
Code:
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Namespace zone1
Public Class MainForm
Inherits System.Windows.Forms.Form
Private labelmilieu As System.Windows.Forms.Label
Private labelhaut As System.Windows.Forms.Label
Private labelbas 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.labelbas = New System.Windows.Forms.Label
Me.labelhaut = New System.Windows.Forms.Label
Me.labelmilieu = New System.Windows.Forms.Label
Me.SuspendLayout
'
'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
'
'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
'
'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
'
'MainForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(608, 398)
Me.Controls.Add(Me.labelhaut)
Me.Controls.Add(Me.labelbas)
Me.Controls.Add(Me.labelmilieu)
Me.Name = "MainForm"
Me.Text = "MainForm"
AddHandler Load, AddressOf Me.MainFormLoad
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.Top = Me.LabelBas.Top - 16
Me.LabelMilieu.Height = 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(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.LabelBas.Top = Me.LabelMilieu.Top + 16
Me.LabelMilieu.Height = 16
Else
Me.LabelBas.Top = Me.LabelBas.Top + AgrandissementY
Me.LabelMilieu.Height = NewHeight
End if
End if
End Sub
Private Sub LabelmilieuMouseUp(sender As System.Object, e As System.Windows.Forms.MouseEventArgs)
End Sub
Private Sub LabelbasMouseUp(sender As System.Object, e As System.Windows.Forms.MouseEventArgs)
End Sub
Private Sub MainFormLoad(sender As System.Object, e As System.EventArgs)
SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint , True)
SetStyle(ControlStyles.ResizeRedraw, True) 'le controle est redissiné lors de son redimensionnement
SetStyle(ControlStyles.SupportsTransparentBackColor, True) 'gère les couleurs transparentes
End Sub
Private Sub AlphaBlendTextBox1TextChanged(sender As System.Object, e As System.EventArgs)
End Sub
End Class
End Namespace