November 20, 2008

Menggunakan Main Menu untuk mengatur Child Window (MDI)

Dengan Main Menu kita bisa menampilkan dan mengatur banyak Child Window sesuai dengan yang di inginkan...Dan untuk mendapatkan source code lengkapnya bisa didownload disini. Selamat mencoba


Imports System
Imports System.Collections
Imports System.Data
Imports System.IO
Imports System.Xml.Serialization
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Drawing.Printing


Public Class MainClass
Shared Sub Main()
Dim form1 As Form = New Form1()
Application.Run(form1)
End Sub
End Class


Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Me.Text = "I'm an MDI Parent"
Me.IsMdiContainer = True
Dim MyChild As New System.Windows.Forms.Form()
MyChild.MdiParent = Me
MyChild.Show()
MyChild.Text = "First MDI Child"
InitializeMenu()
End Sub

Public Sub InitializeMenu()
Dim mnuWindow As New MenuItem("&Window")
MainMenu1.MenuItems.Add(mnuWindow)
mnuWindow.MenuItems.Add(New MenuItem("&Cascade", AddressOf WindowCascade_Clicked))
mnuWindow.MenuItems.Add(New MenuItem("Tile &Horizontal", AddressOf WindowTileHoriz_Clicked))
mnuWindow.MenuItems.Add(New MenuItem("Tile &Vertical", AddressOf WindowTileVert_Clicked))
mnuWindow.MdiList = True
End Sub

Protected Sub WindowCascade_Clicked(ByVal Sender As Object, _
ByVal e As System.EventArgs)
Me.LayoutMdi(MdiLayout.Cascade)
End Sub

Protected Sub WindowTileHoriz_Clicked(ByVal Sender As Object, _
ByVal e As System.EventArgs)
Me.LayoutMdi(MdiLayout.TileHorizontal)
End Sub

Protected Sub WindowTileVert_Clicked(ByVal Sender As Object, _
ByVal e As System.EventArgs)
Me.LayoutMdi(MdiLayout.TileVertical)
End Sub

Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
System.Environment.Exit(0)
End Sub

Private Sub mnuNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNew.Click
Static numOfChildren As Integer = 2
Dim MyChild As New System.Windows.Forms.Form()
MyChild.MdiParent = Me
MyChild.Show()
MyChild.Text = "MDI Child " & CStr(numOfChildren)
numOfChildren += 1
End Sub

No comments: