0 امتیاز
چطوری امکان داره به جای استفاده از اسکرول بار بتونم سطر های بالایی و پایینی دیتاگرید رو مشاهده کنم

در واقع دو تا دکمه دارم می خوام با بردن ماوس روی دکمه (دکمه به سمت بالا) سطرها همانند اینکه با اسکرول بار در حرکتند به حرکت دراید و با دکمه (دکمه به سمت پایین) به سمت پایین حرکت کنند

و دوم اینکه هر موقع ماوس از روی دکمه بیرون رفت سطر های در حال نمایش در همان موقعیت بماند و بالا پایین نشود

برای برچسب هم از ویرگول استفاده می کنم قبول نمیکنه و بایداین  ,  رو گذاشت
بسته شده

1 پاسخ

0 امتیاز
 
بهترین پاسخ

سلام

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;
            }
        }

    }
}

 

توسط (6,145 امتیاز) 5 11 116
سوال جدید

2,337 سوال

2,871 پاسخ

3,725 دیدگاه

3,926 کاربر

دسته بندی ها

...