new Moving function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • willem

    #1

    new Moving function

    Hi,

    I want move my form with mouse when I press button over a different position
    from normal bar of title.

    I set MouseUp, MouseDown and, MouseMove events and all works good.

    is it possible work with a more intelligent method ?

    When I move a normal form only its border is visible.
    How can I do this effect in my personal moving functions ?

    Thanks a Lot





  • Hai Ly Hoang - MT00KSTN

    #2
    Re: new Moving function

    Hi,
    To move the windows by yourself, you have to implement mousemove. To make
    sure that you drag from your form, you have
    to override MouseDown. Therefore, implement 3 methods is the only way to
    move your form.
    To have the border of the windows move, you should draw a rectangle with
    Graphics object in MouseMove Event.


    "willem" <willem@libero. it> wrote[color=blue]
    > Hi,
    >
    > I want move my form with mouse when I press button over a different[/color]
    position[color=blue]
    > from normal bar of title.
    >
    > I set MouseUp, MouseDown and, MouseMove events and all works good.
    >
    > is it possible work with a more intelligent method ?
    >
    > When I move a normal form only its border is visible.
    > How can I do this effect in my personal moving functions ?
    >
    > Thanks a Lot[/color]



    Comment

    • Magnus Krisell

      #3
      Re: new Moving function

      There is a clever way to achieve this, and have it work the same
      way as when the window is moved using the title bar.

      The trick is to override the WndProc method of the form and
      handle the WM_NCHITTEST message and return HTCAPTION
      for the appropriate mouse coordinates.

      As a demo, create a new form and add this code to it:

      protected override void WndProc(ref Message m)
      {
      // from WinUser.h
      const int WM_NCHITTEST = 0x0084;
      const int HTCAPTION = 2;

      if (m.Msg == WM_NCHITTEST)
      {
      Point screenPoint = new Point((int)m.LP aram % 65536,
      (int)m.LParam / 65536);
      Point clientPoint = PointToClient(s creenPoint);

      // Check that the user clicked in the area to be
      // used for moving the window, in this case a circle
      // of radius 50 centered at coordinates 100, 100
      if (Math.Pow(clien tPoint.X - 100, 2) +
      Math.Pow(client Point.Y - 100, 2) < 50 * 50)
      {
      m.Result = (IntPtr)HTCAPTI ON;
      return;
      }
      }
      base.WndProc(re f m);
      }

      protected override void OnPaint(PaintEv entArgs e)
      {
      e.Graphics.Fill Ellipse(Brushes .Blue, 50, 50, 100, 100);
      }

      This obviously depends on how Windows handles messages, so it
      probably isn't 100% "future proof". But right now it works great.

      - Magnus


      "willem" <willem@libero. it> wrote in message
      news:OGhv0IeeDH A.892@TK2MSFTNG P12.phx.gbl...[color=blue]
      > Hi,
      >
      > I want move my form with mouse when I press button over a different[/color]
      position[color=blue]
      > from normal bar of title.
      >
      > I set MouseUp, MouseDown and, MouseMove events and all works good.
      >
      > is it possible work with a more intelligent method ?
      >
      > When I move a normal form only its border is visible.
      > How can I do this effect in my personal moving functions ?
      >
      > Thanks a Lot
      >[/color]


      Comment

      Working...