Rabu, 04 Februari 2009

Create a Windows Application
1. Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
2. On the File menu, point to New, and then click Project.
3. Under Project Types, click Visual Basic Projects.

Note In Visual Studio 2005, click Visual Basic under Project Types.
4. Under Templates, click Windows Application.
5. In the Name text box, type ImageDemo, and then click OK.

Form1.vb is created.

Back to the top

Replace the Existing Constructor of Your Form
By default, the existing constructor of Form1 does not accept any parameters. To pass a list of images and their descriptions to the constructor of Form1, modify the default constructor. To do this, follow these steps: 1. On the View menu, click Code.
2. In the Form1.vb file, locate the following code in the Windows Form Designer generated code region:Public Sub New()
MyBase.New()

'The Windows Form Designer requires this call.
InitializeComponent()

'Add any initialization after the InitializeComponent() call.

End Sub

3. Replace the code that you located in step 2 with the following code: ' Declare the constructor of Form1 to accept the passed command-line arguments.
Public Sub New(ByVal CmdArgs() As String)
MyBase.New()

'The Windows Form Designer requires this call.
InitializeComponent()

'Add any initialization after the InitializeComponent() call.
Me.WindowState = FormWindowState.Maximized

' Call the method that opens and then displays your images.
OpenAndDisplayImages(CmdArgs)
End Sub


Back to the top

Add a New Module to Your Project
To pass a list of images and their descriptions to the constructor of Form1, add a new module to your project and then create a new Form1 object in the Main method of your new module. The Main method accepts command-line arguments. To do this, follow these steps: 1. On the Project menu, click Add Module.
2. In the Add New Item - ImageDemo dialog box, click Open.

By default, Module1.vb is created.
3. In the Module1.vb file, locate the following statement:Module Module1

4. Add the following code after the code that you located in step 3:' Declare a Main method that accepts your list of images and their descriptions
' as command-line arguments.
Public Sub Main(ByVal CmdArgs() As String)
' Create a Form1 object by passing the received command-line arguments
' to the constructor of Form1 and then display the new Form1 object.
Application.Run(New Form1(CmdArgs))
End Sub


Back to the top

Change the Startup Object of Your Project
Your project is currently configured to use Form1 as the Startup object. To pass command-line arguments to your project, modify the Startup object for your project to Module1. To do this, follow these steps: 1. On the Project menu, click ImageDemo Properties.
2. In the ImageDemo Property Pages dialog box, click to select Module1 from the Startup object combo box, and then click OK.

Back to the top

Add Code to Open and Then to Display Images
To open and then to display the list of images that are passed to the constructor of your Form1 object, follow these steps: 1. In Form1.vb, locate the following code:End Class

2. Add the following code before the code that you located in step 1:' Declare a method to control the programming logic that you must have
' to open and then to display all your images.
Private Sub OpenAndDisplayImages(ByVal CmdArgs() As String)
' Variable to iterate through your list of images.
Dim Count As Integer
Try
' Temporarily suspend the layout logic for your Form1 object.
Me.SuspendLayout()
' Iterate through your list of images.
For Count = 0 To (CmdArgs.Length - 1) Step 2
' Call the method that opens and then displays the image that corresponds to
' the image file name that is indexed by the current value of Count.
OpenAndDisplay(CmdArgs(Count), Count)
Next
Me.ResumeLayout(False)
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub

' Declare a method to open and then to display the image that ImageFileName specifies.
Private Sub OpenAndDisplay(ByVal ImageFileName As String, ByVal Count As Integer)
' Declare a variable to hold a reference to your image.
Dim ImageStream As System.IO.FileStream
Try
' Open your image for Read access as a new FileStream.
ImageStream = New System.IO.FileStream(ImageFileName, _
System.IO.FileMode.Open, System.IO.FileAccess.Read)
' Declare a variable to hold a reference to your PictureBox.
Dim MyPictureBox As New PictureBox
' Set the image for the PictureBox to reduce or to expand
' to fit the size of the PictureBox.
MyPictureBox.SizeMode = PictureBoxSizeMode.StretchImage
' Set the location of the PictureBox based on the value of Count.
MyPictureBox.Location = New System.Drawing.Point(Count * 64, 0)
' Set the size of the PictureBox.
MyPictureBox.Size = New System.Drawing.Size(128, 128)
' Set the BorderStyle of the PictureBox.
MyPictureBox.BorderStyle = BorderStyle.Fixed3D
' Set the image of the PictureBox from the opened FileStream.
MyPictureBox.Image = System.Drawing.Image.FromStream(ImageStream)
' Add the PictureBox to your Form1 object.
Me.Controls.Add(MyPictureBox)
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub


Back to the top

Complete Code Listing
Module1.vb
Option Strict On

Module Module1

' Declare a Main method that accepts your list of images and their descriptions,
' as command-line arguments.
Public Sub Main(ByVal CmdArgs() As String)
' Create a Form1 object by passing the received command-line arguments
' to the constructor of Form1, and then display the new Form1 object.
Application.Run(New Form1(CmdArgs))
End Sub

End Module
Form1.vb
Option Strict On

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

' Declare the constructor of Form1 to accept the passed command-line arguments.
Public Sub New(ByVal CmdArgs() As String)
MyBase.New()

'The Windows Form Designer requires this call.
InitializeComponent()

'Add any initialization after the InitializeComponent() call.
Me.WindowState = FormWindowState.Maximized

' Call the method that opens and then displays your images.
OpenAndDisplayImages(CmdArgs)
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer.
Private components As System.ComponentModel.IContainer

'NOTE: The Windows Form Designer requires the following procedure.
'It can be modified by using the Windows Form Designer.
'Do not modify the procedure by using the Code editor.
Private Sub InitializeComponent()
components = New System.ComponentModel.Container
Me.Text = "Form1"
End Sub

#End Region

' Declare a method to control the programming logic that you must have
' to open and then to display all your images.
Private Sub OpenAndDisplayImages(ByVal CmdArgs() As String)
' Variable to iterate through your list of images.
Dim Count As Integer
Try
' Temporarily suspend the layout logic for your Form1 object.
Me.SuspendLayout()
' Iterate through your list of images.
For Count = 0 To (CmdArgs.Length - 1) Step 2
' Call the method that opens and then displays the image that corresponds to
' the image file name that is indexed by the current value of Count.
OpenAndDisplay(CmdArgs(Count), Count)
Next
Me.ResumeLayout(False)
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub

' Declare a method to open and then to display the image that ImageFileName specifies.
Private Sub OpenAndDisplay(ByVal ImageFileName As String, ByVal Count As Integer)
' Declare a variable to hold a reference to your image.
Dim ImageStream As System.IO.FileStream
Try
' Open your image for Read access as a new FileStream.
ImageStream = New System.IO.FileStream(ImageFileName, _
System.IO.FileMode.Open, System.IO.FileAccess.Read)
' Declare a variable to hold a reference to your PictureBox.
Dim MyPictureBox As New PictureBox
' Set the image for the PictureBox to reduce or to expand
' to fit the size of the PictureBox.
MyPictureBox.SizeMode = PictureBoxSizeMode.StretchImage
' Set the location of the PictureBox based on the value of Count.
MyPictureBox.Location = New System.Drawing.Point(Count * 64, 0)
' Set the size of the PictureBox.
MyPictureBox.Size = New System.Drawing.Size(128, 128)
' Set the BorderStyle of the PictureBox.
MyPictureBox.BorderStyle = BorderStyle.Fixed3D
' Set the image of the PictureBox from the opened FileStream.
MyPictureBox.Image = System.Drawing.Image.FromStream(ImageStream)
' Add the PictureBox to your Form1 object.
Me.Controls.Add(MyPictureBox)
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub

End Class





source :http://msdn2.microsoft.com

-------------------------------------------------------

Trik Gambar Bergerak

Trik Gambar-dimouse

Trik hapus pwd mysql

Trik insertin to db

Trik jadi root dilinux

Trik jam-distatus-bar

Trik Koneksi-ke database

Trik Koneksi-msql-php

Trik lihat-database-mysql

Trik membahas-fungsi-else

Trik member-area