need to generate text box automatically when I click on the mouse point in image box (while after browsing image in the form.) for the .net form
I need generate text box while I click on the mouse point in image box. in this code only generate text box click on the form. it not generate text box for click on the image box.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
}
private void Form1_MouseDown(开发者_JAVA技巧object sender, MouseEventArgs e)
{
TextBox tb = new TextBox();
tb.Location = new Point(e.X, e.Y);
tb.Width = 100;
this.Controls.Add(tb);
}
}
public Form1() { InitializeComponent(); this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown); }
This code of yours adds the mousedown event on the form . If you want to have the mouse down event in the image box , Do this
1) Go to form designer 2) In the properties of image box, go to events and in mousedown choose the Form1_MouseDown event.
Hope this helps
精彩评论