[英]Position of BackgroundImage in Windows Form
I am setting the BackgroundImage
of a Windows Form to a 200 x 200 image. 我将Windows窗体的BackgroundImage
设置为200 x 200图像。 The Form is 500 x 500. I want the image to be anchored in the bottom right corner of the form. 表格是500 x 500.我希望图像锚定在表单的右下角。 However the only option available to me is the BackgroundImageLayout
property - setting this to 'None' results in the image being anchored to the top left. 然而,我唯一可用的选项是BackgroundImageLayout
属性 - 将此设置为“无”会导致图像锚定在左上角。 How can I change this? 我怎么能改变这个?
Note: I am using .NET 2.0 注意:我使用的是.NET 2.0
Just draw it yourself in the OnPaintBackground() method. 只需在OnPaintBackground()方法中绘制它。 Add the image to the resources (I called it BkgImage) and make the form code look like this: 将图像添加到资源(我称之为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);
}
You cannot do that with the BackgroundImageLayout. 你不能用BackgroundImageLayout做到这一点。
However what you could do is add a PictureBox, anchor it to the bottom right and set it to the lowest z-value. 但是,您可以做的是添加一个PictureBox,将其锚定到右下角并将其设置为最低的z值。 This would result in pretty much the requested effect. 这将导致几乎所需的效果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.