首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在System.Graphics中使用winforms全屏? c#

如何在System.Graphics中使用winforms全屏? c#
EN

Stack Overflow用户
提问于 2018-12-01 02:52:47
回答 2查看 492关注 0票数 0

我需要让winforms gdi+应用程序全屏显示。

我用这段代码绘制所有的界面元素。

代码语言:javascript
复制
e.Graphics.DrawImage(MatheMage.Properties.Resources.ChooseMenu, 0, 300);

我得到了类似于image1的东西

如果我使用这个代码

代码语言:javascript
复制
private void Form1_Load(object sender, EventArgs e)
{
    this.TopMost = true;
    this.FormBorderStyle = FormBorderStyle.None;
    this.WindowState = FormWindowState.Maximized;
}

我得到了类似于image2的东西

我需要所有的元素沿着窗户伸展。

EN

回答 2

Stack Overflow用户

发布于 2018-12-01 03:22:51

在更改WindowState后,在表单加载方法中尝试执行此操作

代码语言:javascript
复制
this.BackgroundImageLayout = ImageLayout.Stretch;
票数 0
EN

Stack Overflow用户

发布于 2018-12-05 23:18:01

由于您已经使用图形对象进行了绘制,因此只需使用ScaleTransform方法即可。

代码语言:javascript
复制
//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);

希望这能让你振作起来。请注意,该代码未经过测试。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53563278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档