Ãֽоð¾î¶ó´Â C#¿¡´Â RoundRect°¡ ¾ø½À´Ï´Ù.
¿Ö ¾ø´ÂÁö µµ¹«Áö ÀÌÇØ°¡ Àß ¾ÈµÇ´Âµ¥ ¾Æ¹«Æ° ¾ø½À´Ï´Ù.
±×·¡¼ ¸¸µé¾î ½á¾ß Çϴµ¥ ´ÙÇàÈ÷ °Ë»öÇØ º¸¸é ÀÌ¹Ì Àß ¸¸µé¾îÁø ÇÔ¼ö°¡ ÀÖÁö¿ä.
´ÙÀ½Àº ½ºÅà ¿À¹öÇ÷ο쿡¼ ãÀº°Çµ¥ ¿ø·¡ È®Àå ÇÔ¼ö·Î µÇ¾î ÀÖÁö¸¸ °£´ÜÇÑ Å×½ºÆ®¿ëÀ¸·Î ¾µ ¼ö ÀÖµµ·Ï ÀÏ¹Ý ÇÔ¼ö·Î ÇüŸ¦ ¾à°£ ¹Ù²Ù¾ú½À´Ï´Ù.
private void Form1_Paint(object sender, PaintEventArgs e)
{
FillRoundedRectangle(e.Graphics, new SolidBrush(Color.Yellow), new Rectangle(10, 10, 300, 200), 15);
DrawRoundedRectangle(e.Graphics, new Pen(Color.Red, 5), new Rectangle(10, 10, 300, 200), 15);
}
public GraphicsPath RoundedRect(Rectangle bounds, int radius)
{
int diameter = radius * 2;
Size size = new Size(diameter, diameter);
Rectangle arc = new Rectangle(bounds.Location, size);
GraphicsPath path = new GraphicsPath();
if (radius == 0)
{
path.AddRectangle(bounds);
return path;
}
// top left arc
path.AddArc(arc, 180, 90);
// top right arc
arc.X = bounds.Right - diameter;
path.AddArc(arc, 270, 90);
// bottom right arc
arc.Y = bounds.Bottom - diameter;
path.AddArc(arc, 0, 90);
// bottom left arc
arc.X = bounds.Left;
path.AddArc(arc, 90, 90);
path.CloseFigure();
return path;
}
public void DrawRoundedRectangle(Graphics graphics, Pen pen, Rectangle bounds, int cornerRadius)
{
if (graphics == null)
throw new ArgumentNullException("graphics");
if (pen == null)
throw new ArgumentNullException("pen");
using (GraphicsPath path = RoundedRect(bounds, cornerRadius))
{
graphics.DrawPath(pen, path);
}
}
public void FillRoundedRectangle(Graphics graphics, Brush brush, Rectangle bounds, int cornerRadius)
{
if (graphics == null)
throw new ArgumentNullException("graphics");
if (brush == null)
throw new ArgumentNullException("brush");
using (GraphicsPath path = RoundedRect(bounds, cornerRadius))
{
graphics.FillPath(brush, path);
}
}
¼¼ ¸Þ¼µå¸¦ ¾²°íÀÚ Çϴ Ŭ·¡½º¿¡ ºÙÀ̰í¿ä Paint À̺¥Æ®¿¡¼ È£Ã⸸ ÇÏ¸é µË´Ï´Ù.
¿Ü°û¼±¸¸ ±×¸± ¶§´Â Draw¸¦ È£ÃâÇÏ°í ³»ºÎ¸¦ ä¿ï ¶§´Â FillÀ» È£ÃâÇÕ´Ï´Ù.
µÑ ´Ù È£ÃâÇÒ ¶§´Â Fill ¸ÕÀú È£ÃâÇϰí Draw¸¦ È£ÃâÇÏ´Â °ÍÀÌ ÁÁ½À´Ï´Ù.
300, 200 Å©±â·Î ¸ð¼¸® ¹ÝÁö¸§ÀÌ 15ÀÎ µÕ±Ù »ç°¢ÇüÀ» ±×·È½À´Ï´Ù.

C#ÀÇ ÆÐ½º ±â´ÉÀÌ Àß ±¸ºñµÇ¾î ÀÖ¾î ÀÌ Á¤µµ´Â ¾ÆÁÖ ½±Áö¿ä.
Ãâ·Â ¸ð¾çµµ ±ò²ûÇÏ°Ô Àß ³ª¿É´Ï´Ù.
|
|