C#中鼠标滚轮的应用

namespace Mous
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            ((Control)this).MouseWheel += new MouseEventHandler(Form1_MouseWheel);

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
        void Form1_MouseWheel(object sender, MouseEventArgs e)
        {
            try
            {
                int i = Convert.ToInt32(textBox1.Text);
                if (textBox1.Bounds.Contains(e.Location)) //判断鼠标所在的地方是否在控件上
                {
                    if (e.Delta.ToString() == "120")
                    {
                        i++;
                        textBox1.Text = i.ToString();
                    }
                    else
                    {
                        i--;
                        textBox1.Text = i.ToString();
                    }
                }
            }
            catch { }
        }

    }
}

posted @ 2007-07-11 13:55  白虎  阅读(2476)  评论(0编辑  收藏  举报
非常感谢dudu,感谢博客园提供的各种服务。
联系白虎(David.Du)