我正在使用windowForms创建一个程序,我想用鼠标滚轮做一些事情,比如用鼠标滚轮改变图像。我一直在寻找微软网站的答案,但我无法理解。谁能给我一个关于鼠标滚轮事件和我需要使用的库的例子。
答案 0 :(得分:0)
这是我需要使用的库
'#'使用'    ' ''
'#'使用'<&#;; System.Windows.Forms.dll'>'
'#'使用'<&#;; System.Drawing.dll'>'
public ref class mainWindow:public System :: Windows :: Forms :: Form
{
公共:
mainWindow(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
//在InitializeComponent()里面我写道:
this->panel_album_info->MouseEnter += gcnew System::EventHandler(this,&mainWindow::panel_album_info_MouseEnter);
this->panel_album_info->MouseWheel += gcnew System::Windows::Forms::MouseEventHandler(this, &mainWindow::panel_album_info_Mouse_Wheel);
每个函数的代码
private: System::Void panel_album_info_Mouse_Wheel(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e) {
//if (tenho_o_rato_no_panel_do_album_info == true)
//{
int movimento = e->Delta;
label1->Text = "teste";
if (movimento == 120)
numero_de_deslocações_do_album += 1;
else if (movimento == -120)
numero_de_deslocações_do_album -= 1;
label1->Text = numero_de_deslocações_do_album.ToString();
//}
//else
//return;
}
private: System::Void panel_album_info_MouseEnter(System::Object^ sender, System::EventArgs^ e) {
this->panel_album_info->Select(); //este tambem da mas nao sei qual é a diferença
//this->panel_album_info->Focus();
}
代码允许滚动内容而不点击它。我想要范围的组件在面板对象内,所以我需要首先聚焦/选择面板对象。