显示文本框下方的表单

时间:2012-07-28 17:27:31

标签: vb.net visual-studio-2005

您好我正在使用Visual Basic 2005为我的论文做些工作我希望for在文本框下方显示但我可以使用绘图点获得文本框的确切位置。

这是我现在的代码:

Dim x As Integer = Me.txtStockQUnit.Location.X + Me.Location.X + Me.grpMonitoring.Location.X
Dim y As Integer = Me.txtStockQUnit.Height + Me.txtStockQUnit.Location.Y + Me.Location.Y + Me.grpMonitoring.Location.Y
My.Forms.frmQuantityUnitDropListGrid.Location = New Point(x, y)
My.Forms.frmQuantityUnitDropListGrid.ShowDialog()

2 个答案:

答案 0 :(得分:0)

表单上控件的位置相对于表单的左上角,因此您无需使用Me.Location来定位文本框。

以下示例在Form_Load上设置文本框和表单的位置:

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    'position a textbox on the form relative to the top left corner of the form
    txtStockQUnit.Location = New Point(100, 25)

    'position the form relative the top left corner of the primary display
    Me.Location = New Point(100, 300)
End Sub

注意:文本框只能放在表单表面而不是“空中”。

答案 1 :(得分:0)

刚刚在网上找到了它并且正如我想要的那样工作。

Dim ctl as Textbox 'the textbox which the form will show at its bottom
Dim ctlpos As Point = ctl.PointToScreen(New Point(0, 0)) 'Point.Empty is not function so se Point(0, 0)

Me.StartPosition = FormStartPosition.Manual 'set it to manual
Me.Location = New Point(ctlpos.X - 2, ctlpos.Y + ctl.Height - 2) 'then locate its position
Me.show