簡體   English   中英

如何使Windows窗體適合任何屏幕分辨率,以及如何使我的圖像大小適合窗體

[英]How to fit windows form to any screen resolution and how to made my image size fit to form

我有以下代碼,其中我試圖顯示圖像並播放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();
        }
    }
}

當我運行此代碼時,表單高度超過了我的屏幕高度,並且我看不到完整的圖像。 圖片與表單不符。

有人可以幫忙嗎?

對圖片框使用錨點 ,也可以對SizeMode使用錨點

WindowState = FormWindowState.Maximized;

將上面的代碼寫在表單的load事件上。

我認為最好的情況是避免使用PictureBox,並在窗體的BackgroundImage中設置圖像,並將窗體BackgroundImageLayout設置為Stretch。

這樣,您可以更改表單的大小,圖像將自動拉伸。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM