JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Moving Controls

There are several ways to move controls in Windows forms, but things are more restricted with Web server controls, which don't have Top and Left properties to position controls. Instead, Web server controls are positioned using CSS styles.

In particular, you can use the Style("LEFT") and Style("TOP") properties to move a control.

You can see how this works in the Controls example on the CD-ROM; when you click the "Move text box" button, the code moves the text box this way, where I'm setting the left edge's position of the text box to 300 pixels:

    Private Sub Button4_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button4.Click
        TextBox1.Style("Left") = "300px"
    End Sub

You can see the result in Figure 15.5, where the text box has been moved to the right. Note that you must be using grid layout for this to work, which means that the Position style attribute has been set to "absolute". In this way, you can move the controls around in your Web forms, but keep in mind that it takes a round trip to the server to do it this way. (You can set the style of HTML controls in browser script like JavaScript, but not Web server controls.) For another example of moving controls, see "Adding Controls at Run Time" in this chapter.

Click To expand
Figure 15.5: Moving a text box.
Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor