當為雙擊時,卻插入不成功。因為雙擊時,Text值就變成了全選,SelectStat值就會變掉,所有沒有其它的方法可以在雙擊時插入值。如有,請高手指導。謝謝!
public partial class Form1 : Form
{
//定義右鍵
ContextMenu cmMenu = new ContextMenu();
public Form1()
{
InitializeComponent();
//增加右鍵菜單
cmMenu.MenuItems.Add("insert");
//右鍵菜單單擊事件
cmMenu.MenuItems[0].Click += new EventHandler(cmMenu_Click);
//在TextBoxt增加右鍵
txt.ContextMenu = cmMenu;
}
/// <summary>
/// 右鍵菜單單擊方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void cmMenu_Click(object sender, EventArgs e)
{
//得到光標當前位置
int iStart = txt.SelectionStart;
//插入值
txt.Text = txt.Text.Insert(iStart, "33");
}
}
{
//定義右鍵
ContextMenu cmMenu = new ContextMenu();
public Form1()
{
InitializeComponent();
//增加右鍵菜單
cmMenu.MenuItems.Add("insert");
//右鍵菜單單擊事件
cmMenu.MenuItems[0].Click += new EventHandler(cmMenu_Click);
//在TextBoxt增加右鍵
txt.ContextMenu = cmMenu;
}
/// <summary>
/// 右鍵菜單單擊方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void cmMenu_Click(object sender, EventArgs e)
{
//得到光標當前位置
int iStart = txt.SelectionStart;
//插入值
txt.Text = txt.Text.Insert(iStart, "33");
}
}