tags:

views:

77

answers:

2

I am making a very basic map editor. I'm halfway through it and one problem i hit is how to delete an object.

I would like to press delete but there appears to be no keydown event for pictureboxes and it will seem like i will have it only on my listbox.

What is the best solution for deleting an object in my editor?

+1  A: 

i think this is the best methode:

http://felix.pastebin.com/Q0YbMt22

Werewolve
i see where your going with that.
acidzombie24
+1  A: 

You'll want the PictureBox to participate in the tabbing order and show that it has the focus. That takes a bit of minor surgery. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form. Implement the KeyDown event.

using System;
using System.Drawing;
using System.Windows.Forms;

class SelectablePictureBox : PictureBox {
  public SelectablePictureBox() {
    this.SetStyle(ControlStyles.Selectable, true);
    this.TabStop = true;
  }
  protected override void OnMouseDown(MouseEventArgs e) {
    this.Focus();
    base.OnMouseDown(e);
  }
  protected override void OnEnter(EventArgs e) {
    this.Invalidate();
    base.OnEnter(e);
  }
  protected override void OnLeave(EventArgs e) {
    this.Invalidate();
    base.OnLeave(e);
  }
  protected override void OnPaint(PaintEventArgs pe) {
    base.OnPaint(pe);
    if (this.Focused) {
      var rc = this.ClientRectangle;
      rc.Inflate(-2, -2);
      ControlPaint.DrawFocusRectangle(pe.Graphics, rc);
    }
  }
}
Hans Passant
Thanks, it works nicely :D
acidzombie24