Presentation is loading. Please wait.

Presentation is loading. Please wait.

PictureBox, Timer, Resources. Resources An easy and effective way to add pictures (photos, graphics) to your programs Using Resources guarantees that.

Similar presentations


Presentation on theme: "PictureBox, Timer, Resources. Resources An easy and effective way to add pictures (photos, graphics) to your programs Using Resources guarantees that."— Presentation transcript:

1 PictureBox, Timer, Resources

2 Resources An easy and effective way to add pictures (photos, graphics) to your programs Using Resources guarantees that your pictures will stay with your application—they are embedded in the exe file. Resources can be used in PictureBoxes, or as the BackgroundImage for forms and other controls

3 Adding a Picture Resource – Prepare the picture file—reduce the file size if possible – Go to your project’s properties – Go to resources – Select Add Resource  Add Existing File – Browse Windows for the picture that you want to add – Give the resource a simple, appropriate name— this name will show up in your code

4 Referencing a Resource – A picture resource has a data type of Image – To use a resource in code, simply type My.Resources.[resourcename] wherever an Image variable can be used. – For example, the constructor for my Window class takes an Image parameter, so I can pass it my “stream” picture like this: New Window(New Point(3, 3), 1, My.Resources.stream) – For the Image or BackgroundImage of any control that has these properties, all of the picture resources in your project will appear when you click the “…” box in the properties window.

5 Drawing a Picture on a Graphics Object DrawImage has many overloads; Pick the overload that best meets your needs.

6 PictureBox Control You know from assignment 4 that PictureBoxes can be drawn on, using a Graphics object. PictureBox controls are also used to display picture files directly: – Bitmap (*.bmp) – JPEG (*.jpg) – GIF (*.gif)

7 PictureBox Properties The Image property tells the PictureBox what image to display. You can set the Image property at design time using the properties window—simply select the resource or file that you want to use. To set the Image property in code, use the Load procedure: PictureBox1.Load(“C:\MyPicture.jpg”)

8 SizeMode The SizeMode property determines how the picture fits into the PictureBox. It can take one of five values: – AutoSize: The PictureBox changes its size to match the picture. – Normal: Displays the picture at normal size in the upper- left corner of the PictureBox. If the picture is too big, it is clipped; if it is too small, white space appears around it. – CenterImage: Just like normal, except the picture is centered in the PictureBox. – Zoom: Provides the best fit for the picture in the PictureBox. The image will be enlarged or reduced to fit, but will not be distorted. – StretchImage: Forces the image to fit the PictureBox exactly, distorting it if necessary (changing its aspect ratio).

9

10

11 Timers Timers are event generators. At regular time intervals, a Tick event is generated. You can write code to handle the Tick event just like any other event.

12 Timer Properties Enabled: When True, the Timer Ticks. When False, it does nothing (no Tick events are generated). To turn a Timer off, set Enabled to False. Interval: The time in milliseconds between ticks. If you want a Timer to tick five times a second, set Interval to 200.

13


Download ppt "PictureBox, Timer, Resources. Resources An easy and effective way to add pictures (photos, graphics) to your programs Using Resources guarantees that."

Similar presentations


Ads by Google