0

Problem:
I have created a tool to help create levels for a game, the problem occurs when I click in the pictureBox, absolutely nothing happens, I place a breakpoint and it is never run.

pictureBox event settings:

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

Code:

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);
    }
}

Auto generated code:

#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

Please just ask for any other information

Sora
  • 21
  • 8
  • 1
    Are you sure you added the events correctly? Try: displayWindow.Mouseup += displayWindow_MouseUp And the same for mouse down. – Stijn Bernards May 19 '14 at 05:52
  • Is the "displayWindow" actually the picturebox you are trying to get events fired for? – Matthijs May 19 '14 at 05:53
  • 1
    both events are culled (this.displayWindow.MouseDown += new System.Windows.Forms.MouseEventHandler(this.displayWindow_MouseDown); this.displayWindow.MouseUp += new System.Windows.Forms.MouseEventHandler(this.displayWindow_MouseUp);) during the initialization of the displayWindow and yes the "disaplyWindow" is the picturebox i am trying to get the events for – Sora May 19 '14 at 05:53
  • @o_weisman After a bit of reading - this code is written using windows forms, not xaml, i have added the auto generated code, which is probably the part you where asking for – Sora May 19 '14 at 08:13
  • sorry, for some reason thought it was WPF – o_weisman May 19 '14 at 08:24
  • Do you mean only MouseDown is not triggered? Or both never run? Another thing I'd check is to make sure no other control is overlapping the PictureBox. – Fung May 19 '14 at 08:27
  • @Sora After looking at the code again, is it possible that your line `CPPFuncs.CreateNewWindow(displayWindow.Handle, 20, 20);` creates a new window that overlaps the one you create using WinForms? – o_weisman May 19 '14 at 08:34
  • @o_weisman the CreateNewWindow just creates a handle for the window which is used in my C++ code //bad naming on my part – Sora May 19 '14 at 08:44
  • @Fung the MouseDown and the MouseUp and never triggered also the pictureBox is the only thing running on the that specific form – Sora May 19 '14 at 08:45

1 Answers1

0

Code is still the same except a few changes,

I have added a panel on top of the pictureBox which does the checks for input

This has resolved the problem.

Likely cause: Most probably the CPP code underneath which used HGE to render to the window was absorbing all of the events somehow.

Thanks to all those who responded

Sora
  • 21
  • 8