加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

winforms – Windows窗体中BackgroundImage的位置

发布时间:2020-12-13 20:40:10 所属栏目:Windows 来源:网络整理
导读:我将Windows窗体的BackgroundImage设置为200 x 200图像.表格是500 x 500.我希望图像锚定在表单的右下角.但是,我唯一可用的选项是BackgroundImageLayout属性 – 将此设置为“无”会导致图像锚定在左上角.我怎么能改变这个? 注意:我使用的是.NET 2.0 只需在O
我将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);
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读