Home > Net >  With rounded corners for WInForm modify button shape, only the top left corner is rounded
With rounded corners for WInForm modify button shape, only the top left corner is rounded

Time:10-10

using System;
Using System. Collections. Generic;
Using System.Com ponentModel;
Using System. The Data;
Using System. Drawing;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;
Using System. Windows. Forms;
Using System. Drawing. Drawing2D;

The namespace WindowsFormsApplication6. Button. _03
{

Public partial class Form1: Form
{

Public _click ()
{
InitializeComponent ();
}
Private void button1_Click (object sender, EventArgs e)
{
}
Private void Form1_Load (object sender, EventArgs e)
{
}
Protected override void OnPaint (PaintEventArgs PE)
{
GraphicsPath path=new GraphicsPath ();
A Rectangle the rect=new Rectangle (0, 22, this Width, enclosing Height - 22).
Path=GetRoundedRectPath (the rect, 20);
Region reg=new Region (path);
This. For. Region=reg;
Base. The OnPaint (PE);
}
Private GraphicsPath GetRoundedRectPath (a Rectangle the rect, radius, int)
{
Int diameter=radius;
A Rectangle arcRect=new Rectangle (the rect. The Location, the new Size (diameter, diameter));
GraphicsPath path=new GraphicsPath ();
//the top left corner
Path. AddArc (arcRect, 180, 90);
//the top right corner
ArcRect. X=the rect. Right - diameter;
Path. AddArc (arcRect, 270, 90);
//at the bottom right
ArcRect. Y=the rect. Bottom - 0;
Path. AddArc (arcRect, 0, 90);
//left corner
ArcRect. X=the rect. Left;
Path. AddArc (arcRect, 90, 90);
Path. CloseFigure ();
Return path.
}
Private void SetWindowRegion (object sender, EventArgs e)
{
}
Private void OnPaint (object sender, EventArgs e)
{
}
}

}

CodePudding user response:

Clearly set enclosing. For the Region this is wrong,

CodePudding user response:

Every time when painting the rounded with a Rectangle arcRect? Position does not change?

CodePudding user response:


refer to the second floor MichaelGLX response:
every painting when rounded corners with a Rectangle arcRect? Position does not change?

Wrong, this how to delete ah!!

Is set work area is wrong, when you draw the rect width 1 to try? And set the work area to line that how click ah, you can fill up!

CodePudding user response:

 
using System;
Using System. Collections. Generic;
Using System.Com ponentModel;
Using System. The Data;
Using System. Drawing;
Using System. Drawing. Drawing2D;
Using System. Linq;
Using System. The Text;
Using System. Windows. Forms;

The namespace Gid_1
{
Public partial class Form1: Form
{
Public _click ()
{
InitializeComponent ();
}

Private void the Draw (a Rectangle Rectangle, Graphics g, int _radius, bool cusp, Color begin_color, Color end_color)
{
Int span=2;
//anti-aliasing
G.S moothingMode=SmoothingMode. AntiAlias;
//the gradient
LinearGradientBrush myLinearGradientBrush=new LinearGradientBrush (rectangle, begin_color, end_color, LinearGradientMode. Vertical);
//draw Angle
If (cusp)
{
Span=10;
PointF p1=new PointF (rectangle Width - 12, a rectangle, Y + 10);
PointF p2=new PointF (rectangle Width - 12, a rectangle, Y + 30);
PointF p3=new PointF (rectangle. Width, a rectangle, Y + 20);
PointF [] ptsArray={p1, p2, p3};
G.F illPolygon (myLinearGradientBrush ptsArray);
}
//fill in
G.F illPath (myLinearGradientBrush, DrawRoundRect (rectangle. X, a rectangle. The Y, a rectangle. The Width - span, a rectangle. The Height of 1, _radius));
}
Public static GraphicsPath DrawRoundRect (int x, int y, int width, int height, radius, int)
{
//edges rounded
GraphicsPath gp=new GraphicsPath ();
Gp. AddArc (x, y, the radius, the radius, 180, 90);
Gp. AddArc (width - the radius, y, the radius, the radius, 270, 90);
Gp. AddArc (width - the radius, height - the radius, the radius, the radius, 0, 90);
Gp. AddArc (x, height - the radius, the radius, the radius, 90, 90);
Gp. CloseAllFigures ();
Return gp;
}

Private void panel1_Paint (object sender, PaintEventArgs e)
{
The Draw (e.c. with our fabrication: lipRectangle, um participant raphics, 18, true, Color. FromArgb (90, 143, 0), Color, FromArgb (41, 67, 0));
Base. The OnPaint (e);
Graphics g=um participant raphics;
G.D rawString (" I was in fact a Panel, "the new Font (" Microsoft elegant black," 9, FontStyle. Regular), new SolidBrush (Color. White), new PointF (10, 10));
}

Private void panel2_Paint (object sender, PaintEventArgs e)
{
The Draw (e.c. with our fabrication: lipRectangle, um participant raphics, 18, false Color. FromArgb (113, 113, 113), Color, FromArgb (0, 0, 0));
Base. The OnPaint (e);
Graphics g=um participant raphics;
G.D rawString (" I was in fact a Panel, "the new Font (" Microsoft elegant black," 9, FontStyle. Regular), new SolidBrush (Color. White), new PointF (10, 10));
}

Private void button1_Paint (object sender, PaintEventArgs e)
{
The Draw (e.c. with our fabrication: lipRectangle, um participant raphics, 18, false Color. FromArgb (0, 122, 204), and Color. The FromArgb (8, 39, 57));
Base. The OnPaint (e);
Graphics g=um participant raphics;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related