通过panel叠加实现
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace LinPhoneTest { public partial class Form1 : Form { int firstY = 0; public Form1() { InitializeComponent(); this.panel1.MouseWheel += new MouseEventHandler(this.Panel_MouseWheel); firstY = panel2.Location.Y; } private void Form1_Load(object sender, EventArgs e) { panel2.Height = 3000; } private void Panel_MouseWheel(object sender, MouseEventArgs e) { label1.Text = "TOP:"+panel2.Top.ToString()+" W:" + e.Delta; if (panel2.Top + panel2.Height + e.Delta < panel1.Height) { panel2.Top = panel1.Height - panel2.Height; return; } if (panel2.Top+e.Delta > firstY) { panel2.Top = firstY ; return; } panel2.Top += e.Delta; } private void panel1_MouseEnter(object sender, EventArgs e) { this.panel1.Focus(); } private void panel2_MouseEnter(object sender, EventArgs e) { this.panel1.Focus(); } } }
文章评论