在GroupBox内的禁用控件上显示工具提示

时间:2016-02-24 18:25:32

标签: winforms c++-cli

我正在使用以下代码在禁用的CheckBox上显示工具提示,该工具提示放在GroupBox中。 但是,当我将鼠标移到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;
    }
}

1 个答案:

答案 0 :(得分:0)

添加它(使用Form和GroupBox的相同回调)可以解决问题:

this->groupBox1->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &MyForm::MyForm_MouseMove);
相关问题