Timer 사용
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 ExamSlidingMenu
{
public partial class Form1 : Form
{
//슬라이딩 메뉴의 최대, 최소 폭 크기
const int MAX_SLIDING_WIDTH = 200;
const int MIN_SLIDING_WIDTH = 50;
//슬라이딩 메뉴가 보이는/접히는 속도 조절
const int STEP_SLIDING = 10;
//최초 슬라이딩 메뉴 크기
int _posSliding = 200;
public Form1()
{
InitializeComponent();
}
private void checkBoxHide_CheckedChanged(object sender, EventArgs e)
{
if (checkBoxHide.Checked == true)
{
//슬라이딩 메뉴가 접혔을 때, 메뉴 버튼의 표시
button1.Text = "1";
button2.Text = "2";
checkBoxHide.Text = ">";
}
else
{
//슬라이딩 메뉴가 보였을 때, 메뉴 버튼의 표시
button1.Text = "버튼1";
button1.BackgroundImage = null;
button2.Text = "버튼2";
button2.BackgroundImage = null;
checkBoxHide.Text = "<";
}
//타이머 시작
timerSliding.Start();
}
private void timerSliding_Tick(object sender, EventArgs e)
{
if (checkBoxHide.Checked == true)
{
//슬라이딩 메뉴를 숨기는 동작
_posSliding -= STEP_SLIDING;
if (_posSliding <= MIN_SLIDING_WIDTH)
timerSliding.Stop();
}
else
{
//슬라이딩 메뉴를 보이는 동작
_posSliding += STEP_SLIDING;
if (_posSliding >= MAX_SLIDING_WIDTH)
timerSliding.Stop();
}
panelSideMenu.Width = _posSliding;
}
}
}
Main
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ExamSlidingMenu
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
'C# > C# WinForm' 카테고리의 다른 글
WinForm : ListView (0) | 2022.12.28 |
---|---|
WinForm : Oop (0) | 2022.12.27 |
WinForm : CheckBox (0) | 2022.12.26 |
WinForm : 새로 Form 띄우기 (0) | 2022.12.23 |
WinForm : Button, label (0) | 2022.12.22 |