click n' drag: easy question (i hope)

Should be an easy question: I've seen in several programs, that you can click anywhere in a form window to drag the form around, how do I set that up

Answer this question

click n' drag: easy question (i hope)

  • grellsworth

    Hi,
    You  may like to post this query on Windows Forms Forum. That's the best place to get quick response on language agnostic winforms related queries.

    Is you are unable to do so then please let us know. We will write and post a sample code here.

    Thanks.



  • Snommit

    They gave me this code in c#, i tryed to follow its basic idea to get it to work in j#, but I cant get it to work.



    private const int WM_NCLBUTTONDOWN = 0xA1;
    private const int HTCAPTION = 0x2;

    [ DllImport( "user32.dll" ) ]
    public static extern bool ReleaseCapture();

    [ DllImport( "user32.dll" ) ]
    public static extern int SendMessage( IntPtr hWnd, int Msg, int wParam, int lParam );

    private void Form1_MouseDown( object sender, MouseEventArgs e )
    {
      if ( e.Button == MouseButtons.Left )
      {
        ReleaseCapture();
        SendMessage( Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0 );
      }



     


    id really appreciate the j# code.

  • Anand Kumar S.R

    Hi,
    Here is the J# equivalent ...

    private final int WM_NCLBUTTONDOWN = 0xA1;
    private final int HTCAPTION = 0x2;

    /** @attribute DllImport( "user32.dll" ) */
    public static native boolean ReleaseCapture();

    /** @attribute DllImport("user32.dll" ) */
    public static native int SendMessage( IntPtr hWnd, int Msg, int wParam, int lParam );

    private void Form1_MouseDown( Object sender, MouseEventArgs e )

          if ( e.get_Button() == MouseButtons.Left ) 
          { 
                ReleaseCapture(); 
                SendMessage( Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0 );
          }
    }


    Before compiling this code...
    1. Import following packages ...
          import System.Runtime.InteropServices.*;
          import System.*;
          import System.Windows.Forms.*;

    2.  Replace Handle
    with appropriate window handle.
    3. Add reference to System.Windows.Forms.dll.


    Also looking at the converted code can you please post here that what in C# you were finding difficult to convert into J#. Based upon that we may provide you pointers to understand those J# concepts/language constructs.

    Thanks.



  • click n' drag: easy question (i hope)