在Panel中SendMessage移动Label,AutoScroll=true,但不出现滚动条,求解.

guojh021 2014-02-08 11:24:37

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;///会出现滚动条
}
}
...全文
254 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
guojh021 2014-02-19
  • 打赏
  • 举报
回复
guojh021 2014-02-12
  • 打赏
  • 举报
回复
label1.Left = label1.Left+1;
label1.Left = label1.Left-1;
guojh021 2014-02-12
  • 打赏
  • 举报
回复
引用 2 楼 feiyun0112 的回复:
if (e.Button == System.Windows.Forms.MouseButtons.Left) { ReleaseCapture(); SendMessage(label1.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0x0); this.panel1.Refresh(); //如果label超出panel范围,不会出现滚动条,为什么? label1.Location = new Point(label1.Location.X+1, label1.Location.Y); label1.Location = new Point(label1.Location.X - 1, label1.Location.Y); }
我也想这样做.觉得有点傻....所以发个贴问问原因.
feiyun0112 2014-02-11
  • 打赏
  • 举报
回复
if (e.Button == System.Windows.Forms.MouseButtons.Left) { ReleaseCapture(); SendMessage(label1.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0x0); this.panel1.Refresh(); //如果label超出panel范围,不会出现滚动条,为什么? label1.Location = new Point(label1.Location.X+1, label1.Location.Y); label1.Location = new Point(label1.Location.X - 1, label1.Location.Y); }
guojh021 2014-02-11
  • 打赏
  • 举报
回复
顶起来吧~

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧