Apr 11, 2012

How to Create a New Picture Box at Runtime in C

,


A picture box, in an application, is a container that can hold various types of images. One of the programming languages that can handle picture boxes is C. C also allows users to dynamically run code during the execution of the program, also known as during runtime. You can create a picture box in C during runtime by declaring the picture box and supplying its properties to the program.

Instructions

    • 1
      Open the source code of your C application in a text editor. For example, load it into Windows Notepad.
    • 2
      Insert the following code snippet into the source code to declare the picture box:
      Dim newPictureBox As New PictureBox
    • 3
      Enter the following code to specify the picture box's source file:
      newPictureBox.Image = Image.FromFile("C:\path\picture.jpg")
      Replace "path\picture.jpg" with the actual path and file name of the picture file.
    • 4
      Type or copy-and-paste the following code to specify the picture box's properties:
      newPictureBox.Visible = True
      newPictureBox.Top = X
      newPictureBox.Left = Y
      newPictureBox.Width = Z
      newPictureBox.Height = A
      Replace "X" and "Y" with the position you wish to assign to the picture box. "X" should be the number of pixels left between the top of the picture box and the top of the application, while "Y" is the number of pixels between the left edge of the interface and the left edge of the picture box. Replace "Z" and "A" with, respectively, the width and height, expressed in pixels, of the picture.
    • 5
      Enter the following code snippet to create the picture box:
      Controls.Add(newPictureBox)
    • 6
      Save your file and use your regular compiler to compile the program and test it.
 

HowToYo Copyright © 2011 | Template design by O Pregador | Powered by Blogger Templates