■ 배경 이미지 움직이기
------------------------------------------------------------------------------------------------------------------------
▶ MainForm.cs
using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms;
namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary> /// 그라디언트 시작 /// </summary> private float gradientStart = 0;
/// <summary> /// 델타 /// </summary> private float delta = 5f;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent();
#region 이벤트를 설정한다.
this.canvasPictureBox.Paint += canvasPictureBox_Paint; this.timer.Tick += timer_Tick;
#endregion }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event
#region 캔버스 픽처 박스 페인트시 처리하기 - canvasPictureBox_Paint(sender, e)
/// <summary> /// 캔버스 픽처 박스 페인트시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void canvasPictureBox_Paint(object sender, PaintEventArgs e) { int width = this.canvasPictureBox.ClientSize.Width;
SetBackgroundImage(e.Graphics, this.gradientStart, this.gradientStart + width);
this.gradientStart += this.delta;
if(this.gradientStart >= width) { this.gradientStart = 0; }
using(Font font = new Font("Times New Roman", 32, FontStyle.Bold)) { using(StringFormat stringFormat = new StringFormat()) { stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center;
e.Graphics.DrawString ( "Moving Gradient", font, Brushes.Black, this.canvasPictureBox.ClientSize.Width / 2, this.canvasPictureBox.ClientSize.Height / 2, stringFormat ); } } }
#endregion #region 타이머 틱 처리하기 - timer_Tick(sender, e)
/// <summary> /// 타이머 틱 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void timer_Tick(object sender, EventArgs e) { this.canvasPictureBox.Refresh(); }
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 배경 이미지 설정하기 - SetBackgroundImage(graphics, minimumX, maximumX)
/// <summary> /// 배경 이미지 설정하기 /// </summary> /// <param name="graphics">그래픽스</param> /// <param name="minimumX">최소 X</param> /// <param name="maximumX">최대 X</param> private void SetBackgroundImage(Graphics graphics, float minimumX, float maximumX) { using(LinearGradientBrush brush = new LinearGradientBrush(new PointF(minimumX, 0), new PointF(maximumX, 0), Color.Red, Color.Red)) { brush.WrapMode = WrapMode.Tile;
ColorBlend colorBlend = new ColorBlend();
colorBlend.Colors = new Color[] { Color.Red, Color.White, Color.Red }; colorBlend.Positions = new float[] { 0, 0.5f, 1 };
brush.InterpolationColors = colorBlend;
graphics.FillRectangle(brush, this.canvasPictureBox.ClientRectangle); } }
#endregion } }
|
------------------------------------------------------------------------------------------------------------------------
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] 직선 방향의 텍스트 그리기 (0) | 2019.01.01 |
---|---|
[C#/WINFORM] 다각형과 직선 교차점 구하기 (0) | 2019.01.01 |
[C#/WINFORM] 다각형 확장하기 (0) | 2018.12.31 |
[C#/WINFORM] PathGradientBrush 클래스 : 브러시 회전시키기 (0) | 2018.12.31 |
[C#/WINFORM] 텍스트 색상 움직이기 (0) | 2018.12.31 |
[C#/WINFORM] 배경 이미지 움직이기 (0) | 2018.12.31 |
[C#/WINFORM] StringFormat 클래스 : FormatFlags 속성을 사용해 문자열 라인 클리핑 설정하기 (0) | 2018.12.31 |
[C#/WINFORM] StringFormat 클래스 : Trimming 속성을 사용해 문자열 잘라내는 방법(String Trimming) 설정하기 (0) | 2018.12.31 |
[C#/WINFORM] 마우스 아래 파이 슬라이스 구하기 (0) | 2018.12.30 |
[C#/WINFORM] 프린터 해상도 설정하기 (0) | 2018.12.30 |
[C#/WINFORM] 색상 휠 대화 상자 사용하기 (0) | 2018.12.30 |
댓글을 달아 주세요