如何控制鼠标位置 [英] How do I control mouse position

查看:102
本文介绍了如何控制鼠标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。

我正在尝试制作乐谱,我的鼠标位置有问题。我有一些作为谱表的行。问题是如何设置光标移动的鼠标移动只是在线上或线之间,而不是在任何地方。谢谢。

Hi.
I am trying to make a musical notation and I have a problem with mouse position .I have some lines as staff .the problem is how can I set mouse movement that the cursor move just on or between lines ,NOT EVERYWHERE. thank you.

public partial class Form2 : Form
   {
       Graphics staff;
       Graphics note;
       Font f1 = new System.Drawing.Font("Polihymnia", 35, FontStyle.Regular);//music font size 35
       public Form2()
       {
           InitializeComponent();
       }

<pre lang="C#">private void Form2_Load(object sender, EventArgs e)
        {
            staff = panel1.CreateGraphics(); 
             note = panel1.CreateGraphics();
                              //------------------------------------------
            PictureBox pb = new PictureBox() { Image = Image.FromFile(@"G:\hh.png") };//cursor _whole note   
            this.Cursor = new Cursor(((Bitmap)pb.Image).GetHicon());
            
                              //------------------------------------------
         
            
        }

        private void staff_show(int x)//
        {
           
            
          

            Pen _pen = new Pen(Color.Black); 
            //---------------------------------------------

            for (int i = x; i <= x + 110; i = i + 110) 
            {
                for (int j = i; j <= i + 40; j = j + 10)
                {
                    staff.DrawLine(_pen, 100, j, 900, j); // staff
                }
            note.DrawString("c", f1, Brushes.Black, 125, i-22); // 4/4 ---------------------------------
            }

            for (int ii = 100; ii <= 900; ii = ii + 200)
            {
                staff.DrawLine(_pen, ii, x, ii, x + 150); // barline
                
            }
            note.DrawString("G", f1, Brushes.Black, 90, x-11); // G clef --------------------------------------------
            note.DrawString("?", f1, Brushes.Black, 90, x+80); // F clef --------------------------------------------
        
           
           
        }

        private void Form2_Shown(object sender, EventArgs e)
        {

            staff_show(100);
            staff_show(340);
            staff_show(580);

        }
      

    }
}





我尝试了什么:



我设计了一个带有面板的表单,我在其中绘制一些行作为谱表并使用音乐字体进行绘制notes



What I have tried:

I design a form with a panel in which I draw some lines as staff and used a music font for draw notes

推荐答案

我不建议以编程方式移动鼠标光标。它可以被认为是过于干扰和激怒大多数用户。



但是,如果你真的需要这样做,你可以通过Windows API <$ c $来做到这一点c> SendInput :

SendInput功能(Windows) [ ^ ]。



我可以通过P / Invoke完成。一切都已经完成了: http://www.pinvoke.net/default.aspx/user32.sendinput [ ^ ]。



实际上,P / Invoke极大地损害了你的平台兼容性,但你别无选择;控制光标不是.NET FCL的一部分;无论如何,请看我上面的第一段。 :-)



您的代码示例,但我的感觉是您犯了太大的错误:使用 PictureBox 并使用 CreateGraphics 。这不是图形渲染的完成方式。但是我们可以单独讨论它;它需要您的项目更多信息。



-SA
I would not recommend to programmatically move a mouse cursor, ever. It can be considered as too intrusive and irritate most users.

However, if you really need to do that, you can do it via the Windows API SendInput:
SendInput function (Windows)[^].

I can be done via P/Invoke. Everything is already done for you: http://www.pinvoke.net/default.aspx/user32.sendinput[^].

Actually, P/Invoke greatly compromise your platform compatibility, but you have no choice; controlling of the cursor is not a part of .NET FCL; anyway, see my first paragraph above. :-)

Your code sample, but my feeling is that you a making too big mistakes: using PictureBox and using CreateGraphics. This is not how graphic rendering is done. But we can discuss it separately; it needs more information of your project.

—SA


这篇关于如何控制鼠标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆