Search code examples
winformsvisual-studioeventsc++-climousewheel

mouse wheel event scroll c++ Visual Studio


I am making a program with windowForms and I want to use the mouse wheel to do some things, like changing image with the mouse wheel. I have been looking for some answers in the microsoft website but I couldn't understand it . Can anyone give me a example about mouse wheel event and what libraries I need to use.


Solution

  • this was the library that i need to use

    '#' using '<'System.dll'>'

    '#' using '<'System.Windows.Forms.dll'>'

    '#' using '<'System.Drawing.dll'>'

    public ref class mainWindow : public System::Windows::Forms::Form

    {

    public:

        mainWindow(void)
    
        {
    
             InitializeComponent();
    
           //
    
            //TODO: Add the constructor code here
    
           //
        }  
    

    //inside InitializeComponent() i wrote:

           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);
    

    code of each function

     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();
    
    }
    

    the code allows to scroll something without click it. the component that i want to scope was inside a panel object so i need to focus/select the panel object first.