[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 ());
}
}
}