C# 如何使windows窗体适合任何屏幕分辨率,以及如何使我的图像大小适合窗体

C# 如何使windows窗体适合任何屏幕分辨率,以及如何使我的图像大小适合窗体,c#,C#,我有下面的代码,在其中我试图显示一个图像和播放一首MP3歌曲 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Media; using WMPLib; u

我有下面的代码,在其中我试图显示一个图像和播放一首MP3歌曲

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;
using WMPLib;
using System.Windows;

namespace CreatingInstaller
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Size = Screen.PrimaryScreen.WorkingArea.Size;
            var size = this.Size;
            var screen = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
            PictureBox pb1 = new PictureBox();
            Image img = Image.FromFile(Application.StartupPath + "\\Input\\CYMERA_20141109_141742.jpg");
            //this.Width = img.Width;
            //this.Height = screen.Height;
            pb1.Image = img;
            //pb1.Width = img.Width;
            //pb1.Height = screen.Height; 
            pb1.Size = this.Size;
            this.Controls.Add(pb1);

            WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();

            wplayer.URL = Application.StartupPath + "\\Input\\Nee Sneham - [www.MazaMp3.com].mp3";
            wplayer.controls.play();
        }
    }
}
当我运行此代码时,表单高度超过屏幕高度,无法看到完整图像。图像与表单不匹配


有人能帮忙吗?

用于您的PictureBox,也可以。

WindowsState=FormWindowsState.Maximized


在窗体的加载事件中写入上述行。

我认为您最好避免使用PictureBox,在窗体的BackgroundImage中设置图像,并将窗体BackgroundImageLayout设置为Stretch

通过这种方式,您可以更改窗体的大小,图像将自动拉伸