I'm writing a basic 2D tilemap editor for a hobby-level game, and while the game itself is going fairly well, I'm having some trouble with the Winform aspect (which is why I'm posting this in general programming rather than the game programming board).
The problem I'm having is that the picturebox which displays the XNA output (the map that's being edited) registers mouse clicks even when there's another window in front of it (for example, clicking OK on a save dialog box will edit whatever tile is behind it). I thought I'd fixed it with the marked addition below, but that just introduced a more confusing bug (it didn't seem like a particularly clean solution anyway, so I'm not surprised).
protected override void Update(GameTime gameTime)
{
Camera.Position = new Vector2(hscroll.Value, vscroll.Value);
MouseState ms = Mouse.GetState();
if ((ms.X > 0) && (ms.Y > 0) &&
(ms.X < Camera.ViewPortWidth) &&
(ms.Y < Camera.ViewPortHeight))
{
Vector2 mouseLoc = Camera.ScreenToWorld(
new Vector2(ms.X, ms.Y));
if (Camera.WorldRectangle.Contains(
(int)mouseLoc.X, (int)mouseLoc.Y) **&& pictureBox.Capture**) //<--
{
if (ms.LeftButton == ButtonState.Pressed)
//....
Now it no longer edits the map through save/load dialogs, but instead refuses to acknowledge right clicks nine times out of ten--until the window is minimized and restored. After that it works exactly as expected. Anyone have any ideas? MSDN was less than helpful.






