日期:2014-05-18  浏览次数:20820 次

C#窗体,能实现从右到左投影的阴影效果吗?
API实现窗体阴影是从左上投影的,我想实现一个从右(上)投影的阴影效果。主要是想做个侧边栏程序,停靠在右侧,在窗体左边出现一个阴影,不知能否实现?

------解决方案--------------------
用图片来模拟比较直观...
------解决方案--------------------
API实现的时候没有提供方向么?
------解决方案--------------------
用png图片吧...
------解决方案--------------------
C# code

protected override void OnPaintBackground(PaintEventArgs pevent)//OnPaintBackground是我测试的,具体你用时可能就不是pevent,可能是 g,那就直接用 g.FillRectangle
{
    base.OnPaintBackground(pevent);//我测试时是用重载PictrueBox,这个是填充原本的背景。

    if (this.Image != null)
    {
        GraphicsUnit gUnit = GraphicsUnit.Pixel;
        RectangleF rect = this.Image.GetBounds(ref gUnit);//获取图片的矩形大小,
        pevent.Graphics.FillRectangle(Brushes.Red, rect.Left - 2, rect.Top + 2, rect.Width, rect.Height);//Brushes.Red是我测试时用红色来显示。
    }
}

------解决方案--------------------
mark