鼠标悬停时改变图片框,鼠标离开时重置

Changing picture box on mouseover, and resetting on mouseleave

本文关键字:鼠标 离开 悬停 改变      更新时间:2023-10-16

我正在开发一个windows窗体程序,很难找到如何在c++中做到这一点。MSDN有这个页面,http://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.image,但与VB相比,c++文档是缺乏的。

这是我目前所知道的。这种方法应该避免常见的闪烁问题,但我不确定从那里去,因为我需要它回到鼠标离开后的原始图像。

void InitializeComponent(void)
    {   
this->btnExit->BackColor = System::Drawing::Color::Transparent;
        this->btnExit->BackgroundImageLayout = System::Windows::Forms::ImageLayout::None;
        this->btnExit->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"btnExit.Image")));
        this->btnExit->Location = System::Drawing::Point(764, 4);
        this->btnExit->Name = L"btnExit";
        this->btnExit->Size = System::Drawing::Size(30, 20);
        this->btnExit->TabIndex = 3;
        this->btnExit->TabStop = false;
        this->btnExit->Click += gcnew System::EventHandler(this, &mainForm::btnExit_Click);
}
#pragma endregion
private: System::Void btnExit_OnMouseEnter(System::Object^  sender, System::EventArgs^  e) {
            Image^ get ();
            void set (Image^ value);
         }

谢谢。

private: System::Void btnExit_MouseEnter(System::Object^  sender, System::EventArgs^  e) {
         btnExit->Image = Image::FromFile("C:\Users\...\image.png");
 }

工作,不确定这是不是正确的方法。