473,657 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting screen coordinates for positioning a floating control next to a tableLayOutPane l embeded control

Hi All

I have textboxes within a TableLayoutpane l and I want to be able to position
an independant control adjacent to a selected textbox

This independent control allows selection of text to insert into the textbox

I am having trouble achieving this, see code below, the x position is too
far to the right and the y position is close to the bottom of the textbox
and I want it to be side by side.

I am obviously not understanding the coordinate system properly

Regards
Steve
Private Sub txtbox_Mousedow n(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs)

'common sub for any textbox clicked

Dim mypoint As New Point

Panel1.Visible = True

Panel1.BringToF ront()

mypoint.X = sender.pointtos creen(sender.lo cation).x + sender.width

mypoint.Y = sender.pointtos creen(sender.lo cation).y

Panel1.Location = mypoint

end sub
Jun 13 '06 #1
3 5389
Hi Steve,

Thank you for your post.

The coordinate system for a Windows Form is based on device coordinates,
and the basic unit of measure when drawing in Windows Forms is the device
unit (typically, the pixel). Points on the screen are described by x- and
y-coordinate pairs, with the x-coordinates increasing to the right and the
y-coordinates increasing from top to bottom. The location of the origin,
relative to the screen, will vary depending on whether you are specifying
screen or client coordinates.

A Windows Forms application specifies the position of points in a form or
control using client coordinates. The origin for client coordinates is the
upper-left corner of the client area of the control or form. Client
coordinates ensure that an application can use consistent coordinate values
while drawing in a form or control, regardless of the position of the form
or control on the screen.

In your code, since the Panel1 and the TextBox have different parent
container, the coordinates of them are not exchangable, we must convert
them to screen coordinates first before we can add or compare.

I've written following commented code to achieve the objective in your post:
Private Sub txtbox_Mousedow n(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs)

Panel1.Visible = True
Panel1.BringToF ront()

Dim txt As TextBox = CType(sender, TextBox) ' it's recommended to cast
the sender to TextBox first
Dim p as Point = txt.Parent.Poin tToScreen(txt.L ocation) ' since the
txt.Location is a client coordinate in its parent, we should call
txt.Parent.Poin tToScreen, not txt.PointToScre en
p.X = p.X + txt.Width
Panel1.Location = Panel1.Parent.P ointToClient(p) ' again, since the
Panel1.Location is a client coordinate in its parent, we should call
Panel1.Parent.P ointToClient() to convert a screen coordinate back to a
client coordinate

end sub
Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 13 '06 #2
Hi Walter

Thanks for the great reply

Worked a treat
Regards
Steve
"Walter Wang [MSFT]" <wa****@online. microsoft.com> wrote in message
news:0I******** *****@TK2MSFTNG XA01.phx.gbl...
Hi Steve,

Thank you for your post.

The coordinate system for a Windows Form is based on device coordinates,
and the basic unit of measure when drawing in Windows Forms is the device
unit (typically, the pixel). Points on the screen are described by x- and
y-coordinate pairs, with the x-coordinates increasing to the right and the
y-coordinates increasing from top to bottom. The location of the origin,
relative to the screen, will vary depending on whether you are specifying
screen or client coordinates.

A Windows Forms application specifies the position of points in a form or
control using client coordinates. The origin for client coordinates is the
upper-left corner of the client area of the control or form. Client
coordinates ensure that an application can use consistent coordinate
values
while drawing in a form or control, regardless of the position of the form
or control on the screen.

In your code, since the Panel1 and the TextBox have different parent
container, the coordinates of them are not exchangable, we must convert
them to screen coordinates first before we can add or compare.

I've written following commented code to achieve the objective in your
post:
Private Sub txtbox_Mousedow n(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs)

Panel1.Visible = True
Panel1.BringToF ront()

Dim txt As TextBox = CType(sender, TextBox) ' it's recommended to cast
the sender to TextBox first
Dim p as Point = txt.Parent.Poin tToScreen(txt.L ocation) ' since the
txt.Location is a client coordinate in its parent, we should call
txt.Parent.Poin tToScreen, not txt.PointToScre en
p.X = p.X + txt.Width
Panel1.Location = Panel1.Parent.P ointToClient(p) ' again, since the
Panel1.Location is a client coordinate in its parent, we should call
Panel1.Parent.P ointToClient() to convert a screen coordinate back to a
client coordinate

end sub
Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.

Jun 13 '06 #3
Hi Steve,

Appreciate your update and response. I am glad to hear that the problem has
been fixed. If you have any other questions or concerns, please do not
hesitate to contact us. It is always our pleasure to be of assistance.

Have a nice day!

Regards,
Walter Wang
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1892
by: Siegfried Heintze | last post by:
I want to implement drag and drop for tables, divs, spans. The problem is that I don't know how wide or long my tables, divs and spans are going to be in advance so I cannot use absolute coordinates. (It always seemed odd to me that there is no function called GetExtent that would return the bounding rectangle of an object -- this would solve my problem). There is a way, however, to fetch the coordinates of an object (such as a table, or...
2
4568
by: Dan Sikorsky | last post by:
How do you get the x,y pixel location of a textbox so that you can position the Web Date Control popup nearby the associated textbox that will contain the date selected by the Web Date Control? -- Thank you kindly, Dan Sikorsky BAB, BScE, MSC
2
2717
by: Steve Bottoms | last post by:
Hi, all! Using VB as code-behind in asp.net page... I have a TABLE control which I'm building dynamically. After the table is built, I'm trying to retrieve the HEIGHT property of that table (table.height.value) to be able to dynamically position the next elements on the form. However, this control property is coming back as -0- every time. I also try to get the table height with Javascript after-the-fact (table.style.height), but that...
3
5749
by: ZorpiedoMan | last post by:
Help... I need the screen coordinates of a control so I can place a pop up form underneath it. --Zorpy *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
7
2574
by: Peter Row | last post by:
Hi, I've started work on my own control some parts of which use standard controls, others I need to draw on my controls surface to get the display output I require, however.... I seem to be stupid or missing the point. I used DrawString( ) as a simple test but I cannot get it to work at all unless I handle my custom controls Paint event.
2
17561
by: steve | last post by:
Hi All I need to change the rowspan, columnspan properties of a control when they are within a TableLayoutPanel (VB.net 2005) At runtime the property is not available, but is at design time Any ideas Regards
35
4149
by: Friendly_Lola | last post by:
What Screen Resolution do You use? 800 X 600 1024 X 768 1280 X 1024 Wow! 1600 X 1200 (i can't imagine this) I use 1024 X 768. For what resolution you optimize your web pages?
6
2018
by: Samuel Rhodes | last post by:
Hi I am trying to write a code snippet that would display a '?' sign on the top left of a control. I do not want to hard code the positioning of the DIV which will contain that '?'. Is it possible to somehow know the top, left position of the content rendered by a User Control in a asp page. For eg, assume the figure below as a web page and A and B as user controls
0
8927
by: raylopez99 | last post by:
keywords: logical coordinates, page coordinates, world coordinates, device coordinates, physical coordinates, screen coordinates, client coordinates. offset rectangle. WYSIWYG rubber rectangle problem, bounded rectangle problem. PointToClient, PointToScreen Beware this newbie trap for the unwary. It goes by various names (in some old MFC literature I saw some of the keywords above). Whenever doing comparisons between points,...
0
8315
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8829
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8608
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2733
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.