gpt4 book ai didi

c# - WPF 中的可拖动控件?

转载 作者:行者123 更新时间:2023-11-30 20:06:14 28 4
gpt4 key购买 nike

虽然我在表单方面有一些经验,但我对 WPF 有点陌生,所以我决定最终尝试弄清楚如何使用 WPF。因此,当我使用可拖动控件时,这是我想出的代码(我试图将其更改为与 WPF 一起使用,但控件到处都在抽动):

private void rectangle1_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed) {
double x = this.Left + (double)e.GetPosition(this).X - (double)rectangle1.Margin.Left;
double y = this.Top + (double)e.GetPosition(this).Y - (double)rectangle1.Margin.Top;
rectangle1.Margin = new Thickness(x, y, rectangle1.Margin.Right, rectangle1.Margin.Bottom);
}
}

最佳答案

您想使用 adorners实现拖动、缩放、旋转等

关于c# - WPF 中的可拖动控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10022605/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com