0

您好,我正在使用 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()
4

2 回答 2

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
于 2012-07-29T21:18:18.703 回答
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

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

于 2012-07-29T08:34:31.120 回答