// SinglePictureApplication.cs Copyright (c) Kari Laitinen // http://www.naturalprogramming.com/ // 2008-02-24 File created. // 2022-12-20 Tested in Developer Command Prompt for VS 2022. // This program demonstrates how a C# GUI application can show pictures. // The picture files (e.g. .jpg or .png) files must be in the same // folder where the C# program (i.e. the .exe file) is located. // Class Bitmap, that is a subclass of Image, is used to handle image // information in this program. using System ; using System.Windows.Forms ; using System.Drawing ; class SinglePictureForm : Form { const int WINDOW_WIDTH = 820 ; const int WINDOW_HEIGHT = 435 ; Image picture_to_show ; public SinglePictureForm() { Text = "C# GUI APPLICATION SHOWING AN IMAGE" ; Size = new Size( WINDOW_WIDTH, WINDOW_HEIGHT ) ; picture_to_show = new Bitmap( "governor_arnold_schwarzenegger.jpg" ) ; } protected override void OnPaint( PaintEventArgs paint_data ) { Graphics graphics = paint_data.Graphics ; int picture_width = picture_to_show.Width ; int picture_height = picture_to_show.Height ; int picture_position_x = 15 ; int picture_position_y = 15 ; // The following statement shows the picture in its natural size. graphics.DrawImage( picture_to_show, picture_position_x, picture_position_y, picture_width, picture_height ) ; picture_position_x = picture_position_x + picture_width + 10 ; // Next we'll show a smaller version of the picture. graphics.DrawImage( picture_to_show, picture_position_x, picture_position_y, picture_width / 2, picture_height / 2 ) ; picture_position_x = picture_position_x + picture_width / 2 + 10 ; // The last statement shows the picture so that its width is enlarged. graphics.DrawImage( picture_to_show, picture_position_x, picture_position_y, (int) (picture_width * 1.5), picture_height ) ; } } public class SinglePictureApplication { static void Main() { Application.Run( new SinglePictureForm() ) ; } }