Export (0) Print
Expand All

Visual Basic: Windows Controls

AutoSize Property (Panel Object) Example

This example adds two Panel objects to a StatusBar control and sets the AutoSize property to Content for all panels. As the cursor is moved over the objects on the form, the x and y coordinates are displayed as well as the Tag property value for each control. To try the example, place a StatusBar, a PictureBox, and a CommandButton on a form, then paste the code into the Declarations section. Run the example and move the cursor over the various controls.

Private Sub Form_Load()
   Dim pnlX As Panel
   ' Set long tags for each object.
   Form1.Tag = "Project 1 Form"
   Command1.Tag = "A command button"
   Picture1.Tag = "Picture Box Caption"   
   StatusBar1.Tag = "Application StatusBar1"
   ' Set the AutoSize style of the first panel to Contents.
   StatusBar1.Panels(1).AutoSize = sbrContents
   ' Add 2 more panels, and set them to Contents.
   Set pnlX = StatusBar1.Panels.Add
   pnlX.AutoSize = sbrContents
   Set pnlX = StatusBar1.Panels.Add
   pnlX.AutoSize = sbrContents
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
   ' Display the control's tag in panel 1, and x and y
   ' coordinates in panels 2 and 3. Because AutoSize = Contents,
   ' the first panel stretches to accommodate the varying text.
   StatusBar1.Panels(1).Text = Form1.Tag
   StatusBar1.Panels(2).Text = "X = " & x
   StatusBar1.Panels(3).Text = "Y = " & y
End Sub

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
   StatusBar1.Panels(1).Text = Command1.Tag
   StatusBar1.Panels(2).Text = "X = " & x
   StatusBar1.Panels(3).Text = "Y = " & y
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
   StatusBar1.Panels(1).Text = Picture1.Tag
   StatusBar1.Panels(2).Text = "X = " & x
   StatusBar1.Panels(3).Text = "Y = " & y
End Sub

Private Sub StatusBar1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
   StatusBar1.Panels(1).Text = StatusBar1.Tag
   StatusBar1.Panels(2).Text = "X = " & x
   StatusBar1.Panels(3).Text = "Y = " & y
End Sub
Show:
© 2015 Microsoft