Leistiko
08-30-2000, 04:40 PM
I have a topmost window that I want to keep visible, so I don't want to allow users to move it partially off the screen. This would be sort of like the ad windows on some free internet services. How do I do this?
Preventing form from moving off-screenLeistiko 08-30-2000, 04:40 PM I have a topmost window that I want to keep visible, so I don't want to allow users to move it partially off the screen. This would be sort of like the ad windows on some free internet services. How do I do this? SeiferTim 08-30-2000, 05:37 PM While I'm not sure of the exact coding, I'm sure you can use a method to find the size of the screen, and if the top, left, top+height, or left+width go out of these boundaries, you can set which ever parameter is out of bound to the border... for instance... given that the top of the screen is 0, and your FormMain.Top=50, you should have in your From_Move() a method like: <code> If FormMain.Top < ScreenTop Then FormMain.Top = ScreenTop End If </code> And you can have an If-Then Statement for each possibility. -Seifer Tim Visit my Web-Site: http://solenoid.50megs.com BillSoo 08-30-2000, 05:43 PM Personally, I hate programs that think they know better than I do but if you insist... If you knew that the form moved, then you could compare it's location with the screen coordinates to decide whether it had moved offscreen. You could then move it back. You could tell if the form moved by detecting the WM_MOVE message. One way of doing this is subclassing the form. "I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder Sparkey 08-30-2000, 09:54 PM Will this window only be visible while the program is running, e.g. will there be a main form or something? If so, you could just set the form's (the one you don't want moved) enabled property to false then the user can click on it all they want and it will just sit there. They won't be able to close it though, so you would need a way of doing that, like if there is a main form you could put your disabled forms unload in the main form unload event. Just a thought. amram71 08-30-2000, 10:48 PM Put this in a timer control's code If me.left<0 then me.left=0 If me.left > screen.width-me.width then _ me.left=screen.width-me.width If me.top<0 then me.top=0 If me.top>screen.height-me.height then _ me.top=screen.height-me.height Leistiko 08-31-2000, 01:14 PM Thanks! I subclassed the form and intercepted its Move message and it seems to work. One minor detail, though, when you move the form off the screen, it seems to draw it first in the new location off the screen, and then move it to where it's supposed to be on screen, so there is some flickering. I thought that by not calling the old windows procedure if it was off the screen, this would fix that but it doesn't seem to. Any suggestions? If not I can live with what I have now. Kwalude 09-01-2000, 03:44 PM Why not just change the Moveable property of the Form to False? BillSoo 09-01-2000, 05:40 PM If you've subclassed the form, then you can intercept the move message before it moves the form. I can't remember if you can get the coordinates that the window is to move to. If you can, you could check the coordinates and decide not to pass on the move message if it would put you off the screen. "I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder |
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum