Solved

How to identify text box position on the FORM and text box position in GROUP BOX

Posted on 2006-11-10
5
273 Views
Last Modified: 2010-04-23
VB 2005
I have a text box that is in a group box.  I need to identify the left, right coordinates based on it's location in the form and not the location of it in the group box because I am displaying a list box under the text box as part of an auto complete function.

Can I do this?

Sincerely,
Phil
0
Comment
Question by:TSFLLC
  • 3
5 Comments
 
LVL 24

Assisted Solution

by:Jeff Certain
Jeff Certain earned 250 total points
ID: 17919401
Worst case is taht you take groupBox.top + textBox.top and groupBox.left + textBox.left to get the locations.
0
 

Author Comment

by:TSFLLC
ID: 17919501
Jeff,

I just did that, tested it and decided to get back on EE and see if I'd gotten any bites with any other ideas.

This issue has come about simply for the fact that Microsoft removed line/box draw capability.  To me it was a bad joke to remove.  In 90 out of 100 instances I have no use for a group box.  I simply use it to separate groups of fields for visual and not programmatic purposes.  I wish they would bring that capability back.

Having never needed to do this, would I use textbox1.container and some additional info to identify the container name & type (is it a group box?) to determine whether I need to add left/top to my listbox position inside my autocomplete function.  I'm already receiving the textbox (ByVal Sender as TextBox) into my function.

Thanks for the info!
0
 

Author Comment

by:TSFLLC
ID: 17919532
I'm apparently on the wrong track, msgbox (txtbox.container) comes up blank.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 17919606
Here is an approach that will work regardless of how deeply nested the TextBox is.  We directly get the TextBoxes SCREEN coordinates using the GetWindowRect() API.  Then we convert that screen rectangle to the Forms CLIENT coordinates using the RectangleToClient() function.  This approach completely bypasses the TextBoxes container(s)...

Public Class Form1

    Public Structure RECT
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer
    End Structure

    Private Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" _
        (ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim screenRect As RECT
        Call GetWindowRect(TextBox1.Handle, screenRect)

        Dim formRect As Rectangle = Me.RectangleToClient(New Rectangle(screenRect.Left, screenRect.Top, screenRect.Right - screenRect.Left, screenRect.Bottom - screenRect.Top))

        Dim lb As New ListBox
        lb.Items.Add("Hello World!")
        lb.Width = formRect.Width
        lb.Left = formRect.Left
        lb.Top = formRect.Top + formRect.Height - 1
        Me.Controls.Add(lb)
        lb.BringToFront()
    End Sub

End Class


0
 

Author Comment

by:TSFLLC
ID: 17919669
Thanks guys for both posts.  They are about  valid options.  I'll split the points equally.

I'll test both to see which requires the least changes in my existing forms.

Thanks!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question