salut,

j'utilise l'API windows pour déplacer certains composants sur ma forme en execution. Ca marche parfaitement pour les boutons, mais pas pour les labels, alors que je les construit exactement pareil.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
        using System.Runtime.InteropServices;
 
        private const int HTCAPTION = 0x2;
        private const int WM_NCLBUTTONDOWN = 0xA1;
 
        [DllImport("User32.dll")]
        public static extern bool ReleaseCapture();
 
        [DllImport("User32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
        //ok pour le bouton
        private void button1_MouseDown(object sender, MouseEventArgs e)
        {
            Button buttonSelected;
 
            buttonSelected = sender as Button;
 
            if (e.Button == MouseButtons.Left)
            {
                ReleaseCapture();
                SendMessage(buttonSelected.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
            }
        }
 
        //pas ok pour le label
        private void label1_MouseDown(object sender, MouseEventArgs e)
        {
            Label labelSelected;
 
            labelSelected = sender as Label;
 
            if (e.Button == MouseButtons.Left)
            {
                ReleaseCapture();
                SendMessage(labelSelected.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
            }
        }
Est ce que j'adapte mal ? Il y a une explication logique ?