|
-
May 19th, 2013, 12:31 AM
#1
Thread Starter
Lively Member
[RESOLVED] formLocation
I've been using a set of code to make a form appear directly underneath a button. I know I'm either using the wrong one, or one that would be easier for what I'm trying to do. I currently have two sets of code. One for when the window is in default normal size, and the other for when it is maximized. This is the code as follows:
Code:
Dim formLocation = PointToScreen(TwitterButton.Location)
formLocation.Offset(798, 30)
TwitterPopupMenu.StartPosition = FormStartPosition.Manual
TwitterPopupMenu.Location = formLocation
TwitterPopupMenu.Show()
If Me.WindowState = FormWindowState.Maximized Then
formLocation.Offset(570, 2)
TwitterPopupMenu.StartPosition = FormStartPosition.Manual
TwitterPopupMenu.Location = formLocation
TwitterPopupMenu.Show()
The issue I currently have is that when the user manually adjusts the form size, neither of the codes are relevant any longer, and the popup forms will no longer appear in their appropriate locations. I'm quite positive that the codes I have here are not the correct ones, and that the one that I'm looking for can actually set the forms to launch in their places in this case, a button (which is what these are supposed to be doing, though quite honestly, I think there's just simply something botched up with these codes, and their just sneakily hiding under my nose). This is probably a duh thing (it's been one of those days )
-
May 19th, 2013, 01:57 AM
#2
Fanatic Member
Re: formLocation
Hi,
you should be using something like scaling / percentages
example using Top
if the button should be 2/3 way down the form then
buttontop = (form.height * 0.66) with this it doesnt matter how big the form is it will always stay in its perspective place, but you should apply limits to form size(keep it big enough to show all controls clearly)
menutop = (button.top + button.height) it doesnt matter were the button it this will always put the menu under it
try something like that
Yes!!!
Working from home is so much better than working in an office...
Nothing can beat the combined stress of getting your work done on time whilst
1. one toddler keeps pressing your AVR's power button
2. one baby keeps crying for milk
3. one child keeps running in and out of the house screaming and shouting
4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
5. working at 1 O'clock in the morning because nobody is awake at that time
6. being grossly underpaid for all your hard work

-
May 19th, 2013, 12:20 PM
#3
Re: formLocation
You're really never going to pin this down with absolute accuracy. Point conversion (to screen, to client) is simply not reliable enough especially when working with both client and screen co-ordinates as you are here. If you want a customised button with menu you'd be far better off creating a user control so that you have absolute ... er .. control over the placement of the control and its dropdowns/flyouts/popups and other assorted attachments.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
May 19th, 2013, 03:30 PM
#4
Thread Starter
Lively Member
Re: formLocation
The peculiar thing about it is that actually have a form set to launch directly underneath a button, and it works no matter how much the main form size changes, but yet the same sets of code being used for other forms will not. I've checked several times for differences in the two codes, and there is none at all.
Code:
Dim formLocation = PointToScreen(QuickLaunchButton.Location)
formLocation.Offset(-135, QuickLaunchButton.Height)
DynamicQuickLaunch.StartPosition = FormStartPosition.Manual
DynamicQuickLaunch.Location = formLocation
DynamicQuickLaunch.Show()
Note the code previously posted. The only exception is that the button height replaces the offset number in the previously posted code. But I don't believe that has any bearing of what's happening here due to the fact I'm not having the problem with that particular offset. I wish there was a way to replace the whole line of code that indicates the offset with something that simply indicates the location of the button opposed to the preset manual offset. Or better yet that the point to screen continues to update itself during runtime. I'm just curious why the same set of code behaves differently in almost the same exact environment. Besides that, the height offset differences would have nothing to do with it, because it behaves the exact same way before that offset was ever even changed. I don't know. Strange.
-
May 19th, 2013, 08:19 PM
#5
Re: formLocation
This code will display the form such that it's top-left corner is directly below the bottom-left corner of the Button:
Code:
Dim formLocation = QuickLaunchButton.PointToScreen(New Point(0, QuickLaunchButton.Height))
DynamicQuickLaunch.StartPosition = FormStartPosition.Manual
DynamicQuickLaunch.Location = formLocation
DynamicQuickLaunch.Show()
Note the use of the Button's PointToScreen method, so you simply specify offsets from zero in both directions to determine the location of the form.
-
May 20th, 2013, 08:54 PM
#6
Re: formLocation
 Originally Posted by dunfiddlin
Point conversion (to screen, to client) is simply not reliable enough especially when working with both client and screen co-ordinates as you are here...
Actually, you're wrong. The conversions are very accurate. I developed an alert system that uses layered windows to highlight controls and I use such conversions to keep the alerts aligned to the controls and they work perfectly. If I told someone that the alerts themselves were not forms but controls, they'd have no reason to doubt it unless they saw the source code. That is how well they work.
-
May 20th, 2013, 10:42 PM
#7
Thread Starter
Lively Member
Re: formLocation
Thank you very much jmcilhinney, that worked perfectly. Thank you everyone else for your help as well .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|