Home

Windows Controls: The Picture Box

 
 

Description

As we have seen regularly in this and as you will see in other lessons, you can display a picture directly on a form. Still, to give you a more comfortable space to show a picture, the .NET Framework provides a Windows control named PicturePox.

 

Getting a Picture Box

Like most controls, to get a picture box, from the Toolbox, you can click the PictureBox PictureBox button and click the form.

To programmatically get the control, you can create a handle to the PictureBox class. Before using the control, make sure you add it to the list of Controls of the form that will host it. Here is an example:

Imports System.Drawing
Imports System.Windows.Forms

Module Exercise

    Public Class Starter
        Inherits Form

        Private pctBox As PictureBox

        Dim components As System.ComponentModel.Container

        Public Sub New()
            InitializeComponent()
        End Sub

        Public Sub InitializeComponent()
            pctBox = New PictureBox()
            Controls.Add(pctBox)
        End Sub

    End Class

    Function Main() As Integer

        Dim frmStart As Starter = New Starter

        Application.Run(frmStart)

        Return 0
    End Function

End Module
 

Home Copyright © 2008-2016, FunctionX, Inc. Next