[C#] 콘트롤 애니메이션 효과
페이지 정보
작성자 sbLAB 댓글 0건 조회 6,313회 작성일 18-07-25 18:00본문
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
comboBox1.Text = "서울";
Util.Animate(comboBox1, Util.Effect.Slide, 60, 180);
Util.Animate(comboBox1, Util.Effect.Slide, 60, 180);
comboBox2.Text = "전북";
Util.Animate(comboBox2, Util.Effect.Slide, 70, 180);
Util.Animate(comboBox2, Util.Effect.Slide, 70, 180);
comboBox3.Text = "울산";
Util.Animate(comboBox3, Util.Effect.Slide, 80, 180);
Util.Animate(comboBox3, Util.Effect.Slide, 80, 180);
}
}
public static class Util
{
public enum Effect { Roll, Slide, Center, Blend }
public static void Animate(Control ctl, Effect effect, int msec, int angle)
{
int flags = effmap[(int)effect];
if (ctl.Visible) { flags |= 0x10000; angle += 180; }
else
{
if (ctl.TopLevelControl == ctl) flags |= 0x20000;
else if (effect == Effect.Blend) throw new ArgumentException();
}
flags |= dirmap[(angle % 360) / 45];
bool ok = AnimateWindow(ctl.Handle, msec, flags);
if (!ok) throw new Exception("Animation failed");
ctl.Visible = !ctl.Visible;
}
private static int[] dirmap = { 1, 5, 4, 6, 2, 10, 8, 9 };
private static int[] effmap = { 0, 0x40000, 0x10, 0x80000 };
[DllImport("user32.dll")]
private static extern bool AnimateWindow(IntPtr handle, int msec, int flags);
}
}
댓글목록
등록된 댓글이 없습니다.