在文本框下方显示一个表格
问题描述:
您好,我正在为使用Visual Basic 2005的论文工作,我希望显示在文本框下方,但我可以使用绘图点获取文本框的准确位置。在文本框下方显示一个表格
这里是我的代码现在:
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()
答
的窗体上控件的位置是相对于表格的左上角,这样你就不需要使用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
注意:一个文本框只能放置形式表面上不在“半空中”。
答
刚刚在网上发现它,并正在按照我想要的方式工作。
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
我想它真正伟大的作品的代码,但我的问题是,文本框是另一种形式则是另一种形式,即会显示当在文本框中的事件发生时,这是GOT_FOCUS该表单将显示框的下面...我用位置指向窗体的位置,但它不能找到文本框我也设置窗体启动位置手动仍然不会工作..任何想法? – naviciroel 2012-07-29 17:19:02