0% found this document useful (0 votes)
8 views3 pages

PictureBox and Date&Time Picker

The document provides an overview of the PictureBox and DateTimePicker controls in Windows Forms applications, detailing their properties, methods, and events. The PictureBox control displays images and supports various formats, while the DateTimePicker allows users to select dates and times. Examples of usage for both controls are included to illustrate their functionality.

Uploaded by

alieeyraza1601
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

PictureBox and Date&Time Picker

The document provides an overview of the PictureBox and DateTimePicker controls in Windows Forms applications, detailing their properties, methods, and events. The PictureBox control displays images and supports various formats, while the DateTimePicker allows users to select dates and times. Examples of usage for both controls are included to illustrate their functionality.

Uploaded by

alieeyraza1601
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

PictureBox Control

Introduction:

The PictureBox control is used to display images in a Windows Forms


application. It supports various image formats such as JPG, PNG, BMP, GIF,
and ICO. It is commonly used to display logos, profile pictures, or
dynamically loaded images.

Properties:

1. Image - Sets the image displayed in the PictureBox.

2. SizeMode - Determines how the image is displayed (Normal,


StretchImage, AutoSize, CenterImage, Zoom).

3. BorderStyle - Defines the border (None, FixedSingle, Fixed3D).

4. BackColor - Sets the background color.

5. Enabled - Enables or disables the control.

6. Visible - Controls visibility of the PictureBox.

Methods:

1. Load() - Loads an image from a file or URL.

o Example: pictureBox1.Load("C:\\image.jpg");

2. Refresh() - Redraws the PictureBox.

3. Dispose() - Releases resources.

Events:

1. Click - Triggers when clicked.

2. MouseHover - Occurs when the mouse hovers over the PictureBox.

WinForms Example 1: Load an Image from File


private void btnLoad_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Image Files|*.jpg;*.png;*.bmp";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image =
Image.FromFile(openFileDialog.FileName);
}
}

WinForms Example 2: Change Image on Button Click


private void btnChangeImage_Click(object sender, EventArgs e)
{
pictureBox1.Image = Image.FromFile("C:\\newImage.jpg");
}

7. DateTimePicker Control

Introduction:

The DateTimePicker control is used to select dates and times in a user-


friendly way. It allows users to pick a date from a dropdown calendar or enter
a time manually.

Properties:

1. Value - Gets or sets the selected date.

2. Format - Specifies the date format (Long, Short, Time, Custom).

3. CustomFormat - Defines a custom date format (e.g., "dd/MM/yyyy").

4. MinDate - Sets the minimum selectable date.

5. MaxDate - Sets the maximum selectable date.

6. ShowUpDown - Displays an up-down control instead of a dropdown


calendar.

Methods:

1. ResetText() - Resets the DateTimePicker to the default value.

2. Focus() - Sets focus on the control.


Events:

1. ValueChanged - Occurs when the selected date or time changes.

2. CloseUp - Fires when the calendar dropdown closes.

WinForms Example 1: Display Selected Date in Label


private void dateTimePicker1_ValueChanged(object sender,
EventArgs e)
{
label1.Text = "Selected Date: " +
dateTimePicker1.Value.ToShortDateString();
}

WinForms Example 2: Restrict Date Selection


private void Form1_Load(object sender, EventArgs e)
{
dateTimePicker1.MinDate = DateTime.Today;
dateTimePicker1.MaxDate = DateTime.Today.AddMonths(6);
}

You might also like