我需要让winforms gdi+应用程序全屏显示。
我用这段代码绘制所有的界面元素。
e.Graphics.DrawImage(MatheMage.Properties.Resources.ChooseMenu, 0, 300);我得到了类似于image1的东西
如果我使用这个代码
private void Form1_Load(object sender, EventArgs e)
{
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
}我得到了类似于image2的东西
我需要所有的元素沿着窗户伸展。
发布于 2018-12-01 03:22:51
在更改WindowState后,在表单加载方法中尝试执行此操作
this.BackgroundImageLayout = ImageLayout.Stretch;发布于 2018-12-05 23:18:01
由于您已经使用图形对象进行了绘制,因此只需使用ScaleTransform方法即可。
//save the current Transformation state of the graphics object.
var transState = e.Graphics.Save();
// Setting keepAspectRatio to false will scale your image to full screen.
// setting it to true will fill either the width or the height. you might need to use TranslateTransform method to move the image to the center.
bool keepAspectRatio = false;
// Calculate width and height ratios
// if you currently render everything to 640px/480px, you can take those dimensions instead of the Image size I used to calculate the ratios.
float widthRatio = this.DisplayRectangle.Width / MatheMage.Properties.Resources.ChooseMenu.Width;
float heightRatio = this.DisplayRectangle.Height / MatheMage.Properties.Resources.ChooseMenu.Height;
if(keepAspectratio)
{
// If aspect ratio shall be kept: choose the smaller scale for both dimensions
if(widthRatio > heightRatio)
{
widthRatio = heightRatio;
}
else
{
heightRatio = widthRatio;
}
}
// Scale the graphics object.
e.Graphics.ScaleTransform(widthRatio, heightRatio);
// Draw your stuff as before.
e.Graphics.DrawImage(MatheMage.Properties.Resources.ChooseMenu, 0, 300);
//finally restor the old transformation state of the graphics object.
e.Graphics.Restore(transState);希望这能让你振作起来。请注意,该代码未经过测试。
https://stackoverflow.com/questions/53563278
复制相似问题