Vincent,
Derive from the label control and override its WndProc
private const int WM_NCHITTEST = 0x84;
private const int HTCAPTION = 0x2;
private const int HTCLIENT = 0x1;
protected override void WndProc(ref Message m)
{
base.WndProc (ref m);
if(m.Msg == WM_NCHITTEST && m.Result == new IntPtr(HTCLIENT))
{
m.Result = new IntPtr(HTCAPTION);
}
That should work for any control
--
HTH
- Mostra testo tra virgolette -
Hi, thanks.
I tried as you suggested but was not able to see it working.
This is my class:
namespace UtilityConfigManager
{
public class MovingLabel: Label
{
private const int WM_NCHITTEST = 0x84;
private const int HTCAPTION = 0x2;
private const int HTCLIENT = 0x1;
public MovingLabel()
{
}
protected override void WndProc(ref Message m)
{
base.WndProc (ref m);
if(m.Msg == WM_NCHITTEST && m.Result == new IntPtr(HTCLIENT))
{
m.Result = new IntPtr(HTCAPTION);
}
}
}
}
and this is my form where I try to use the control:
public class Form2 : System.Windows.Forms.Form
{
private UtilityConfigManager.MovingLabel mlabel1;
private System.ComponentModel.Container components = null;
public Form2()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent()
{
this.mlabel1 = new UtilityConfigManager.MovingLabel();
this.SuspendLayout();
//
// mlabel1
//
this.mlabel1.AllowDrop = true;
this.mlabel1.Location = new System.Drawing.Point(72, 48);
this.mlabel1.Name = "mlabel1";
this.mlabel1.TabIndex = 1;
this.mlabel1.Text = "mlabel1";
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.mlabel1);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false);
}
}
Where Am I wrong?
Thanks