使用鼠标滚轮事件改变鼠标大小

3
如果我的一个按钮被选中并且鼠标滚轮被激活,则其大小应根据鼠标滚轮动作而改变。 如果鼠标滚轮向上滚动,我的按钮的大小应增加2个单位。 如果鼠标滚轮向下滚动,我的按钮的大小应减小2个单位。
我正在尝试以下内容:
 private void Form1_Load(object sender, EventArgs e)
    {
        foreach (Control c in this.Controls)
        {
            btn = c as Button;
            {
                if (btn == null)
                    continue;

               c.MouseWheel += c_MouseWheel;


            }
        }
    }
    private void c_MouseWheel(object sender, MouseEventArgs e)
    {
        TabControl tabControl = sender as TabControl;
        if (tabControl != null)
        {
            if (e.Delta < 0)
            {

                tabControl.Size = new Size(-2, -2);
            }
            else
            {

                tabControl.Size = new Size(+2, +2);
            }

很抱歉,我的代码无法正常工作。
1个回答

1
这个问题现在已经解决:

    private void Form1_Load(object sender, EventArgs e)
    {
        foreach (Control c in this.Controls)
        {
            btn = c as Button;
            {
                if (btn == null)
                    continue;

               c.MouseWheel += c_MouseWheel;


            }
        }
    }
    private void c_MouseWheel(object sender, MouseEventArgs e)
    {
        ss = sender as Button;
        TabControl tabControl = sender as TabControl;
        int y = ss.Size.Width;
        int x = ss.Size.Height;

            if (e.Delta < 0)
            {

                ss.Size = new Size(y+2, x+2);
            }
            else
            {

                ss.Size = new Size(y-2, x-2);
            }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接