OVH Cloud OVH Cloud

Controle du genre : LabelTextControl ???

2 réponses
Avatar
[[ Olivier ]]
Bonjour

Pour afficher mes données, je dois (comme tout le monde) mettre un Label
pour le titre du champs et un TextBox pour la valeur.
bon, ca j'en ai beaucoup à faire, et c'est un peu pénible de devoir à chaque
fois aligner le label avec le textbox quand y en a plusieurs. Et quand il
faut changer leur emplacement, c'est galère.

Bref, existe-t'il un control qui ferai les deux automatiquement :
Un genre de : LabelTextControl ?

Merci
Olivier

2 réponses

Avatar
Olivier
C'est ce que j'essaye de faire, mais bon, je débute et c'est pas façile.

Merci quand même

Olivier


"LEBRUN Thomas" <lebrun_thomas_at_hotmail.com> a écrit dans le message de
news:
Pourquoi ne pas créer ton propre composant ? Car je pense que c'est le
mieux
: à ma connaissance (mais je ne les connais pas tous), il n'existe pas de
composant regroupant une TextBox et un Label.

A+

-------------------
LEBRUN Thomas
http://morpheus.developpez.com


"[[ Olivier ]]" wrote:

Bonjour

Pour afficher mes données, je dois (comme tout le monde) mettre un Label
pour le titre du champs et un TextBox pour la valeur.
bon, ca j'en ai beaucoup à faire, et c'est un peu pénible de devoir à
chaque
fois aligner le label avec le textbox quand y en a plusieurs. Et quand il
faut changer leur emplacement, c'est galère.

Bref, existe-t'il un control qui ferai les deux automatiquement :
Un genre de : LabelTextControl ?

Merci
Olivier







Avatar
Ghislain Proulx
Bonjour Olivier,

Voici qui devrait te donner un coup de main, c'est loin d'être parfait mais
c'est un très bon début je crois.

Bonne journée

Ghislain Proulx
=========================================================================== === Imports System.ComponentModel

Public Class LabelTextBox
Inherits System.Windows.Forms.UserControl

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'UserControl overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents lbl As System.Windows.Forms.Label
Friend WithEvents txt As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.lbl = New System.Windows.Forms.Label
Me.txt = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'lbl
'
Me.lbl.AutoSize = True
Me.lbl.Location = New System.Drawing.Point(0, 0)
Me.lbl.Name = "lbl"
Me.lbl.Size = New System.Drawing.Size(26, 16)
Me.lbl.TabIndex = 0
Me.lbl.Text = "Title"
Me.lbl.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
'txt
'
Me.txt.Location = New System.Drawing.Point(96, 0)
Me.txt.Name = "txt"
Me.txt.Size = New System.Drawing.Size(192, 20)
Me.txt.TabIndex = 1
Me.txt.Text = ""
'
'LabelTextBox
'
Me.Controls.Add(Me.txt)
Me.Controls.Add(Me.lbl)
Me.Name = "LabelTextBox"
Me.Size = New System.Drawing.Size(296, 20)
Me.ResumeLayout(False)

End Sub

#End Region

Public Enum TextBoxWidthStyles
RightAnchor = 1
UserDefine = 2
End Enum

Private Const LabelPadding As Int32 = 5

Private _TextBoxWidthStyle As TextBoxWidthStyles TextBoxWidthStyles.RightAnchor
Private _TextBoxWidth As Int32 = 100

<Category("Appearance"), Description("Permet de définir le 'look' du
Textbox dans le contrôle"), DefaultValue(GetType(TextBoxWidthStyles), "1")>
_
Public Property TextBoxWidthStyle() As TextBoxWidthStyles
Get
Return _TextBoxWidthStyle
End Get
Set(ByVal Value As TextBoxWidthStyles)
_TextBoxWidthStyle = Value
Me.Invalidate()
End Set
End Property

<Category("Appearance"), Description("Permet de définir la largeur du
Textbox dans le contrôle lorsque la propriété TextBoxWidthStyle UserDefine"), DefaultValue(GetType(Int32), "100")> _
Public Property TextBoxWidth() As Int32
Get
Return _TextBoxWidth
End Get
Set(ByVal Value As Int32)
_TextBoxWidth = Value
Me.Invalidate()
End Set
End Property

<Category("Appearance"), Description("Permet de définir un titre au
contrôle. Ce titre s'affiche dans la portion 'Label' du contrôle."),
DefaultValue(GetType(String), "")> _
Public Property Title() As String
Get
Return lbl.Text
End Get
Set(ByVal Value As String)
lbl.Text = Value
Me.Invalidate()
End Set
End Property

<Category("Appearance"), Description("Permet de définir le texte du
contrôle. Ce texte s'affiche dans la portion 'TextBox' du contrôle."),
DefaultValue(GetType(String), "")> _
Public Property TextBoxText() As String
Get
Return txt.Text
End Get
Set(ByVal Value As String)
txt.Text = Value
End Set
End Property

<Category("Appearance"), Description("Permet de définir un l'alignement du
titre."), DefaultValue(GetType(System.Drawing.ContentAlignment),
"MiddleLeft")> _
Public Property TitleAlign() As System.Drawing.ContentAlignment
Get
Return lbl.TextAlign
End Get
Set(ByVal Value As System.Drawing.ContentAlignment)
lbl.TextAlign = Value
Me.Invalidate()
End Set
End Property

Private Sub LabelTextBox_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

Try
Me.SuspendLayout()
txt.Left = lbl.Width + LabelPadding
Select Case _TextBoxWidthStyle
Case TextBoxWidthStyles.RightAnchor
txt.Width = Me.Width - txt.Left

Case TextBoxWidthStyles.UserDefine
txt.Width = _TextBoxWidth
End Select

Select Case lbl.TextAlign
Case ContentAlignment.TopLeft, ContentAlignment.TopLeft,
ContentAlignment.TopRight
lbl.Top = 0

Case ContentAlignment.MiddleCenter, ContentAlignment.MiddleLeft,
ContentAlignment.MiddleRight
lbl.Top = (Me.Height - lbl.Height) / 2

Case ContentAlignment.BottomCenter, ContentAlignment.BottomLeft,
ContentAlignment.BottomRight
lbl.Top = Me.Height - lbl.Height
End Select

Catch ex As Exception
Throw New Exception("LabelTextBox internal error", ex)

Finally
Me.ResumeLayout()

End Try

End Sub

Private Sub LabelTextBox_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Resize
' Il existe une meilleur manière d'empêcher le redimensionnement dans un
sens
' mais ça ne me revient pas ce soir.
Me.Height = txt.Height
End Sub

End Class


=============================================================== "Olivier" a écrit dans le message de
news:%23x$
C'est ce que j'essaye de faire, mais bon, je débute et c'est pas façile.

Merci quand même

Olivier


"LEBRUN Thomas" <lebrun_thomas_at_hotmail.com> a écrit dans le message de
news:
> Pourquoi ne pas créer ton propre composant ? Car je pense que c'est le
> mieux
> : à ma connaissance (mais je ne les connais pas tous), il n'existe pas


de
> composant regroupant une TextBox et un Label.
>
> A+
>
> -------------------
> LEBRUN Thomas
> http://morpheus.developpez.com
>
>
> "[[ Olivier ]]" wrote:
>
>> Bonjour
>>
>> Pour afficher mes données, je dois (comme tout le monde) mettre un


Label
>> pour le titre du champs et un TextBox pour la valeur.
>> bon, ca j'en ai beaucoup à faire, et c'est un peu pénible de devoir à
>> chaque
>> fois aligner le label avec le textbox quand y en a plusieurs. Et quand


il
>> faut changer leur emplacement, c'est galère.
>>
>> Bref, existe-t'il un control qui ferai les deux automatiquement :
>> Un genre de : LabelTextControl ?
>>
>> Merci
>> Olivier
>>
>>
>>






---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 2004-09-10