Solved

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

Posted on 2006-11-10
5
272 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now