C# 如何在windows窗体中查找鼠标移动速度?
如何在鼠标事件中找到windows窗体控件中的鼠标移动速度。根据鼠标移动速度,我需要移动控件。就像用鼠标左键移动鼠标一样,根据移动控件所需的鼠标速度,我会这样做:C# 如何在windows窗体中查找鼠标移动速度?,c#,mouseevent,windows-forms-designer,onmousemove,C#,Mouseevent,Windows Forms Designer,Onmousemove,如何在鼠标事件中找到windows窗体控件中的鼠标移动速度。根据鼠标移动速度,我需要移动控件。就像用鼠标左键移动鼠标一样,根据移动控件所需的鼠标速度,我会这样做: 第一次移动鼠标时启动计时器并保存起始位置。 如果它继续移动,请查看移动是否在直线上,如果不是,请停止计时器,然后应用公式计算移动的总距离,并将其除以所用时间。 如果有多条“直线”,您可以使用平均值(总和/超高)。也许Microsoft的这个代码示例可以帮助您: using System; using System.Windows.Fo
第一次移动鼠标时启动计时器并保存起始位置。 如果它继续移动,请查看移动是否在直线上,如果不是,请停止计时器,然后应用公式计算移动的总距离,并将其除以所用时间。
如果有多条“直线”,您可以使用平均值(总和/超高)。也许Microsoft的这个代码示例可以帮助您:
using System;
using System.Windows.Forms;
using System.Reflection;
namespace SystemInfoBrowser
{
public partial class SystemInfoBrowserForm : System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.TextBox textBox1;
public SystemInfoBrowserForm()
{
this.SuspendLayout();
InitForm();
// Add each property of the SystemInformation class to the list box.
Type t = typeof(System.Windows.Forms.SystemInformation);
PropertyInfo[] pi = t.GetProperties();
for (int i = 0; i < pi.Length; i++)
listBox1.Items.Add(pi[i].Name);
textBox1.Text = "The SystemInformation class has " + pi.Length.ToString() + " properties.\r\n";
// Configure the list item selected handler for the list box to invoke a
// method that displays the value of each property.
listBox1.SelectedIndexChanged += new EventHandler(listBox1_SelectedIndexChanged);
this.ResumeLayout(false);
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
// Return if no list item is selected.
if (listBox1.SelectedIndex == -1) return;
// Get the property name from the list item.
string propname = listBox1.Text;
if (propname == "PowerStatus")
{
// Cycle and display the values of each property of the PowerStatus property.
textBox1.Text += "\r\nThe value of the PowerStatus property is:";
Type t = typeof(System.Windows.Forms.PowerStatus);
PropertyInfo[] pi = t.GetProperties();
for (int i = 0; i < pi.Length; i++)
{
object propval = pi[i].GetValue(SystemInformation.PowerStatus, null);
textBox1.Text += "\r\n PowerStatus." + pi[i].Name + " is: " + propval.ToString();
}
}
else
{
// Display the value of the selected property of the SystemInformation type.
Type t = typeof(System.Windows.Forms.SystemInformation);
PropertyInfo[] pi = t.GetProperties();
PropertyInfo prop = null;
for (int i = 0; i < pi.Length; i++)
if (pi[i].Name == propname)
{
prop = pi[i];
break;
}
object propval = prop.GetValue(null, null);
textBox1.Text += "\r\nThe value of the " + propname + " property is: " + propval.ToString();
}
}
private void InitForm()
{
// Initialize the form settings
this.listBox1 = new System.Windows.Forms.ListBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));
this.listBox1.Location = new System.Drawing.Point(8, 16);
this.listBox1.Size = new System.Drawing.Size(172, 496);
this.listBox1.TabIndex = 0;
this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBox1.Location = new System.Drawing.Point(188, 16);
this.textBox1.Multiline = true;
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBox1.Size = new System.Drawing.Size(420, 496);
this.textBox1.TabIndex = 1;
this.ClientSize = new System.Drawing.Size(616, 525);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.listBox1);
this.Text = "Select a SystemInformation property to get the value of";
}
}
使用系统;
使用System.Windows.Forms;
运用系统反思;
命名空间系统信息浏览器
{
公共部分类SystemInfoBrowserForm:System.Windows.Forms.Form
{
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.TextBox textBox1;
公共系统InfoBrowserForm()
{
这个.SuspendLayout();
InitForm();
//将SystemInformation类的每个属性添加到列表框中。
类型t=类型(System.Windows.Forms.SystemInformation);
PropertyInfo[]pi=t.GetProperties();
对于(int i=0;i
}
它来自并使用SystemInformation类向您显示一些属性,它还向您显示MouseSpeed,其范围从1到20,默认情况下应设置为10。您只需提取此属性的代码部分,就可以设置
您无法可靠地执行此操作,因为这是不必要的,您根本不关心速度,只需按新的鼠标位置重新定位即可。如果你有一段时间没有得到新的更新,不管是什么原因,那么它仍然可以正常工作。使用位置。我已经通过使用MouseDown、MouseMove和MouseUp等鼠标事件实现了触摸平移操作。根据你的建议,平移操作非常完美,我已经使用了鼠标位置。但我还需要在相同的鼠标事件中实现滑动滚动支持,我如何才能实现这一点?我需要OnMouseMove覆盖方法中的鼠标移动速度,在这一点上我怎么能找到呢?