1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Project7
{
/// <summary>
/// Description Résumé de WinForm.
/// </summary>
public class WinForm : System.Windows.Forms.Form
{
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HTCAPTION = 0x2;
private System.Windows.Forms.CheckBox ChBoxTest;
[DllImportAttribute ("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute ("user32.dll")]
public static extern bool ReleaseCapture();
/// <summary>
/// Variable requise par le concepteur.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button BtnTest;
public WinForm()
{
//
// Requis pour la gestion du concepteur Windows Form
//
InitializeComponent();
//
// TODO: Ajouter tout le code du constructeur après l'appel de InitializeComponent
//
}
/// <summary>
/// Nettoyage des ressources utilisées.
/// </summary>
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
#region Code généré par le concepteur Windows Form
/// <summary>
/// Méthode requise pour la gestion du concepteur - ne pas modifier
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InitializeComponent()
{
this.BtnTest = new System.Windows.Forms.Button();
this.ChBoxTest = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// BtnTest
//
this.BtnTest.Location = new System.Drawing.Point(8, 48);
this.BtnTest.Name = "BtnTest";
this.BtnTest.Size = new System.Drawing.Size(112, 23);
this.BtnTest.TabIndex = 4;
this.BtnTest.Text = "Cliquez-moi !";
this.BtnTest.Click += new System.EventHandler(this.BtnTest_Click);
this.BtnTest.MouseDown += new System.Windows.Forms.MouseEventHandler(this.BtnTest_MouseDown);
//
// ChBoxTest
//
this.ChBoxTest.Location = new System.Drawing.Point(8, 8);
this.ChBoxTest.Name = "ChBoxTest";
this.ChBoxTest.Size = new System.Drawing.Size(120, 24);
this.ChBoxTest.TabIndex = 5;
this.ChBoxTest.Text = "Mode déplacement";
this.ChBoxTest.CheckedChanged += new System.EventHandler(this.ChBoxTest_CheckedChanged);
//
// WinForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.AutoScroll = true;
this.ClientSize = new System.Drawing.Size(400, 301);
this.Controls.Add(this.ChBoxTest);
this.Controls.Add(this.BtnTest);
this.Name = "WinForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "WinForm";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// Le point d'entrée principal de l'application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new WinForm());
}
private void BtnTest_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(ChBoxTest.Checked)
{
ReleaseCapture();
SendMessage(BtnTest.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
}
private void BtnTest_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Click");
}
private void ChBoxTest_CheckedChanged(object sender, System.EventArgs e)
{
if(ChBoxTest.Checked) BtnTest.Text = "Déplacez-moi !";
else BtnTest.Text = "Cliquez-moi !";
}
}
} |
Partager