【发布时间】:2012-01-26 20:53:45
【问题描述】:
我有一个显示音符图像的图片框。我希望能够根据放下位置的相应 Y 位置在包含它的面板内上下拖动音高时更改音高的值。使用下面的代码,音高确实发生了变化,但似乎 Y 值只是随机的,当它应该上升时,我拖动越高,向下拖动越低。
private void StartDrag(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isDragging = true;
pitch = e.Y;
this.Location = new Point(this.Location.X, pitch);
}
}
private void StopDrag(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
isDragging = false;
pitch = e.Y;
}
}
private void NoteDrag(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (isDragging)
{
this.Top = this.Top + (e.Y - this.pitch); //move in Vertical direction
}
}
【问题讨论】:
-
你不能为此设置一个滑块吗?
-
我不熟悉滑块,因为我是 C# 新手。每个音符是否有可能有自己的滑块?在程序中可以添加多个注释
-
这些拖拽音符的问题本周无休无止。一定是某种家庭作业。
-
设置滑块样式可能是对 web/WPF/Silverlight 控件的引用。如果您不限于 winforms,这听起来很适合 WPF 或 Silverlight。这种交互会更简单。
标签: c# winforms drag-and-drop panel picturebox