我有一个带有 RichTextBox 的用户控件和两个按钮。我试图在 ToolStripDropDown 上单击 ToolStripButton 来证明这一点。我正在使用 ToolStripControlHost 将我的控件放在 ToolStripDrowDown 上。当我在表单工具栏上单击 ToolStripButton 时,我会在某个位置显示下拉菜单并将焦点放在 ToolStripControlHost 控件上。鼠标指针停留在 ToolStripButton 上方,光标位于 RichTextBox。但是当我开始编辑 RichTextBox 时,鼠标指针消失了,只有当它超出矩形时我才能看到它。我该如何解决?
这是我的代码:
private void toolBtnNote_Click(object sender, EventArgs e)
{
dropDownClosed = false;
noteChanged = false;
tsdd = new ToolStripDropDown();
this.tsdd.Opened += new EventHandler(tsdd_Opened);
this.tsdd.AutoSize = true;
NoteEdit ne = new NoteEdit();
ne.NoteText = note ?? "";
// appears when user clicks first button at my control
ne.OkClick += new NoteEdit.NoteEditEvent(ne_OkClick);
// appears when user clicks second button at my control
ne.CancelClick += new NoteEdit.NoteEditEvent(ne_CancelClick);
this.tbh = new ToolStripControlHost(ne, "noteEdit");
this.tbh.Padding = new Padding(0);
this.tbh.AutoSize = false;
this.tbh.Size = ne.Size;
this.tsdd.Items.Add(tbh);
this.tsdd.Padding = new Padding(0);
this.tsdd.Closing += new ToolStripDropDownClosingEventHandler(tsdd_Closing);
// show toolstripdrowdown at specific position at DataGridView
this.tsdd.Show(dgvMarks, cellRect.Location + new Size(0, cellRect.Height));
while (!this.dropDownClosed)
{
Application.DoEvents();
}
if(noteChanged) {...}
}
void ne_CancelClick()
{
tsdd.Close();
}
void ne_OkClick()
{
noteChanged = true;
tsdd.Close();
}
void tsdd_Opened(object sender, EventArgs e)
{
tbh.Focus();
}
void tsdd_Closing(object sender, ToolStripDropDownClosingEventArgs e)
{
dropDownClosed = true;
}