2 Replies - 295 Views - Last Post: 06 November 2019 - 01:47 PM Rate Topic: -----

#1 Somalia   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-January 18

Control Panel opacity with mousewheel

Posted 06 November 2019 - 10:47 AM

Mousewheel up/down should change the opacity of a panel on a form.
Currently the mousewheel has no effect. I try to control opacity like this.
Are there things I missed in the code or something I do wrong in the Design view?
I dragged a "panel1" with blue color back color in Design view onto the Form window and dragged a "timer1" onto "panel1".
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    namespace test1
    {
        public partial class Form1 : Form
        {
            Timer myTimer = new Timer();
            int mdelta = 0;
    
            public Form1()
            {
                InitializeComponent();
                myTimer.Interval = 100;
                myTimer.Tick += Timer1_Tick;
                this.panel1.MouseWheel += OwnMWheel;
            }
    
            private void OwnMWheel(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                myTimer.Stop();
                mdelta = e.Delta / 12;
                myTimer.Start();
            }
    
            private void Timer1_Tick(object sender, EventArgs e)
            {
                int alpha = this.panel1.BackColor.A + mdelta;
    
                if (alpha > -1 && alpha < 255)
                {
                    this.panel1.BackColor = Color.FromArgb(alpha, this.panel1.BackColor);
                    this.panel1.Invalidate();
                }
            }
        }
    }


Is This A Good Question/Topic? 0
  • +

Replies To: Control Panel opacity with mousewheel

#2 Somalia   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-January 18

Re: Control Panel opacity with mousewheel

Posted 06 November 2019 - 11:45 AM

Sorry, there is wrong information in my start post - you don't need to add an extra timer object in design view.
I defined it in the code already. That didn't cause the problem though.

Was This Post Helpful? 0
  • +
  • -

#3 Somalia   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 21-January 18

Re: Control Panel opacity with mousewheel

Posted 06 November 2019 - 01:47 PM

OK. I solved that problem now. It was really just a focus issue.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1