Here's a very simple way to do this; it assumes:
1. You want to capture the co-ordinates of the MouseDown only when the user clicks on the Form with the Control-Alt keys held down.
2. When a valid click is received, then you want a TextBox to pop-up located where the user clicked on the Form, and this TextBox will be closed when the user hits the Escape Key.
At design-time: assume your main form is named 'form1
1. put a Textbox on the Form, size and style it in the way you want, set its 'Visible property to 'false. Name it 'tbCoordinates
2. add this code: link-up the Form's MouseDown EventHandler, and the TextBox's KeyDown and Leave EventHandlers to the code here:
private Point mouseDownPoint;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (tbCoordinates.Visible)
{
tbCoordinates.Hide();
this.Cursor = Cursors.Default;
return;
}
if (!(ModifierKeys.HasFlag(Keys.Control) && ModifierKeys.HasFlag(Keys.Alt))) return;
mouseDownPoint = e.Location;
tbCoordinates.Location = mouseDownPoint;
tbCoordinates.Show();
tbCoordinates.Focus();
tbCoordinates.Capture = true;
this.Cursor = Cursors.IBeam;
}
private void tbCoordinates_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape || e.KeyCode == Keys.Return)
{
tbCoordinates.Hide();
this.Cursor = Cursors.Default;
}
}
private void tbCoordinates_Leave(object sender, EventArgs e)
{
if (tbCoordinates.Visible)
{
tbCoordinates.Hide();
this.Cursor = Cursors.Default;
return;
}
}
Notes:
1. You could, of course, display the TextBox for entering the name of the co-ordinate Points in a fixed position, or in a ToolStripMenu, or anywhere else you wished.
2. You could, if you wanted something "fancier," create a UserControl that displayed the co-ordinates clicked and any other data you wanted to; you could show it, and hide it, using the same techniques here, but you would have to manage transmitting the edited name to the Form for use with your database.