回复 5楼Alice的帖子
我又做了一个demo,里边有RichTextBox和editor两种,都是用的contextMenuStrip,RichTextBox可以删除
而editor不能显示父窗体为null,。都是用一级菜单求得sourcecontrol。您再看看
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
// contextMenuStrip1.SourceControl 一直为 null
C1.Win.C1Editor.C1Editor c1editor = contextMenuStrip1.SourceControl as C1.Win.C1Editor.C1Editor;
DialogResult dr = MessageBox.Show("是否删除?", "删除", MessageBoxButtons.OKCancel);
if (dr == DialogResult.OK)
{
c1editor.Parent.Controls.Remove(c1editor);//删除TextBox控件
}
}
/// <summary>
/// 删除文本框
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void 删除ToolStripMenuItem1_Click(object sender, EventArgs e)
{
RichTextBox tb = contextMenuStrip2.SourceControl as RichTextBox;
DialogResult dr = MessageBox.Show("是否删除?", "删除", MessageBoxButtons.OKCancel);
if (dr == DialogResult.OK)
{
tb.Parent.Controls.Remove(tb);//删除TextBox控件
}
}
} |