加入程式畫面使用this.Controls.Add(box);
加入物件畫面使用this.pictureBox1.Controls.Add(box);
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
TextBox box = new TextBox();
//取得滑鼠位置
int x = ((MouseEventArgs)e).X;
int y = ((MouseEventArgs)e).Y;
//設定新物件位置
Point p = new Point(x, y);
box.Location = p;
//整個畫面加入物件
//this.Controls.Add(box);
//只有在圖片加入物件
//this.pictureBox1.Controls.Add(box);
//置頂物件
box.BringToFront();
}
}
}
參考資料:
http://support.microsoft.com/kb/319266
http://msdn.microsoft.com/zh-tw/library/wh9zw57z(v=vs.80).aspx


