Page #119 (Chapter 28: Picture Boxes)

 

Placing a Bitmap Picture on the Picture Box

To place the cog train picture into the picture box, follow these steps:

  1. Highlight the PictureBox control to bring its properties into the Properties window.

  2. Scroll down to the Image entry in the left column and click on the Browse button (the button on the right with three dots) to open the Select Resource window.

    image from book
    Figure 28-2: Select Resource window

  3. Click on the Import button to display the Open window. Change the display to Visual Studio 2005\Projects\DemosSourceCode\Picture Box\bin\debug. This is where the CogTrain2.PNG graphic should be located.

    image from book
    Figure 28-3: Open window

  4. Highlight the CogTrain2.PNG file and click on the Open button to bring this graphic into the Select Resource window. The graphic also appears in the pictureBox1 control on the main window.

This completes the Picture Box project.

Picture Box (PB) Listing

 Form1.cs: PB002:        using System; PB003:        using System.Collections.Generic; PB004:        using System.ComponentModel; PB005:        using System.Data; PB006:        using System.Drawing; PB007:        using System.Windows.Forms; PB009:        namespace Picture_Box PB010:        { PB011:          partial class Form1 : Form PB012:          { PB013:            public Form1() PB014:            {InitializeComponent(); } //-----------------------------------------------------------------------------------------// PB020:            private void button1_Click(object sender, EventArgs e) PB021:            { // Quit. PB022:              Close(); PB023:            } PB024:          } PB025:        } //========================================================================================// Form1.Designer.cs: PB100:        namespace Picture_Box PB101:        { PB102:          partial class Form1 PB103:          {                   // Required designer variable. PB104:            private System.ComponentModel.IContainer components = null;                   // Clean up any resources being used. PB105:            protected override void Dispose(bool disposing) PB106:            { PB107:              if (disposing && (components != null)) components.Dispose(); PB108:              base.Dispose(disposing); PB109:            } PB110:            #region Windows Form Designer generated code                   // Required method for Designer support. PB111:            private void InitializeComponent() PB112:            { PB113:              this.pictureBox1 = new System.Windows.Forms.PictureBox(); PB114:              this.label1 = new System.Windows.Forms.Label(); PB115:              this.button1 = new System.Windows.Forms.Button(); PB116:              this.panel1 = new System.Windows.Forms.Panel();                     ((System.ComponentModel.ISupportInitialize)                       (this.pictureBox1)).BeginInit(); PB117:              this.SuspendLayout();                     //                     // pictureBox1                     // PB118:              this.pictureBox1.BorderStyle = System.Windows.Forms.                          BorderStyle.FixedSingle; PB119:              this.pictureBox1.Image = Picture_Box.Properties.Resources.CogTrain2; PB120:              this.pictureBox1.Location = new System.Drawing.Point(32, 56); PB121:              this.pictureBox1.Name = "pictureBox1"; PB122:              this.pictureBox1.Size = new System.Drawing.Size(525, 250); PB123:              this.pictureBox1.TabIndex = 0; PB124:              this.pictureBox1.TabStop = false;                     //                     // label1                     // PB125:              this.label1.AutoSize = true; PB126:              this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F,                       System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point,                       ((byte)(0))); PB127:              this.label1.Location = new System.Drawing.Point(140, 16); PB128:              this.label1.Name = "label1"; PB129:              this.label1.Size = new System.Drawing.Size(308, 24); PB130:              this.label1.TabIndex = 1; PB131:              this.label1.Text = "Cog Train at the Top of Pike\'s Peak";                     //                     // button1                     // PB132:              this.button1.Location = new System.Drawing.Point(16, 328); PB133:              this.button1.Name = "button1"; PB134:              this.button1.Size = new System.Drawing.Size(75, 25); PB135:              this.button1.TabIndex = 2; PB136:              this.button1.Text = "Quit"; PB137:              this.button1.Click += new System.EventHandler(this.button1_Click);                     //                     // panel1                     // PB138:              this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; PB139:              this.panel1.Location = new System.Drawing.Point(168, 295); PB140:              this.panel1.Name = "panel1"; PB141:              this.panel1.Size = new System.Drawing.Size(30, 20); PB142:              this.panel1.TabIndex = 3;                     //                     // Form1                     // PB143:              this.AutoScaleDimensions = new System.Drawing.SizeF(5F, 13F); PB144:              this.ClientSize = new System.Drawing.Size(584, 367); PB145:              this.Controls.Add(this.panel1); PB146:              this.Controls.Add(this.button1); PB147:              this.Controls.Add(this.label1); PB148:              this.Controls.Add(this.pictureBox1); PB149:              this.Name = "Form1"; PB150:              this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; PB151:              this.Text = "Picture Box";                     ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); PB152:              this.ResumeLayout(false); PB153:              this.PerformLayout(); PB154:            } PB155:            #endregion PB156:            private System.Windows.Forms.PictureBox pictureBox1; PB157:            private System.Windows.Forms.Label label1; PB158:            private System.Windows.Forms.Button button1; PB159:            private System.Windows.Forms.Panel panel1; PB160:          } PB161:        } 
 


Unlocking Microsoft C# V 2.0 Programming Secrets
Unlocking Microsoft C# V 2.0 Programming Secrets (Wordware Applications Library)
ISBN: 1556220979
EAN: 2147483647
Year: 2005
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net