سلام
1- دو تایمر، دو دکمه و یک دیتاگرید بر روی فرم قرار بدین
2- خاصیت interval دو تایمر رو روی 50 بذارین
3 اسم یک تایمر رو TimerDown و اسم دیگری رو timerUp بذارین
سپس کدهای زیر رو تو رویداد MouseLeave و MouseEnter دکمه ها و رویداد tick تایمرها بنویسید :
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication15
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.dataGridView1.Rows.Add("");
this.dataGridView1.Rows.Add("");
this.dataGridView1.Rows.Add("");
this.dataGridView1.Rows.Add("");
this.dataGridView1.Rows.Add("");
this.dataGridView1.Rows.Add("");
this.dataGridView1.Rows.Add("");
this.dataGridView1.Rows.Add("");
this.dataGridView1.Rows.Add("");
this.dataGridView1.Rows.Add("");
this.dataGridView1.Rows.Add("");
this.dataGridView1.Rows.Add("");
this.dataGridView1.Rows.Add("");
this.dataGridView1.Rows.Add("");
this.dataGridView1.Rows.Add("");
this.dataGridView1.Rows.Add("");
}
private void button1_Click(object sender, EventArgs e)
{
this.dataGridView1.FirstDisplayedScrollingRowIndex = 7;
}
private void button1_MouseEnter(object sender, EventArgs e)
{
this.TimerDown.Start();
}
private void button1_MouseLeave(object sender, EventArgs e)
{
this.TimerDown.Stop();
}
private void button2_MouseMove(object sender, MouseEventArgs e)
{
System.Threading.Thread.Sleep(70);
}
private void button2_MouseEnter(object sender, EventArgs e)
{
this.timerUp.Start();
}
private void button2_MouseLeave(object sender, EventArgs e)
{
this.timerUp.Stop();
}
private void TimerDown_Tick(object sender, EventArgs e)
{
int currentValue = this.dataGridView1.FirstDisplayedScrollingRowIndex;
if (currentValue <= this.dataGridView1.Rows.Count)
{
this.dataGridView1.FirstDisplayedScrollingRowIndex = ++currentValue;
}
}
private void timerUp_Tick(object sender, EventArgs e)
{
int currentValue = this.dataGridView1.FirstDisplayedScrollingRowIndex;
if (currentValue > 0)
{
this.dataGridView1.FirstDisplayedScrollingRowIndex = --currentValue;
}
}
}
}