473,548 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding coordinates of an item in a panel on form

Say I put an item into a panel and place it onto a form, and I want to know
where on the form the item is in X,Y positions... but If I check the
location property of the item in the panel, that is relative to the X,Y
cordinates (0,0) of the panel, not of the form. How would I know where the
item is on the entire form even though it is in a panel?

Like if the panel is 10 from left and 10 from top of the form, and I place a
textbox in the panel at 10 from its left and 10 from its top, the textbox's
location is listed as (10,10) even though it is (20,20) relative to the
form.

How would I get that 20,20 location instead of the one relative to its
parent container? thanks!
Nov 21 '05 #1
5 6712
The values of the locations would be (assuming panel1 is the name of
your panel, item1 is the name of the object, and form1 is the name of
the form):

x = item1.location. x + panel1.location .x
y = item1.location. y + panel1.location .y

In VB.Net 05, there are some nifty functions that do this, but I haven't
looked into them yet.

Brian Henry wrote:
Say I put an item into a panel and place it onto a form, and I want to know
where on the form the item is in X,Y positions... but If I check the
location property of the item in the panel, that is relative to the X,Y
cordinates (0,0) of the panel, not of the form. How would I know where the
item is on the entire form even though it is in a panel?

Like if the panel is 10 from left and 10 from top of the form, and I place a
textbox in the panel at 10 from its left and 10 from its top, the textbox's
location is listed as (10,10) even though it is (20,20) relative to the
form.

How would I get that 20,20 location instead of the one relative to its
parent container? thanks!

Nov 21 '05 #2
well yes, I already knew you could add them together... but it gets complex
if you have panels in panels in panels... this is being used in a custom
control, so it would be hard to know what it's exactly in.. so a function or
routine that could figure it out automatically would be nice

"Matt" <ba*******@hotm ail.com> wrote in message
news:eXMDe.1302 3$N91.4871@trnd dc08...
The values of the locations would be (assuming panel1 is the name of your
panel, item1 is the name of the object, and form1 is the name of the
form):

x = item1.location. x + panel1.location .x
y = item1.location. y + panel1.location .y

In VB.Net 05, there are some nifty functions that do this, but I haven't
looked into them yet.

Brian Henry wrote:
Say I put an item into a panel and place it onto a form, and I want to
know where on the form the item is in X,Y positions... but If I check the
location property of the item in the panel, that is relative to the X,Y
cordinates (0,0) of the panel, not of the form. How would I know where the
item is on the entire form even though it is in a panel?

Like if the panel is 10 from left and 10 from top of the form, and I place
a textbox in the panel at 10 from its left and 10 from its top, the
textbox's location is listed as (10,10) even though it is (20,20) relative
to the form.

How would I get that 20,20 location instead of the one relative to its
parent container? thanks!

Nov 21 '05 #3

You are after the PointToControl and PointToScreen methods of Control,
I think.

Brian Henry wrote:
well yes, I already knew you could add them together... but it gets complex
if you have panels in panels in panels... this is being used in a custom
control, so it would be hard to know what it's exactly in.. so a function or
routine that could figure it out automatically would be nice

"Matt" <ba*******@hotm ail.com> wrote in message
news:eXMDe.1302 3$N91.4871@trnd dc08...
The values of the locations would be (assuming panel1 is the name of your
panel, item1 is the name of the object, and form1 is the name of the
form):

x = item1.location. x + panel1.location .x
y = item1.location. y + panel1.location .y

In VB.Net 05, there are some nifty functions that do this, but I haven't
looked into them yet.

Brian Henry wrote:
Say I put an item into a panel and place it onto a form, and I want to
know where on the form the item is in X,Y positions... but If I check the
location property of the item in the panel, that is relative to the X,Y
cordinates (0,0) of the panel, not of the form. How would I know where the
item is on the entire form even though it is in a panel?

Like if the panel is 10 from left and 10 from top of the form, and I place
a textbox in the panel at 10 from its left and 10 from its top, the
textbox's location is listed as (10,10) even though it is (20,20) relative
to the form.

How would I get that 20,20 location instead of the one relative to its
parent container? thanks!


Nov 21 '05 #4
"Brian Henry" <no****@nospam. microsoft.com> wrote in message news:OR******** ******@TK2MSFTN GP14.phx.gbl...
well yes, I already knew you could add them together... but it gets complex
if you have panels in panels in panels... this is being used in a custom
control, so it would be hard to know what it's exactly in.. so a function or
routine that could figure it out automatically would be nice

"Matt" <ba*******@hotm ail.com> wrote in message
news:eXMDe.1302 3$N91.4871@trnd dc08...
The values of the locations would be (assuming panel1 is the name of your
panel, item1 is the name of the object, and form1 is the name of the
form):

x = item1.location. x + panel1.location .x
y = item1.location. y + panel1.location .y

In VB.Net 05, there are some nifty functions that do this, but I haven't
looked into them yet.

Brian Henry wrote:
Say I put an item into a panel and place it onto a form, and I want to
know where on the form the item is in X,Y positions... but If I check the
location property of the item in the panel, that is relative to the X,Y
cordinates (0,0) of the panel, not of the form. How would I know where the
item is on the entire form even though it is in a panel?

Like if the panel is 10 from left and 10 from top of the form, and I place
a textbox in the panel at 10 from its left and 10 from its top, the
textbox's location is listed as (10,10) even though it is (20,20) relative
to the form.

How would I get that 20,20 location instead of the one relative to its
parent container? thanks!



Would something like this work?

///
Public Function PointOnForm(ByV al ctl As Control) As Point
Dim o As Object
Dim p as New Point

o = ctl
Do While Not TypeOf o Is Form
p.X += o.location.x
p.Y += o.location.y
o = o.Parent
Loop

Return p

End Function
\\\

It will need some modifications if you use "Option Strict = On", however.

--
Al Reid
Nov 21 '05 #5
yeah, I was already doing it like this

Private Function FindTopLocation (ByVal item As Control) As Integer

Dim i_top As Integer = 0

i_top = item.Top

If Not TypeOf item Is Form Then

i_top += FindTopLocation (item.Parent)

End If

Return i_top

End Function

Private Function FindLeftLocatio n(ByVal item As Control) As Integer

Dim i_left As Integer = 0

i_left = item.Left

If Not TypeOf item Is Form Then

i_left += FindLeftLocatio n(item.Parent)

End If

Return i_left

End Function

was just hoping there is a function that did it automatically.

"Al Reid" <ar*****@reidDA SHhome.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
"Brian Henry" <no****@nospam. microsoft.com> wrote in message
news:OR******** ******@TK2MSFTN GP14.phx.gbl...
well yes, I already knew you could add them together... but it gets
complex
if you have panels in panels in panels... this is being used in a custom
control, so it would be hard to know what it's exactly in.. so a function
or
routine that could figure it out automatically would be nice

"Matt" <ba*******@hotm ail.com> wrote in message
news:eXMDe.1302 3$N91.4871@trnd dc08...
> The values of the locations would be (assuming panel1 is the name of
> your
> panel, item1 is the name of the object, and form1 is the name of the
> form):
>
> x = item1.location. x + panel1.location .x
> y = item1.location. y + panel1.location .y
>
> In VB.Net 05, there are some nifty functions that do this, but I
> haven't
> looked into them yet.
>
>
>
> Brian Henry wrote:
>
>>Say I put an item into a panel and place it onto a form, and I want to
>>know where on the form the item is in X,Y positions... but If I check
>>the
>>location property of the item in the panel, that is relative to the X,Y
>>cordinates (0,0) of the panel, not of the form. How would I know where
>>the
>>item is on the entire form even though it is in a panel?
>>
>>Like if the panel is 10 from left and 10 from top of the form, and I
>>place
>>a textbox in the panel at 10 from its left and 10 from its top, the
>>textbox's location is listed as (10,10) even though it is (20,20)
>>relative
>>to the form.
>>
>>How would I get that 20,20 location instead of the one relative to its
>>parent container? thanks!
>>
>>



Would something like this work?

///
Public Function PointOnForm(ByV al ctl As Control) As Point
Dim o As Object
Dim p as New Point

o = ctl
Do While Not TypeOf o Is Form
p.X += o.location.x
p.Y += o.location.y
o = o.Parent
Loop

Return p

End Function
\\\

It will need some modifications if you use "Option Strict = On", however.

--
Al Reid

Nov 21 '05 #6

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

Similar topics

1
474
by: TB | last post by:
Howdy... I have an asp.net web form with an ImageButton control on the form. When clicked, the ImageButton's click event handler is supposed to pass X and Y coordinates of the mouse click's location on the PAGE. I know that I can see the X, Y coords for the click event relative to the ImageButton control, but this does no good for my...
1
4418
by: Asaf Dan | last post by:
Hi, I'm using a panel to show an image. The Image could be bigger or smaller than the panel. I want to show the pixel coordinates of the image on a label next to the panel. I'm using an event but i cant get to show the real image pixel's coordinates. I would appreciate any kind of help.
2
21421
by: Robin Senior | last post by:
Hi, I'm trying to drag and drop onto a Panel on my form. The panel is inside a groupBox, which of course is inside my form. When dropping the item onto my Panel, I want it to appear at that point on the Panel, and therefore need the mouse coordinates relative to the Panel and not the form itself. Something like: private void...
0
950
by: Keerati Inochanon via .NET 247 | last post by:
Hi, I was wondering whether it is possible to find out the name of a panel given a screen coordinate (x,y). Given a set of screen coordinates (x,y) I would like to be able to tell where that point is (ie. what panel). Thank you very much in advance. -------------------------------- From: Keerati Inochanon
2
4563
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
1
2015
by: Dino M. Buljubasic | last post by:
I am trying to get coordinates of mouse_down/mouse_up event BUT relevant to the form or the parent of a control, not to the control where mouse click has occured. That means, even if I click a control on the form, I want to get the coordinates of the form of the click event, not coordinates of the control that was clicked on. My user...
2
1484
by: Rob | last post by:
Hi, I have a form which has a panel which has a picturebox inside of that. When a user clicks on the picture, it zooms by x2. The panel has autoscroll set to true, so when the image is larger then the panel, I can scroll to a different part of it. What I'm looking to do is when a user clicks on the image,the point at which he/she clicks is...
3
63322
by: Tom | last post by:
I have a picturebox on my VB.NET form. The picturebox size mode is set to stretched. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and display (in the status bar) the image coordinates of the mouse location. However, if I use the picturebox's MouseMove event, I am getting the...
0
3467
by: deko | last post by:
I'm trying to implement a custom TreeView that shows a ghost image while dragging. But the form I'm using is different from the sample code found here: http://www.codeproject.com/cs/miscctrl/TreeViewDragDrop.asp The problem is I can't get the proper coordinates required when dragging begins. I have two tree views in a panel with a...
0
7707
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. ...
0
7951
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...
1
7466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7803
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...
0
5082
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3475
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1926
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
1
1051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
751
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.