Ver Mensaje Individual
  #4 (permalink)  
Antiguo 16/05/2012, 19:50
doword
 
Fecha de Ingreso: febrero-2011
Mensajes: 99
Antigüedad: 14 años
Puntos: 10
Respuesta: Obtener ancho de botón con AutoSize

Gracias Aquaventus!

La verdad me siento un poco tonto, hehe…

Comparando códigos (trabajaba en VB, pero el C se parece) me di cuenta que lo que pasa es lo siguiente…

Si tu pides el ancho del botón antes de “invocarlo” te dará 100 o 75, pero si lo pides una vez ya invocado te da el ancho verdadero…

Ejemplo:

Código vb:
Ver original
  1. Dim texto As New Label
  2.         Dim boton As New Button
  3.  
  4.         boton.AutoSize = True
  5.         boton.Location = New Point(30, 30)
  6.         boton.Text = "reu9tfdu34sfd 384fs 38940fsy 32984e 23849fsd jhd289 fdh2s39"
  7.  
  8.  
  9.         texto.Text = boton.Width
  10.         texto.Location = New Point(70, 70)
  11.  
  12.         Me.Controls.Add(boton)
  13.         Me.Controls.Add(texto)

El texto te sale "75"

Pero si lo invoco antes de "texto.Text = boton.Width"

Código vb:
Ver original
  1. Dim texto As New Label
  2.         Dim boton As New Button
  3.  
  4.         boton.AutoSize = True
  5.         boton.Location = New Point(30, 30)
  6.         boton.Text = "reu9tfdu34sfd 384fs 38940fsy 32984e 23849fsd jhd289 fdh2s39"
  7.         Me.Controls.Add(boton) ' se invoca el boton!
  8.        
  9.         texto.Text = boton.Width
  10.         texto.Location = New Point(70, 70)
  11.  
  12.         Me.Controls.Add(texto)

Me sale "319".

Muchas gracias!