C#重绘窗体

有没有好点的窗体代码?或好点的方法,谢谢... 有没有好点的窗体代码?
或好点的方法,谢谢
展开
 我来答
匿名用户
2013-06-19
展开全部
不知道你要哪一种重绘的代码,圆角矩形窗体的要吗?重绘后可托动窗体,能实现窗体的立体效果,这是整个重载Form的类,就发给你了吧。。 public partial class form : Form
{

public form()
{
InitializeComponent();
SetStyle(
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.ResizeRedraw |
ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.Transparent;
this.FormBorderStyle = FormBorderStyle.None;
}
Color baseColor= Color.FromArgb(51, 161, 224);
private Point mypoint; protected override void OnMouseDown(MouseEventArgs e) //可以手动托动
{
mypoint = new Point(-e.X, -e.Y);
base.OnMouseDown(e);
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point mypoint2 = Control.MousePosition;
mypoint2.Offset(mypoint);
this.DesktopLocation = mypoint2;
}
base.OnMouseMove(e);
}
protected override void OnPaint(PaintEventArgs e) //主要重绘在这里体现
{
Graphics g = e.Graphics;
Brush brush = Brushes.YellowGreen;
GraphicsPath path = CreatePath(new Rectangle(0, 0, 200, 200), 10);
this.Region = new Region(path);
g.DrawPath(new Pen(Brushes.YellowGreen), path); //以下这段用来实现窗体有立体感
LinearGradientBrush brus = new LinearGradientBrush(ClientRectangle, Color.Transparent, Color.Transparent, LinearGradientMode.Vertical);
Color[] colors = new Color[4];
colors[0] = GetColor(baseColor, 0, 35, 24, 9);
colors[1] = GetColor(baseColor, 0, 13, 8, 3);
colors[2] = baseColor;
colors[3] = GetColor(baseColor, 0, 68, 69, 54);
ColorBlend blend = new ColorBlend();
blend.Colors = colors;
blend.Positions = new float[] { 0.0f, 0.3f, 0.35f, 1.0f };
brus.InterpolationColors = blend;
g.FillPath(brus, path);

base.OnPaint(e);
}
private Color GetColor(Color colorBase, int a, int r, int g, int b)
{
int a0 = colorBase.A;
int r0 = colorBase.R;
int g0 = colorBase.G;
int b0 = colorBase.B; if (a + a0 > 255) { a = 255; } else { a = Math.Max(a + a0, 0); }
if (r + r0 > 255) { r = 255; } else { r = Math.Max(r + r0, 0); }
if (g + g0 > 255) { g = 255; } else { g = Math.Max(g + g0, 0); }
if (b + b0 > 255) { b = 255; } else { b = Math.Max(b + b0, 0); } return Color.FromArgb(a, r, g, b);
}
public static GraphicsPath CreatePath( //这里是创建一个圆角矩形窗体
Rectangle rect, int radius

)
{
GraphicsPath path = new GraphicsPath();
int radiusCorrection = 1;// correction ? 1 : 0; path.AddArc(rect.X, rect.Y, radius, radius, 180, 90);
path.AddArc(
rect.Right - radius - radiusCorrection,
rect.Y,
radius,
radius,
270,
90);
path.AddArc(
rect.Right - radius - radiusCorrection,
rect.Bottom - radius - radiusCorrection,
radius,
radius, 0, 90);
path.AddArc(
rect.X,
rect.Bottom - radius - radiusCorrection,
radius,
radius,
90,
90);
path.CloseFigure(); return path;
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式