Solved

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

Posted on 2006-11-10
5
271 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
Comment Utility
Worst case is taht you take groupBox.top + textBox.top and groupBox.left + textBox.left to get the locations.
0
 

Author Comment

by:TSFLLC
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

8 Experts available now in Live!

Get 1:1 Help Now