C # windows form programming Series II

Source: Internet
Author: User

[Assembly: system. reflection. assemblyversion ("1.2")]
Namespace mynamespace
{
Using system;
Using system. drawing;
Using system. Windows. forms;

Public class myform: Form
{
Private button btnload;
Private picturebox pboxphoto;

Public myform ()
{
This. Text = "Wentao's C # form ";
// Set the form's minimum size
This. minimumsize = new size (200,200 );

// Create and initialize ate the button
Btnload = new button ();
Btnload. Text = "& Load ";
Btnload. Left = 10;
Btnload. Top = 10;
Btnload. Click + = new system. eventhandler (this. onloadclick );
Btnload. Anchor = anchorstyles. Top | anchorstyles. Left;

// Create and modify ate the picturebox
Pboxphoto = new picturebox ();
Pboxphoto. borderstyle = system. Windows. Forms. borderstyle. fixed3d;
Pboxphoto. width = This. width/2;
Pboxphoto. Height = This. Height/2;
Pboxphoto. Left = (this. Width-pboxphoto. width)/2;
Pboxphoto. Top = (this. Height-pboxphoto. Height)/2;
Pboxphoto. sizemode = pictureboxsizemode. stretchimage;
Pboxphoto. Dock = dockstyle. Fill;
// Support for picturebox resize operation
// Pboxphoto. Anchor = anchorstyles. Top | anchorstyles. Bottom
// | Anchorstyles. Left | anchorstyles. Right;

// Add our new controls to the form
This. Controls. Add (btnload );
This. Controls. Add (pboxphoto );
}

Private void onloadclick (Object sender, system. eventargs E)
{
Openfiledialog DLG = new openfiledialog ();

DLG. Title = "Open photo ";
DLG. Filter = "JPG files (*. jpg) | *. jpg | all files (*. *) | *.*";

If (DLG. showdialog () = dialogresult. OK)
{
Pboxphoto. Image = new Bitmap (DLG. openfile ());
}

DLG. Dispose ();
}

Public static void main ()
{
Application. Run (New myform ());
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.