winforms – Windows窗体中BackgroundImage的位置

前端之家收集整理的这篇文章主要介绍了winforms – Windows窗体中BackgroundImage的位置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我将Windows窗体的BackgroundImage设置为200 x 200图像.表格是500 x 500.我希望图像锚定在表单的右下角.但是,我唯一可用的选项是BackgroundImageLayout属性 – 将此设置为“无”会导致图像锚定在左上角.我怎么能改变这个?

注意:我使用的是.NET 2.0

只需在OnPaintBackground()方法中绘制它.将图像添加到资源(我称之为BkgImage)并使表单代码如下所示:
public Form1() {
        InitializeComponent();
        backgroundImage = Properties.Resources.BkgImage;
        this.DoubleBuffered = true;
        this.SetStyle(ControlStyles.ResizeRedraw,true);
    }
    private Image backgroundImage;

    protected override void OnPaintBackground(PaintEventArgs e) {
        base.OnPaintBackground(e);
        var rc = new Rectangle(this.ClientSize.Width - backgroundImage.Width,this.ClientSize.Height - backgroundImage.Height,backgroundImage.Width,backgroundImage.Height);
        e.Graphics.DrawImage(backgroundImage,rc);
    }
原文链接:https://www.f2er.com/windows/372052.html

猜你在找的Windows相关文章