2012-07-28 30 views
0

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

回答

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 

注意:一個文本框只能放置形式表面上不在「半空中」。

+0

我想它真正偉大的作品的代碼,但我的問題是,文本框是另一種形式則是另一種形式,即會顯示當在文本框中的事件發生時,這是GOT_FOCUS該表單將顯示框的下面...我用位置指向窗體的位置,但它不能找到文本框我也設置窗體啓動位置手動仍然不會工作..任何想法? – naviciroel 2012-07-29 17:19:02

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