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

Home Posts Topics Members FAQ

Positioning form: Location() and PointToScreen() question

Thanks everyone for help in my previous post. Using the
"Point.op_Addit ion" from the previous post I have to now focus on the
real problem.

I need to manually position a new form so that its upper left hand
corner is positioned exactly in the middle of the button that was
pressed (Button1).

I can't seem to get the knack of Location() and PointToScreen() to
position the new form here. According to the help, location() is to do
with coordinates of the container and PointToScreen() for the screen
but I can't link them together properly.
Thank you again
Colin
Private Sub Button1_MouseDo wn(ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) _
Handles Button1.MouseDo wn
Dim b As Button = CType(sender, Button)
Dim f As New Form
f.StartPosition = FormStartPositi on.Manual
f.FormBorderSty le = FormBorderStyle .None
f.Location = Point.op_Additi on(b.PointToScr een(b.Location) , _
New Size(b.Width \ 2, b.Height \ 2))
f.Size = New Size(80, 80)
f.BackColor = Color.Yellow
f.Show()
End Sub
Nov 20 '05 #1
1 9405
Colin,
f.Location = Point.op_Additi on(b.PointToScr een(b.Location) , _
New Size(b.Width \ 2, b.Height \ 2))
b.Location is relative to the owning form, b.PointToScreen is attempting to
adjust the point relative to the button itself, not relative to the owing
form.

Try:
f.Location = Point.op_Additi on(Me.PointToSc reen(b.Location ), _
New Size(b.Width \ 2, b.Height \ 2))

Which will adjust the location of the button (relative to the form)
relative to the screen.

Hope this helps
Jay

"Colin McGuire" <co***********@ lycos.co.uk> wrote in message
news:ab******** *************** ***@posting.goo gle.com... Thanks everyone for help in my previous post. Using the
"Point.op_Addit ion" from the previous post I have to now focus on the
real problem.

I need to manually position a new form so that its upper left hand
corner is positioned exactly in the middle of the button that was
pressed (Button1).

I can't seem to get the knack of Location() and PointToScreen() to
position the new form here. According to the help, location() is to do
with coordinates of the container and PointToScreen() for the screen
but I can't link them together properly.
Thank you again
Colin
Private Sub Button1_MouseDo wn(ByVal sender As Object, _
ByVal e As System.Windows. Forms.MouseEven tArgs) _
Handles Button1.MouseDo wn
Dim b As Button = CType(sender, Button)
Dim f As New Form
f.StartPosition = FormStartPositi on.Manual
f.FormBorderSty le = FormBorderStyle .None
f.Location = Point.op_Additi on(b.PointToScr een(b.Location) , _
New Size(b.Width \ 2, b.Height \ 2))
f.Size = New Size(80, 80)
f.BackColor = Color.Yellow
f.Show()
End Sub

Nov 20 '05 #2

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

Similar topics

2
1356
by: web1110 | last post by:
I have an opening form that I want to size to 90% screen width and 90% screen width, I want to set the location of the top left corner to 5% values. Ths size comes out correctly, but on each successive open, the window move down and left. The positioning/sizing code is shown below. Any ideas on how to prevent the down and left creep? Rectangle stScreenDims=Screen.GetBounds(Bounds);
1
1480
by: steve bull | last post by:
I have a picture box which lies on a panel which lies on a form. Is there some way that I can calculate the position of the picture box relative to the form rather than the panel on which it lies? The location of the picture box in the Control class is given relative to the panel on which it lies. Thanks, Steve
18
2956
by: Colin McGuire | last post by:
Hi - this was posted last weekend and unfortunately not resolved. The solutions that were posted almost worked but after another 5 days of working on the code everynight, I am not further ahead. If you do have any ideas I would really like to hear them. Thanks Colin - 0 - 0 - 0 - I want a glorified popup/context menu on a button that shows only when
3
96949
by: Rich | last post by:
I am instnatiating a second form from a first form. I set startuplocation to manual, then I enter 100 for X and 300 for Y on the second form. Then on the click event of a button on form1 I have Dim frm = New form2, frm.Show. But form2 shows up way to the right of the screen. I also tried this in code frm.Location = New Point(100, 300) but same results. How do you control the position of a form in VB.Net? Thanks,
5
6740
by: Brian Henry | last post by:
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...
4
3333
by: gsb58 | last post by:
Hi! On a form I have a calendar. The form is rezised to 1024x768 (Don't worry - this is a training case) when loaded. Now I want to center the calendar on the form so that its edges are equally far from the upper, right, left and bottom borders of the form. I understand I must use the location property, am I right?
3
5390
by: steve | last post by:
Hi All I have textboxes within a TableLayoutpanel 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.
1
2219
by: final farewell | last post by:
Hello, I am using Ekhau Location Tracking System for an assignment. It is a system that is able to track configured tags attached to people or objects. I am new to the Ekahau Location Tracking System, but I have quite a good idea how it works. I have an assignment to develop a real application using the Ekahau Positioning Engine (The Engine is a software based real-time location system). The Location Tracking Model of the area to be...
1
3519
by: Dean Slindee | last post by:
I have a child form painted within a parent form. I would like to get the X,Y location of the child form on the desktop, but when I use the following statements, .Location returns 0,0. Dim ptChildForm As New Point ptChildForm = Me.Location
0
8407
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8837
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
8739
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...
1
8512
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
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
7347
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...
1
6175
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2739
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
1969
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.