Winforms 如何在第二和第三区域之间重新创建此阴影效果?
我需要复制此窗口的底部,以便以我自己的形式使用Winforms 如何在第二和第三区域之间重新创建此阴影效果?,winforms,Winforms,我需要复制此窗口的底部,以便以我自己的形式使用 您需要做的是覆盖现有控件的绘制或创建自己的控件。就我个人而言,我会覆盖面板控件的绘制,该控件将成为整个窗口底部的面板 渐变面板是一个常见的需求,并且有一篇博客文章(下面提供了代码) 显然,您不希望绘制完整的渐变,但它演示了如何在控件上绘制 您可以使用整个面板的较小子集绘制渐变,也可以使用类似的方法绘制渐变,并以正确的颜色绘制直线 博客帖子代码(避免死链接): 使用系统; 使用系统组件模型; 使用系统图; 使用System.Drawing.Draw
您需要做的是覆盖现有控件的绘制或创建自己的控件。就我个人而言,我会覆盖
面板
控件的绘制,该控件将成为整个窗口底部的面板
渐变面板是一个常见的需求,并且有一篇博客文章(下面提供了代码)
显然,您不希望绘制完整的渐变,但它演示了如何在控件上绘制
您可以使用整个面板的较小子集绘制渐变,也可以使用类似的方法绘制渐变,并以正确的颜色绘制直线
博客帖子代码(避免死链接):
使用系统;
使用系统组件模型;
使用系统图;
使用System.Drawing.Drawing2D;
使用System.Windows.Forms;
命名空间postsing.Controls
{
///
///GradientPanel与常规面板类似,只是它是可选的
///显示渐变。
///
[工具箱位图(面板类型))]
公共类渐变面板:面板
{
///
///属性渐变颜色(颜色)
///
私有颜色_渐变颜色;
公共颜色渐变颜色{
获取{返回此。_gradientColor;}
设置{this.\u gradientColor=value;}
}
///
///属性旋转(浮动)
///
私人浮动旋转;
公众浮标轮换{
获取{返回此。_rotation;}
设置{this._rotation=value;}
}
受保护的覆盖无效OnPaint(PaintEventArgs e){
if(e.ClipRectangle.IsEmpty)return;//如果不可见,为什么要绘制?
使用(LinearGradientBrush lgb=new
LinearGradientBrush(此.ClientRectangle,
这个,背景色,
这是GradientColor,
这是(轮换){
e、 Graphics.FillRectangle(lgb,this.ClientRectangle);
}
base.OnPaint(e);//对,希望处理过的任何东西也能绘制出来。
}
}
}
像Action Center那样操作,使用Paint事件。
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace PostXING.Controls
{
/// <summary>
/// GradientPanel is just like a regular panel except it optionally
/// shows a gradient.
/// </summary>
[ToolboxBitmap(typeof(Panel))]
public class GradientPanel : Panel
{
/// <summary>
/// Property GradientColor (Color)
/// </summary>
private Color _gradientColor;
public Color GradientColor {
get { return this._gradientColor;}
set { this._gradientColor = value;}
}
/// <summary>
/// Property Rotation (float)
/// </summary>
private float _rotation;
public float Rotation {
get { return this._rotation;}
set { this._rotation = value;}
}
protected override void OnPaint(PaintEventArgs e) {
if(e.ClipRectangle.IsEmpty) return; //why draw if non-visible?
using(LinearGradientBrush lgb = new
LinearGradientBrush(this.ClientRectangle,
this.BackColor,
this.GradientColor,
this.Rotation)){
e.Graphics.FillRectangle(lgb, this.ClientRectangle);
}
base.OnPaint (e); //right, want anything handled to be drawn too.
}
}
}