How to get window size in a WinForms application using C#

1 Answer

0 votes
namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int width = this.Width;  // Get the window width
            int height = this.Height; // Get the window height

            MessageBox.Show($"Window Size: {width} x {height}", "Window Size");
        }
    }
}



/*
run:
 
Window Size: 816 x 489
 
*/

 



answered Apr 2 by avibootz
...