C# 从上到下的尺寸
这更多的是一个方法问题。我知道如何创建一个从四面八方扩展的控件,但我不明白为什么这段代码在没有重新绘制问题(抖动)的情况下不能流畅地工作。它仅从顶部缩放面板,但在此过程中会出现抖动。我错过了什么C# 从上到下的尺寸,c#,winforms,C#,Winforms,这更多的是一个方法问题。我知道如何创建一个从四面八方扩展的控件,但我不明白为什么这段代码在没有重新绘制问题(抖动)的情况下不能流畅地工作。它仅从顶部缩放面板,但在此过程中会出现抖动。我错过了什么 public partial class Form1 : Form { Point MousePoint = new Point(); public Form1() { InitializeComponent(); panel1.Mouse
public partial class Form1 : Form
{
Point MousePoint = new Point();
public Form1()
{
InitializeComponent();
panel1.MouseMove += Panel1_MouseMove;
panel1.MouseDown += Panel1_MouseDown;
panel1.Width = 100;
panel1.Height = 100;
}
private void Panel1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
MousePoint = e.Location;
}
}
private void Panel1_MouseMove(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
panel1.Top = e.Location.Y + panel1.Location.Y - MousePoint.Y;
panel1.Height = panel1.Height - e.Y + MousePoint.Y;
}
}
}
您正在更改两个不同的属性:顶部,然后是高度。这可能会导致你看到的“不安” 尝试改用SetBounds调用:
panel1.SetBounds(panel1.Left,
e.Location.Y + panel1.Location.Y - mousePoint.Y,
panel1.Width,
panel1.Height - e.Y + mousePoint.Y);
如果面板中包含锚定的控件等,也会影响调整大小的平滑度。将窗体设置为双缓冲区就是这样!我从来没有想过挫折,也从来没有使用过它!非常感谢你给我的启发。