whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

100 Visitors Online


 
...limit a forms movement to the workarea?
Autor: P. Below
[ Print tip ]  

Tip Rating (7):  
     


// For some reason messages.pas declares no message record for this message

type
  
TWmMoving = record
    
Msg: Cardinal;
    fwSide: Cardinal;
    lpRect: PRect;
    Result: Integer;
  end;

// Add a handler to your forms private section:

procedure WMMoving(var msg: TWMMoving); message WM_MOVING;

// Implement it as

  
procedure TFormX.WMMoving(var msg: TWMMoving);
  var
    
r: TRect;
  begin
    
r := Screen.WorkareaRect;
   // compare the new form bounds in msg.lpRect^ with r and modify it if
   // necessary
    
if msg.lprect^.left < r.left then
      
OffsetRect(msg.lprect^, r.left - msg.lprect^.left, 0);
    if msg.lprect^.top < r.top then
      
OffsetRect(msg.lprect^, 0, r.top - msg.lprect^.top);
    if msg.lprect^.right > r.right then
      
OffsetRect(msg.lprect^, r.right - msg.lprect^.right, 0);
    if msg.lprect^.bottom > r.bottom then
      
OffsetRect(msg.lprect^, 0, r.bottom - msg.lprect^.bottom);
    inherited;
  end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners