Recognize touch as MouseDown event

前端 未结 4 2013
没有蜡笔的小新
没有蜡笔的小新 2020-12-31 18:58

I am building a puzzle game in C#, winforms for a touch screen.

I am able to handle touch events on mouse handlers, in fact, i did nothing at all, but it already rec

4条回答
  •  感情败类
    2020-12-31 19:22

    To perform touch operations correct you should not use the mouse handler event's just because touch and use the mouse handler it is going through a library built to handle touch as mouse and not what you should be using for a game your able to register your application to handle touch events using the methods from user32.dll, below is an example of how to implement touch handling in your application.

        [DllImport("user32.DLL")]
        public static extern bool RegisterTouchWindow(IntPtr hwnd, int ulFlags);
    
        [DllImport("user32.DLL")]
        public static extern bool UnregisterTouchWindow(IntPtr hwnd);
    
    
        public Form1()
        {
            InitializeComponent();
            RegisterTouchWindow(button1.Handle, 0);
        }
    
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            UnregisterTouchWindow(button1.Handle);
        }
    

提交回复
热议问题