[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2006-11-10
5
Medium Priority
?
289 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 1000 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 1000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

650 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