110,534
社区成员
发帖
与我相关
我的任务
分享
public partial class Form1 : Form
{
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(System.IntPtr hwnd, int wMsg, int wParam, int lParam);
public const int WM_SYSCOMMAND = 0x0112;
public const int SC_MOVE = 0xF010;
public const int HTCAPTION = 0x0002;
public Form1()
{
InitializeComponent();
this.panel1.AutoScroll = true;
}
private void label1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
ReleaseCapture();
SendMessage(label1.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0x0);
this.panel1.Refresh();
//如果label超出panel范围,不会出现滚动条,为什么?
}
}
private void button1_Click(object sender, EventArgs e)
{
label1.Left = this.panel1.Width - 20;///会出现滚动条
}
}
label1.Left = label1.Left+1;
label1.Left = label1.Left-1;