- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 WinForms 应用程序中有一个 Canvas (面板控件),用户可以在其中拖动文本框、标签等内容。但我想让他们更容易更精确地对齐对象。我已经读过它并且 Adorners 似乎是要走的路?但是,显然它只适用于 WPF。不幸的是,WPF 不适合我。
我想要完成的是,每当用户在 Canvas 中四处拖动对象时,都会弹出线条...它们在 Windows 窗体设计器 View 中的工作方式。
如果有任何帮助,我将不胜感激。
谢谢。
最佳答案
谢谢大家的回答。
我已经想出了自己的解决方案。代码在下面。目前还没有“台词”,但总有一天我会解决的...
Label l = (Label)sender;
foreach (Control control in Canvas.Controls)
{
if (l.Location.X > control.Location.X + control.Size.Width && l.Location.X < control.Location.X + control.Size.Width + 5)
l.Location = new Point(control.Location.X + control.Size.Width + 5, l.Location.Y);
else if (l.Location.X < control.Location.X - l.Size.Width && l.Location.X > control.Location.X - l.Size.Width - 5)
l.Location = new Point(control.Location.X - l.Size.Width - 5, l.Location.Y);
else if (l.Location.Y > control.Location.Y + control.Size.Height && l.Location.Y < control.Location.Y + control.Size.Height + 5)
l.Location = new Point(l.Location.X, control.Location.Y + control.Size.Height + 5);
else if (l.Location.Y < control.Location.Y - control.Size.Height && l.Location.Y > control.Location.Y - control.Size.Height - 5)
l.Location = new Point(l.Location.X, l.Location.Y - 5);
this.Update();
}
上述代码必须放在 Control_MouseMove 事件中,当然,您仍然需要自己的实际移动控件的代码。
上面的代码会将您拖动的控件捕捉到最近控件的右侧、左侧、顶部或底部 5 个像素。
关于c# - C# Windows 窗体的装饰器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2247648/
对于一个科学实验,我写了一个turtle.py ,它会打开一个 800x480 的窗口并绘制一个缓慢增长的黑点。 turtle.py以 C:\Users\kaza>python C:\Users\ka
我开发了一个 swing 应用程序,但每次运行应用程序时都会打开一个新窗口。我希望如果一个窗口已经打开,则其他窗口不允许打开。 最佳答案 Here是一个 Java 单一应用实例的例子: A singl
有没有办法检测主进程中 Electron 的结构? process.platform 似乎也在 x64 机器上返回 win32,我没有在文档中找到任何获取架构的选项。 最佳答案 你试过 process
public short[] HanningWindow(short[] signal_in ,int pos ,int size) { for (int i= pos; i < pos+si
我有一个具有这些属性的 Electron 窗口: mainWindow = new BrowserWindow({ width: 800, height: 600, title: "Aqu
我有一个 Ubuntu 工作站,我正在尝试引导一个 Windows 节点。 Windows 节点在端口 2222 上打开了 ssh。我一直在关注 http://docs.opscode.com/plu
我是一名优秀的程序员,十分优秀!