C#窗口窗体MouseDown事件未被调用

本文关键字:调用 事件 MouseDown 窗口 窗体 | 更新日期: 2023-09-27 18:03:53

问题
我创建了一个工具来帮助为游戏创建关卡,当我点击pictureBox时,问题就会出现,完全没有发生任何事情,我放置了一个断点,它永远不会运行。

pictureBox事件设置:

http://postimg.org/image/hllv4vwjz/

代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Level_Editor
{
    public partial class tileWindow : Form
    {
        LevelControls myLevelControls;
        public float myStartIndex_X;
        public float myStartIndex_Y;
        public float myEndIndex_X;
        public float myEndIndex_Y;
        public tileWindow()
        {
            InitializeComponent();
            CPPFuncs.CreateNewWindow(displayWindow.Handle, 20, 20);
            CPPFuncs.AddTileSprite("Data/Tiles/blank.dds", "blank");
            Application.Idle += AppIdle;
            myLevelControls = new LevelControls();
            myLevelControls.AddParent(this);
            myLevelControls.Show();
        }
        private void AppIdle(object Sender, EventArgs e)
        {
            CPPFuncs.Render();
            this.Invalidate();
        }
        private void quitButton_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        private void displayWindow_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            CPPFuncs.Input((short)e.KeyCode);
        }
        private void displayWindow_MouseDown(object sender, MouseEventArgs e)
        {
            myStartIndex_X = e.X;
            myStartIndex_Y = e.Y;
        }
        private void displayWindow_MouseUp(object sender, MouseEventArgs e)
        {
            myEndIndex_X = e.X;
            myEndIndex_Y = e.Y;
            if (myLevelControls.myCurrentSelectedTile != "")
            {
                CPPFuncs.SetTiles(myStartIndex_X, myStartIndex_Y, myEndIndex_X, myEndIndex_Y, myLevelControls.myCurrentSelectedTile);
            }
        }
    }
    static class CPPFuncs
    {
        const string EngineDLLName = "HGE Handle.dll";
        [DllImport(EngineDLLName, CallingConvention = CallingConvention.Cdecl)]
        public extern static unsafe int CreateNewWindow(IntPtr aHwnd, int aTileWidthCount, int aTileHeightCount);
        [DllImport(EngineDLLName, CallingConvention = CallingConvention.Cdecl)]
        public extern static unsafe int AddTileSprite(string aSprite, string aFileName);
        [DllImport(EngineDLLName, CallingConvention = CallingConvention.Cdecl)]
        public extern static unsafe int LoadLevel(string aDir);
        [DllImport(EngineDLLName, CallingConvention = CallingConvention.Cdecl)]
        public extern static unsafe int MoveCamera(float x, float y);
        [DllImport(EngineDLLName, CallingConvention = CallingConvention.Cdecl)]
        public extern static unsafe int Input(short aKey);
        [DllImport(EngineDLLName, CallingConvention = CallingConvention.Cdecl)]
        public extern static unsafe int SetTiles(float aStartX, float aStartY, float anEndX, float anEndY, string aTileSprite);
        [DllImport(EngineDLLName, CallingConvention = CallingConvention.Cdecl)]
        public extern static unsafe int Render();
        [DllImport(EngineDLLName, CallingConvention = CallingConvention.Cdecl)]
        public extern static unsafe int ScrollTiles(bool aMoveUpFlag);
    }
}

自动生成代码:

#region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.displayWindow = new System.Windows.Forms.PictureBox();
        ((System.ComponentModel.ISupportInitialize)(this.displayWindow)).BeginInit();
        this.SuspendLayout();
        // 
        // displayWindow
        // 
        this.displayWindow.Location = new System.Drawing.Point(-6, -2);
        this.displayWindow.Name = "displayWindow";
        this.displayWindow.Size = new System.Drawing.Size(1020, 788);
        this.displayWindow.TabIndex = 0;
        this.displayWindow.TabStop = false;
        this.displayWindow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.displayWindow_MouseDown);
        this.displayWindow.MouseUp += new System.Windows.Forms.MouseEventHandler(this.displayWindow_MouseUp);
        this.displayWindow.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.displayWindow_PreviewKeyDown);
        // 
        // tileWindow
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.BackColor = System.Drawing.Color.Lavender;
        this.ClientSize = new System.Drawing.Size(1011, 783);
        this.Controls.Add(this.displayWindow);
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        this.Name = "tileWindow";
        this.Text = "TBS Level Editor";
        ((System.ComponentModel.ISupportInitialize)(this.displayWindow)).EndInit();
        this.ResumeLayout(false);
    }
    #endregion

请只询问任何其他信息

C#窗口窗体MouseDown事件未被调用

代码仍然是一样的,除了一些更改,

我在pictureBox的顶部添加了一个面板,用于检查输入

这已经解决了问题。

可能的原因:最有可能的是,下面使用HGE渲染到窗口的CPP代码以某种方式吸收了所有事件。

感谢所有回复

的人