Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tablelayoutpanel

95 views
Skip to first unread message

Oscar

unread,
Aug 14, 2008, 5:36:57 AM8/14/08
to
Hola,

tengo un control tablelayoutpanel donde añado filas y columnas y dentro de
cada celda añado un control label, lo que quiero ahora es ajustar el tamaño
del label al tamaño de la celda, cómo lo hago?

Saludos, Oscar


Jesús López

unread,
Aug 14, 2008, 5:42:28 AM8/14/08
to
Eso se hace con la propiedad Anchor.


"Oscar" <os...@ibergest.net> escribió en el mensaje
news:uI0m%23Ef$IHA....@TK2MSFTNGP03.phx.gbl...

Oscar

unread,
Aug 14, 2008, 5:55:57 AM8/14/08
to
Este es el código que utilizo,

Dim fil, col, i, j As Integer

fil = 3 : col = 3

Tbl_Imagen.Controls.Clear()

Tbl_Imagen.RowCount = fil

While i < fil

j = 0

While j < col

Tbl_Imagen.RowStyles.Add(New RowStyle(SizeType.Percent, 100))

Dim Tbx As New Label

'Tbx.AutoSize = True

Tbx.BackColor = Color.Black

Tbl_Imagen.Controls.Add(Tbx, j, i)

j = j + 1

End While

i = i + 1

End While

que valores debeo asignar a Tbx.anchor?

Gracias de nuevo, Oscar

"Jesús López" <sqlranger.mv...@mvps.org.nospam> escribió en el
mensaje news:OoY6SIf$IHA....@TK2MSFTNGP02.phx.gbl...

Jesús López

unread,
Aug 14, 2008, 6:08:38 AM8/14/08
to
Pon el autosize del label a false, porque si no el tamaño del label se
ajustará al contenido y por tanto no podrá ajustarse al contenedor.

Para que se ajuste tanto a izda, derecha, arriba y abajo:

Tbx.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom Or AnchorStyles.Left Or
AnchorStyles.Right

"Oscar" <os...@ibergest.net> escribió en el mensaje

news:eK3rmPf$IHA....@TK2MSFTNGP06.phx.gbl...

Oscar

unread,
Aug 14, 2008, 6:14:19 AM8/14/08
to
Hola de nuevo,

por lo que he visto el anchor es para colocar el control en una determinada
posición, pero lo que yo quiero hacer es redimensionar el control label par
que ocupe toda la celda, para eso supongo que debo sacar el tamaño de cada
celda y asignarse a las propiedades width y height del control label, el
problema es que no se como sacar el tamaño de una celda de un
tablelayoutpanel...

Saludos, Oscar

"Oscar" <os...@ibergest.net> escribió en el mensaje

news:eK3rmPf$IHA....@TK2MSFTNGP06.phx.gbl...

Oscar

unread,
Aug 14, 2008, 6:19:07 AM8/14/08
to
con esa propiedad se posiciona en un lado de la celda pero no la ocupa toda
como yo quiero... como saco las medidas de una celda del tablelayoutpanel?

Saludos y gracias de nuevo por tu ayuda, Oscar

"Jesús López" <sqlranger.mv...@mvps.org.nospam> escribió en el

mensaje news:O4lm8Wf$IHA...@TK2MSFTNGP06.phx.gbl...

Jesús López

unread,
Aug 14, 2008, 6:42:47 AM8/14/08
to
No sé que te estará fallando. Yo acabo de crear un formulario con un tableLayout y con un label y se ajusta perfectamente.
 
Este es el código que tengo en InitializeComponents del formulario:
 
 
    Private Sub InitializeComponent()
        Me.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel
        Me.Label1 = New System.Windows.Forms.Label
        Me.TableLayoutPanel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'TableLayoutPanel1
        '
        Me.TableLayoutPanel1.ColumnCount = 2
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
        Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
        Me.TableLayoutPanel1.Controls.Add(Me.Label1, 0, 0)
        Me.TableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.TableLayoutPanel1.Location = New System.Drawing.Point(0, 0)
        Me.TableLayoutPanel1.Name = "TableLayoutPanel1"
        Me.TableLayoutPanel1.RowCount = 2
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
        Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
        Me.TableLayoutPanel1.Size = New System.Drawing.Size(292, 266)
        Me.TableLayoutPanel1.TabIndex = 0
        '
        'Label1
        '
        Me.Label1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Label1.Location = New System.Drawing.Point(3, 0)
        Me.Label1.Name = "Label1"
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Label1"
        '
        'Form2
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.TableLayoutPanel1)
        Me.Name = "Form2"
        Me.Text = "Form2"
        Me.TableLayoutPanel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub
 
 
 

Oscar

unread,
Aug 14, 2008, 7:04:10 AM8/14/08
to
Hola de nuevo, te adjunto imagen de como se me ve a mi
 
 
y te adjunto también el código que utilizo, a ver si vieras algo extraño. muchas gracias de nuevo por tu tiempo.

Dim
fil, col, i, j As Integer
fil = 3 : col = 3
Tbl_Imagen.Controls.Clear()
Tbl_Imagen.RowCount = fil
While i < fil
    j = 0
    While j < col
        Tbl_Imagen.RowStyles.Add(
New RowStyle(SizeType.Percent, 100))
        Dim Tbx As New
Label
        Tbx.AutoSize =
False
        Tbx.BackColor = Color.Black
        Tbx.Anchor = AnchorStyles.Top + AnchorStyles.Left

        Tbl_Imagen.Controls.Add(Tbx, j, i)
        j = j + 1
    End While
    i = i + 1
End While
 
Saludos, Oscar

Ivan

unread,
Aug 14, 2008, 8:30:19 PM8/14/08
to
hola Oscar

> por lo que he visto el anchor es para colocar el control en una determinada
> posición, pero lo que yo quiero hacer es redimensionar el control label par
> que ocupe toda la celda

en realidad [creo que] la propiedad anchor, 'en general', es para que
un control 'mantenga' la distancia con los margenes ( epecificados en
dicha propiedad
) de su contenedor cuando este cambia de tamaño, por lo que si
estableces la propiedad para sus cuatro 'lados' (con 'Or' no con +
=>pej como te dice Jesus:

TuControl.Anchor = AnchorStyles.Top Or AnchorStyles.Bottom _
Or AnchorStyles.Left Or AnchorStyles.Right

este aumentara/disminuira de tamaño con su contenedor

>, para eso supongo que debo sacar el tamaño de cada
> celda y asignarse a las propiedades width y height del control label

en cuanto a conocer las medidas del contenedor, creo que en general si
suele ser necesario para ajustar las medidas iniciales del control a
las suyas,

pero [por lo que creo entender en la ayuda 'F1'] para el
TableLayoutPanel Anchor tiene un funcionamiento especial y al parecer
automaticamente ajusta el control agregado a los lados especificados,
con la salvedad de 'respetar' los margenes especificados en la
propiedad Margin del control y los de la propieda Padding del
TableLayoutPanel

bueno, todo esto lo acabo de leer en la ayuda (cursor sobre la palabra
TableLayoutPanel1 y dandole a F1) y por lo que he visto creo que Jesus
tiene razon

espero ayude

un saludo
Ivan

0 new messages