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
- 1Open the source code of your C application in a text editor. For example, load it into Windows Notepad.
- 2Insert the following code snippet into the source code to declare the picture box:Dim newPictureBox As New PictureBox
- 3Enter 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.
- 4Type 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 = AReplace "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. - 5Enter the following code snippet to create the picture box:Controls.Add(newPictureBox)
- 6Save your file and use your regular compiler to compile the program and test it.
- 1