Solved

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

Posted on 2006-11-10
5
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 86

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

729 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