Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
How do i get the correct position of TextBox when placed in Group box.

I need to get the left and bottom value of text box to position datagrid below text box.

With below code i get the correct position when TextBox is not placed in Groupbox (that is Textbox is placed on form not inside any container.).But when i put the text box in Groupbox i dont get correct left and bottom of textbox.

How do i get the correct position when Textbox placed in Groupbox container.


Private Sub TbxSupCode_Enter(sender As Object, e As EventArgs) Handles TbxSupCode.Enter

        Dim TbxRectangle As Rectangle = TbxSupCode.DisplayRectangle()
        TbxRectangle.X += TbxSupCode.Left
        TbxRectangle.Y += TbxSupCode.Top + TbxSupCode.Height

        DgvSupCodeList.Location = New Point(TbxRectangle.X, TbxRectangle.Y)


    End Sub


What I have tried:

Private Sub TbxSupCode_Enter(sender As Object, e As EventArgs) Handles TbxSupCode.Enter

        Dim TbxRectangle As Rectangle = TbxSupCode.DisplayRectangle()
        TbxRectangle.X += TbxSupCode.Left
        TbxRectangle.Y += TbxSupCode.Top + TbxSupCode.Height

        DgvSupCodeList.Location = New Point(TbxRectangle.X, TbxRectangle.Y)


    End Sub
Posted
Updated 16-Apr-20 19:22pm

1 solution

Which "correct" Location do you want to have ?
If your Textbox is member of a Groupbox your Location-value corresponds to the Groupbox.
I suppose you want to have the Screen-Location of your Textbox. In this case you have to ask the Parent of your Textbox (in your case the Groupbox) for it's Location and add it's x- and y-Value to the Values of your Textbox.
But (if this question is allowed) - for what do you need this ...?
 
Share this answer
 
Comments
pravin9455 17-Apr-20 4:25am    
I want to place the datagridview exactly below textbox (left of datagrid should be left of text box and top of datagrid should be bottom of textbox.
In my above code when the texbox is in groupbox i dont get the placement correctly. it goes off the way (Groupbox2)


Private Sub TbxSupCode_Enter(sender As Object, e As EventArgs) Handles TbxSupCode.Enter

Dim TbxRectangle As Rectangle = TbxSupCode.DisplayRectangle()
TbxRectangle.X += TbxSupCode.Left
TbxRectangle.Y += TbxSupCode.Top + TbxSupCode.Height

DgvSupCodeList.Location = New Point(TbxRectangle.X, TbxRectangle.Y)


End Sub
Ralf Meier 17-Apr-20 4:40am    
So there are some new questions :
- what is the sense of the Groupbox ? Why don't you have the Textbox directly on the Form ?
- Does the GroupBox directly end behind the TextBox ?
- or ... do you want to place the DataGridView over the GroupBox (when under the TextBox) ?
- or ... should the DGV also become a Member of the GroupBox ?
pravin9455 17-Apr-20 6:47am    
"it goes off the way (Groupbox2)"

Sorry : groupbox doe not go off the way .its datagridview comes above textbox

i want to place the DataGridView over the GroupBox (when under the TextBox) ?

datagridview becomes visible when enter taxtbox and invisible when leave textbox.
Ralf Meier 17-Apr-20 7:19am    
I can't follow you (in the moment) ...
Please explain : what should happen with which action ?
And : why do you have the Textbox inside a GroupBox ?
pravin9455 17-Apr-20 11:48am    
i have a textbox (TbxSupCode) to enter supplier code and Datagridview (DgvSupCodeList) to show list of supplier code to select. Initially datagridview remains invisible. when entered in textbox i am positioning this datagrid below textbox starting from left of textbox and top of datagrid from bottom of texbox and make it visible (it will be invisible on leaving textbox) .For this i need to get the left and bottom of textbox for placing location of datagrid.

Along with other controls i have place this text box in Group box (GroupBox2) .I have below code to get the location point for datagrid.


Private Sub TbxSupCode_Enter(sender As Object, e As EventArgs) Handles TbxSupCode.Enter

Dim TbxRectangle As Rectangle = TbxSupCode.DisplayRectangle()
TbxRectangle.X += TbxSupCode.Left
TbxRectangle.Y += TbxSupCode.Top + TbxSupCode.Height

DgvSupCodeList.Location = New Point(TbxRectangle.X, TbxRectangle.Y)


End Sub

Problem is if i place this text box on form without inside any container i get the position of datagrid perfectly. but if i put this text box inside container ( like groupbox) it comes above textbox . i need to get this Datagrid below text box when in container.

I need to place in group box for better display as there are many controls on form. i will provide more details if required.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900