在 GroupBox 内的禁用控件上显示工具提示
Show Tooltip on disabled control inside a GroupBox
我正在使用以下代码在位于 GroupBox 内的禁用 CheckBox 上显示工具提示。
然而,当我将鼠标移到 CheckBox 上时,工具提示会显示 仅当我首先在 GroupBox 外部单击 ,然后将鼠标箭头拖到 CheckBox 上时。
这就像 GroupBox 覆盖了对话框的主面板并且它没有触发事件。
但是 GroupBox 没有 MouseMove 事件,所以我想知道如何解决这个问题。
delegate void SetToolTipDelegate(ToolTip^ tooltip, Control^ control, String^ text);
void SetToolTip(ToolTip^ tooltip, Control^ control, String^ text)
{
if (control->InvokeRequired)
{
SetToolTipDelegate^ d = gcnew SetToolTipDelegate(this, &MyForm::SetToolTip);
this->Invoke(d, gcnew cli::array<Object^> { tooltip, control, text });
}
else
{
tooltip->SetToolTip(control, text);
}
}
bool isShown;
System::Void MyForm_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
System::Drawing::Point p = this->checkBox1->Location;
System::Drawing::Point g = this->groupBox1->Location;
System::Drawing::Rectangle r = this->checkBox1->ClientRectangle;
if ((e->X >= (p.X + g.X)) && (e->X <= (p.X + g.X + r.Width)) && (e->Y >= (p.Y + g.Y)) && (e->Y <= (p.Y + g.Y + r.Height)))
{
if (!isShown) {
SetToolTip(this->toolTip1, this->checkBox1, "Here my tooltip text...");
this->toolTip1->Show("Here my tooltip text...", this->checkBox1, r.Width / 2, r.Height / 2);
isShown = TRUE;
}
}
else
{
this->toolTip1->Hide(this->checkBox1);
isShown = FALSE;
}
}
添加这个(对 Form 和 GroupBox 使用相同的回调)达到了目的:
this->groupBox1->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &MyForm::MyForm_MouseMove);
我正在使用以下代码在位于 GroupBox 内的禁用 CheckBox 上显示工具提示。 然而,当我将鼠标移到 CheckBox 上时,工具提示会显示 仅当我首先在 GroupBox 外部单击 ,然后将鼠标箭头拖到 CheckBox 上时。
这就像 GroupBox 覆盖了对话框的主面板并且它没有触发事件。
但是 GroupBox 没有 MouseMove 事件,所以我想知道如何解决这个问题。
delegate void SetToolTipDelegate(ToolTip^ tooltip, Control^ control, String^ text);
void SetToolTip(ToolTip^ tooltip, Control^ control, String^ text)
{
if (control->InvokeRequired)
{
SetToolTipDelegate^ d = gcnew SetToolTipDelegate(this, &MyForm::SetToolTip);
this->Invoke(d, gcnew cli::array<Object^> { tooltip, control, text });
}
else
{
tooltip->SetToolTip(control, text);
}
}
bool isShown;
System::Void MyForm_MouseMove(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
System::Drawing::Point p = this->checkBox1->Location;
System::Drawing::Point g = this->groupBox1->Location;
System::Drawing::Rectangle r = this->checkBox1->ClientRectangle;
if ((e->X >= (p.X + g.X)) && (e->X <= (p.X + g.X + r.Width)) && (e->Y >= (p.Y + g.Y)) && (e->Y <= (p.Y + g.Y + r.Height)))
{
if (!isShown) {
SetToolTip(this->toolTip1, this->checkBox1, "Here my tooltip text...");
this->toolTip1->Show("Here my tooltip text...", this->checkBox1, r.Width / 2, r.Height / 2);
isShown = TRUE;
}
}
else
{
this->toolTip1->Hide(this->checkBox1);
isShown = FALSE;
}
}
添加这个(对 Form 和 GroupBox 使用相同的回调)达到了目的:
this->groupBox1->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &MyForm::MyForm_MouseMove);