Malditos controles

16/07/2004 - 10:35 por Susana | Informe spam
Hola otra vez:
Estoy haciendo un control personalizado con varios botones
y un datagrid,uso una tabla para colocarlos en la pantalla.
El código para generar la tabla es el siguiente:
public class Grid1 :
System.Web.UI.WebControls.WebControl,INamingContainer
{
// Sobreescribo método Render
protected override void Render(HtmlTextWriter output)
{
output.Write("<table style=\"WIDTH: " + ancho.ToString()
+ "px;HEIGHT: " + alto.ToString() + ";TOP: " +
top.ToString() + ";LEFT: " + left.ToString()
+";POSITION:absolute \">");
output.Write("<tr valing=top");
output.WriteFullBeginTag("td");
...
Cuando se pega el control en tiempo de diseño se genera el
siguiente código HTML:
<controlgon:Grid1 id="Grid11" style="Z-INDEX: 102; LEFT:
356px; POSITION: absolute; TOP: 180px" runat="server"
Height="260px" Width="472px"></controlgon:gonGrid1>
¿Me podría explicar alguien como se pueden coger las
propiedades Width,Height,Top,Left que se generan al
arrastrar el ratón para pegar el control y pasarlas a las
propiedades ancho,alto,Top,Left del propio control que uso
para dimensionar y colocar la tabla que engloba todos
controles hijos?
¿O en su defecto como se dimensiona y coloca un control
personalizado (no es un ascx)?
Muchas gracias.
 

Leer las respuestas

#1 wbert
16/07/2004 - 14:44 | Informe spam
Hola

No soy muy bueno para hacer un control a mano, pero si me
ha tocado, Mira te mando esto del libro del que he
estudiado, espero te de ideas.

********************************

Handling Control Resizing

Composite controls handle a lot of design-time and run-
time display features automatically through their base
class' s Render method. However, they cannot automatically
resize their child controls because there is no reasonable
way to tell what type of resizing behavior is appropriate.

To handle resizing composite controls, follow these steps:

1. Override the base class' s Render method.

2. Add code to resize the child controls as appropriate.

3. Call the base class' s Render method to display the
control.


**************************
Visual Basic .NET
Protected Overrides Sub Render(ByVal writer As _
System.Web.UI.HtmlTextWriter)
EnsureChildcontrols()
' Resize text box to match control width.
txtMath.Width = Me.Width
' Resize text box to match control height.
txtMath.Height = Unit.Parse(Me.Height.Value -_
butSum.Height.Value)
' Render the control.
MyBase.Render(writer)
End Sub
******************************
Visual C#
protected override void Render(HtmlTextWriter output)
{
EnsureChildControls();
// Resize text box to match control width.
txtMath.Width = this.Width;
// Resize text box to match control height.
double dHeight = this.Height.Value -
butSum.Height.Value;
txtMath.Height = Unit.Parse(dHeight.ToString());
// Render the control.
base.Render(output);
}


Wbert

Preguntas similares