NEWS

[C#] Hiệu ứng hiển thị menu slide trong winform

[C#] Hiệu ứng hiển thị menu slide trong winform
Đăng bởi: Thảo Meo - Lượt xem: 3683 19:10:12, 02/09/2021EBOOK

Xin chào các bạn, bài viết hôm nay mình sẽ tiếp tục chia sẻ đến các bạn hiệu ứng hiển thị menu trên C#, Winform

[C#] Slide menu effect show hide Winform

Giao diện demo ứng dụng:

animation_menu_effect

Đây là bài viết đơn giản, các bạn chỉ cần sử dụng Timer để cho thay đổi vị trí left trên location của từng menu là xong.

Các bạn thiết kế form như hình dưới đây:

menu_animation

Full source code menu slide effect c#:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace animation_menu
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        bool isShow = false;
        #region "animation"
        private void timer1_Tick(object sender, EventArgs e)
        {
           
            panel1.Left -= 7;
            label1.Left -= 7;
            if (panel1.Left <= 300)
            {
                timer2.Start();
            }
            if (panel2.Left <= 300)
            {
                timer3.Start();
            }
            if (panel3.Left <= 300)
            {
                timer4.Start();
            }
            if (panel1.Left <= 22)
            {
                timer1.Stop();
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            panel2.Left -= 7;
            label2.Left -= 7;
            if (panel2.Left <= 22)
            {
                timer2.Stop();
            }    

        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            panel3.Left -= 7;
            label3.Left -= 7;
            if (panel3.Left <= 22)
            {
                timer3.Stop();
            } 
 
        }
 

        private void timer4_Tick(object sender, EventArgs e)
        {
            panel4.Left -= 7;
            label4.Left -= 7;
            if (panel4.Left <= 22)
            {
                timer4.Stop(); 
                isShow = true;
            }  
        }

        private void Form1_Load(object sender, EventArgs e)
        {
          
        }

        

        private void timer5_Tick(object sender, EventArgs e)
        {
            panel1.Left += 7;
            label1.Left += 7;
            if (panel1.Left >= 62)
            {
                timer6.Start();
            }

            if (panel2.Left >= 62)
            {
                timer7.Start();
            }
            if (panel3.Left >= 62)
            {
                timer8.Start();
            }
            if (panel1.Left >= 344)
            {
                timer5.Stop();
            }
        }

        private void timer6_Tick(object sender, EventArgs e)
        {
            panel2.Left += 7;
            label2.Left += 7;
            if (panel2.Left >= 344)
            {
                timer6.Stop();
                isShow = false;
            }  
        }

        private void timer7_Tick(object sender, EventArgs e)
        {
            panel3.Left += 7;
            label3.Left += 7;
            if (panel3.Left >= 344)
            {
                timer7.Stop();
            }  
        }

        private void timer8_Tick(object sender, EventArgs e)
        {
            panel4.Left += 7;
            label4.Left += 7;
            if (panel4.Left >= 344)
            {
                timer8.Stop();              
            }  
        }

        #endregion

    

        private void label6_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        private void panel6_Click(object sender, EventArgs e)
        {
            if (!isShow)
            {
                timer1.Start();
            }
            else
            {
                timer5.Start();
            }
        }

     
    }
}

Thanks for watching!

DOWNLOAD SOURCE

Tags: menu slide effect c#menu effect winform

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

[C#] Hiệu ứng hiển thị menu slide trong winform
Đăng bởi: Thảo Meo - Lượt xem: 3683 19:10:12, 02/09/2021EBOOK