728x90
반응형
728x170
▶ MainForm.cs
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
this.pictureBox.Resize += pictureBox_Resize;
this.pictureBox.Paint += pictureBox_Paint;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 픽처 박스 크기 변경시 처리하기 - pictureBox_Resize(sender, e)
/// <summary>
/// 픽처 박스 크기 변경시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void pictureBox_Resize(object sender, EventArgs e)
{
this.pictureBox.Refresh();
}
#endregion
#region 픽처 박스 페인트시 처리하기 - pictureBox_Paint(sender, e)
/// <summary>
/// 픽처 박스 페인트시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void pictureBox_Paint(object sender, PaintEventArgs e)
{
using(Font font = new Font("나눔고딕코딩", 40, FontStyle.Bold))
{
Color topBackgroundColor = Color.RoyalBlue;
Color topForegroundColor = Color.White;
Color bottomBackgroundColor = Color.White;
Color bottomForegroundColor = Color.RoyalBlue;
SolidBrush topBackgroundBrush = new SolidBrush(topBackgroundColor );
SolidBrush topForegroundBrush = new SolidBrush(topForegroundColor );
SolidBrush bottomBackgroundBrush = new SolidBrush(bottomBackgroundColor);
SolidBrush bottomForegroundBrush = new SolidBrush(bottomForegroundColor);
DrawSineSplitText
(
e.Graphics,
"싸인파 반전 텍스트",
font,
this.pictureBox.ClientRectangle,
topBackgroundBrush,
topForegroundBrush,
bottomBackgroundBrush,
bottomForegroundBrush,
2.5f,
0.25f
);
topBackgroundBrush.Dispose();
topForegroundBrush.Dispose();
bottomBackgroundBrush.Dispose();
bottomForegroundBrush.Dispose();
}
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 싸인파 분리 텍스트 그리기 - DrawSineSplitText(graphics, text, font, rectangle,
topBackgroundBrush, topForegroundBrush, bottomBackgroundBrush, bottomForegroundBrush, waveCount, scaleY)
/// <summary>
/// 싸인파 분리 텍스트 그리기
/// </summary>
/// <param name="graphics">그래픽스</param>
/// <param name="text">텍스트</param>
/// <param name="font">폰트</param>
/// <param name="rectangle">사각형</param>
/// <param name="topBackgroundBrush">상단 배경 브러시</param>
/// <param name="topForegroundBrush">상단 전경 브러시</param>
/// <param name="bottomBackgroundBrush">하단 배경 브러시</param>
/// <param name="bottomForegroundBrush">하단 전경 브러시</param>
/// <param name="waveCount">웨이브 수</param>
/// <param name="scaleY">Y 축적</param>
private void DrawSineSplitText
(
Graphics graphics,
string text,
Font font,
Rectangle rectangle,
Brush topBackgroundBrush,
Brush topForegroundBrush,
Brush bottomBackgroundBrush,
Brush bottomForegroundBrush,
float waveCount,
float scaleY
)
{
Bitmap topBitmap = new Bitmap(rectangle.Width, rectangle.Height);
Bitmap bottomBitmap = new Bitmap(rectangle.Width, rectangle.Height);
using(StringFormat stringFormat = new StringFormat())
{
stringFormat.Alignment = StringAlignment.Center;
stringFormat.LineAlignment = StringAlignment.Center;
using(Graphics topGraphics = Graphics.FromImage(topBitmap))
{
topGraphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
topGraphics.FillRectangle(topBackgroundBrush, rectangle);
topGraphics.DrawString(text, font, topForegroundBrush, rectangle, stringFormat);
}
using(Graphics bottomGraphics = Graphics.FromImage(bottomBitmap))
{
bottomGraphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
bottomGraphics.FillRectangle(bottomBackgroundBrush, rectangle);
bottomGraphics.DrawString(text, font, bottomForegroundBrush, rectangle, stringFormat);
}
}
using(TextureBrush brush = new TextureBrush(topBitmap))
{
graphics.FillRectangle(brush, rectangle);
}
List<PointF> pointList = new List<PointF>();
float magnitude = (font.Size * 96f / 72f) / 2 * scaleY;
float offsetY = rectangle.Height / 2f;
pointList.Add(new PointF(0, rectangle.Height));
float scaleX = (float)(waveCount * 2 * Math.PI / rectangle.Width);
for(int x = 0; x < rectangle.Width; x++)
{
float y = (float)(offsetY + magnitude * Math.Sin(x * scaleX));
pointList.Add(new PointF(x, y));
}
pointList.Add(new PointF(rectangle.Width - 1, rectangle.Height));
using(TextureBrush brush = new TextureBrush(bottomBitmap))
{
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.FillPolygon(brush, pointList.ToArray());
}
topBitmap.Dispose();
bottomBitmap.Dispose();
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WinForm' 카테고리의 다른 글
[C#/WINFORM] Bitmap 클래스 : 모노크롬 비트맵 구하기 (0) | 2020.07.23 |
---|---|
[C#/WINFORM] DataGridView 클래스 : CellDoubleClick 이벤트를 사용해 체크 박스 컬럼 입력하기 (0) | 2020.07.23 |
[C#/WINFORM] 이미지 리스트에서 이미지 드래그하기 (0) | 2020.07.22 |
[C#/WINFORM] 이미지 리스트 편집하기 (0) | 2020.07.22 |
[C#/WINFORM] PrivateFontCollection 클래스 : 커스텀 폰트 사용하기 (0) | 2020.07.22 |
[C#/WINFORM] 싸인파를 따라 반전된 색상으로 텍스트 그리기 (0) | 2020.07.21 |
[C#/WINFORM] 대각선을 따라 반전된 색상으로 텍스트 그리기 (0) | 2020.07.21 |
[C#/WINFORM] 위쪽 및 아래쪽 절반의 색상으로 반전된 텍스트 그리기 (0) | 2020.07.20 |
[C#/WINFORM] 개선된 투명 배경 이미지 구하기 (0) | 2020.07.20 |
[C#/WINFORM] 둥근 모서리 이미지 구하기 (0) | 2020.07.20 |
[C#/WINFORM] 워터마크 추가하기 (0) | 2020.07.19 |
댓글을 달아 주세요