How to control a headless form by using the mouse

Source: Internet
Author: User

This question is also from the forum question, also is the problem of the novice of. Net WinForm, such a problem if in deplphi such plate is immediately killed by seconds, but. NET version of people do not seem to know too much.

Introduces two methods, one is to send Sc_move message, one is to change the mouse region message

Method One:

 1.using System; 
2.using System.Collections.Generic;
3.using System.ComponentModel;
4.using System.Data;
5.using System.Drawing;
6.using System.Text;
7.using System.Windows.Forms;
8.using System.Runtime.InteropServices;
9.namespace WindowsApplication1
10.{
One. Public partial class Form1:form
12. {
Form1 ()
14. {
InitializeComponent ();
17}
. [DllImport ("user32.dll", EntryPoint = "SendMessage")]
. public static extern int SendMessage (int hWnd, int wmsg, int wParam, int lParam);
[DllImport ("user32.dll", EntryPoint = "ReleaseCapture")]
20. public static extern int releasecapture ();
. public const int wm_syscommand = 0x0112;
. public const int sc_move = 0xf012;
.
.
private void Form1_mousedown (object sender, MouseEventArgs e)
26. {
ReleaseCapture ();
SendMessage (this. Handle.toint32 (), Wm_syscommand, Sc_move, 0);
.}

private void Form1_Load (object sender, EventArgs e)
32. {
A.
34. }
35.
.}

Method Two:

1.using  System;
2.using System.Windows.Forms;
3.namespace WindowsApplication1
6.9
5. Public Partial class Form1:form
6. {
7. Public Form1 ()
8. {
9. InitializeComponent ();
Ten }
11.
protected override void WndProc (ref message m)
{
base. WndProc (ref m); If (m.msg = = 0x84)
{
Switch (M.result.toint32 ())
{
Case 1:
19.
M.result = new IntPtr (2); break;
. }
A. }
. }
. }
25.}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.