Assuming that the form called Main exists with a text. ![]() ![]() Double click on the button and replace all the text in the code window with the following: Begin Code Public Class Form1 Private pic As Bitmap Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click OpenFileDialog1.FileName = "Select File" OpenFileDialog1.ShowDialog() pic = New Bitmap(OpenFileDialog1.FileName) PictureBox1.BackgroundImage = pic End SubEnd Class End Code WHAT THE CODE DOES Public Class Form1 - Defines the form as Public Private pic As Bitmap - Defines pic As a private bitmap Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click - Defines When The Events Should Occur OpenFileDialog1.FileName = "Select File" - Makes the file name in the OpenFileDialog say Select File OpenFileDialog1.ShowDialog() - Shows the OpenFileDialog pic = New Bitmap(OpenFileDialog1.FileName) - Adds the value of the selected image to pic PictureBox1. The method call can be inserted in the applications initialization routine, or in a routine that is called upon a specific event. Visual Basic Example This code fragment shows that strng is loaded with the about text of the DLL.
0 Comments
Leave a Reply. |