Results 1 to 4 of 4

Thread: How to implement the dragging of graph in client area of window?

  1. #1
    Member Contributor
    Join Date
    Jun 2003
    Location
    Hamilton,On,Canada
    Posts
    55

    How to implement the dragging of graph in client area of window?

    Hi!

    I'm using Delphi 5.0

    I want to implement a form such that:
    When I press the mouse down on the client area and move the cursor, the position of graph in client area will move following the mouse. When mouse button up, graph will stay there. (Just image how we drag the pages in adobe pdf viewer).

    The cap problem I have now is don't know how to trace the movement of mouse cursor on client area.

    I know I can use OnMouseMove event to detect the movement of cursor. However, this event only detect the coordinate of cursor after movement(when event is triggered), but not before movement. So I don't know how to implement the offset of graph (the only idea I have now is to detect how much have been drag on mouse, then apply the offset to graph).

    I can use a state variable to record the last coordinate of cursor, but this may course error if the cursor leave client area from left(stop triggering), then enter client arent from right(start triggering).

    Can you give me some idea?

    Thank you!

  2. #2
    Member Contributor
    Join Date
    Mar 2003
    Location
    Suffolk, United Kingdom
    Posts
    99

    Re: How to implement the dragging of graph in client area of window?

    OnMouseDown (or OnLeftClick, whatever) - copy coordinates of point into a variable then SetCapture() (makes sure you get mouse messages even out of client window).

    OnMouseMove - use current coordiantes to work out relative movement from click point and move graph origin by same offset.

    OnMouseUp - ReleaseCapture().

  3. #3
    Senior Member Regular Contributor
    Join Date
    Sep 2002
    Location
    Poland
    Posts
    196

    Re: How to implement the dragging of graph in client area of window?

    Try to use functions like: GetCursporPos and SetCursorPos combined with mouse events. You only have to experiment a little.

  4. #4
    Member Contributor
    Join Date
    Jun 2003
    Location
    Hamilton,On,Canada
    Posts
    55

    Re: How to implement the dragging of graph in client area of window?

    Thank you!

    I tested these routines successfully as following:

    First add these global variables:
    Code :
    var
    headX,headY: Integer;
    tailX, tailY: Integer;
    oldX,oldY;
    Drag: boolean = False;
    OnMouseDown:
    Code :
     tailX := X;
     tailY := Y;
     oldX := X;
     oldY := Y;
     Drag := True;
    OnMouseMove:
    Code :
     if Drag then
      begin
      Graph.Left := oldX + (headX - tailX);
      Graph.Top  := oldX  + (headY - tailY);
      end;

    OnMouseUp:
    Code :
     Drag := False;

Similar Threads

  1. Window is redrawn inside the OpenGL area instead of the whole window
    By Visual act in forum OpenGL: User Software
    Replies: 0
    Last Post: 09-18-2015, 06:31 AM
  2. Replies: 2
    Last Post: 12-02-2014, 04:18 AM
  3. Replies: 10
    Last Post: 01-04-2007, 12:02 AM
  4. opengl can not arrive at the max size of client area of window .
    By guoxusheng in forum OpenGL: User Software
    Replies: 1
    Last Post: 08-22-2002, 12:38 PM
  5. Some of the client area displays nothing in Windows2000
    By Xiaofeng in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 01-16-2002, 11:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean