14.43.1.webbrowser Demo
14.43.1.webbrowser Demo
WebBrowser Demo
Imports System.Windows.Forms public class WebBrowserDemo public Shared Sub Main Application.Run(New Form1) End Sub End class Public Class Form1 Private Sub txtURL_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyE If (e.KeyCode = Keys.Enter) Then WebBrowser1.Navigate(txtURL.Text) End If End Sub
Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArg WebBrowser1.GoBack() End Sub
Private Sub btnForward_Click(ByVal sender As System.Object, ByVal e As System.Event WebBrowser1.GoForward() End Sub
Private Sub btnHome_Click(ByVal sender As System.Object, ByVal e As System.EventArg WebBrowser1.GoHome() End Sub End Class <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Partial Class Form1 Inherits System.Windows.Forms.Form 'Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso components IsNot Nothing Then components.Dispose() End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.ToolStrip1 = New System.Windows.Forms.ToolStrip Me.ToolStripLabel1 = New System.Windows.Forms.ToolStripLabel Me.txtURL = New System.Windows.Forms.ToolStripTextBox Me.btnBack = New System.Windows.Forms.ToolStripButton Me.btnForward = New System.Windows.Forms.ToolStripButton Me.btnHome = New System.Windows.Forms.ToolStripButton Me.WebBrowser1 = New System.Windows.Forms.WebBrowser Me.ToolStrip1.SuspendLayout() Me.SuspendLayout() '
'ToolStrip1 ' Me.ToolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolS Me.ToolStrip1.Location = New System.Drawing.Point(0, 0) Me.ToolStrip1.Name = "ToolStrip1" Me.ToolStrip1.Size = New System.Drawing.Size(703, 25) Me.ToolStrip1.TabIndex = 0 Me.ToolStrip1.Text = "ToolStrip1" ' 'ToolStripLabel1 ' Me.ToolStripLabel1.Name = "ToolStripLabel1" Me.ToolStripLabel1.Size = New System.Drawing.Size(50, 22) Me.ToolStripLabel1.Text = "Address:" ' 'txtURL ' Me.txtURL.Name = "txtURL" Me.txtURL.Size = New System.Drawing.Size(200, 25) ' 'btnBack ' Me.btnBack.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text Me.btnBack.ImageTransparentColor = System.Drawing.Color.Magenta Me.btnBack.Name = "btnBack" Me.btnBack.Size = New System.Drawing.Size(33, 22) Me.btnBack.Text = "Back" ' 'btnForward ' Me.btnForward.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Tex Me.btnForward.ImageTransparentColor = System.Drawing.Color.Magenta Me.btnForward.Name = "btnForward" Me.btnForward.Size = New System.Drawing.Size(51, 22) Me.btnForward.Text = "Forward" ' 'btnHome ' Me.btnHome.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text Me.btnHome.ImageTransparentColor = System.Drawing.Color.Magenta Me.btnHome.Name = "btnHome" Me.btnHome.Size = New System.Drawing.Size(38, 22) Me.btnHome.Text = "Home" ' 'WebBrowser1 ' Me.WebBrowser1.Dock = System.Windows.Forms.DockStyle.Fill Me.WebBrowser1.Location = New System.Drawing.Point(0, 25) Me.WebBrowser1.MinimumSize = New System.Drawing.Size(20, 20) Me.WebBrowser1.Name = "WebBrowser1" Me.WebBrowser1.Size = New System.Drawing.Size(703, 429) Me.WebBrowser1.TabIndex = 1 ' 'Form1 ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(703, 454) Me.Controls.Add(Me.WebBrowser1) Me.Controls.Add(Me.ToolStrip1) Me.Name = "Form1" Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Me.Text = "MyBrowser" Me.ToolStrip1.ResumeLayout(False) Me.ToolStrip1.PerformLayout() Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents End Class ToolStrip1 As System.Windows.Forms.ToolStrip WebBrowser1 As System.Windows.Forms.WebBrowser ToolStripLabel1 As System.Windows.Forms.ToolStripLabel txtURL As System.Windows.Forms.ToolStripTextBox btnBack As System.Windows.Forms.ToolStripButton btnForward As System.Windows.Forms.ToolStripButton btnHome As System.Windows.Forms.ToolStripButton
Imports System.Runtime.InteropServices Imports System.Windows.Forms public class CreateYourOwnBrowserBasedOnDLL public Shared Sub Main Application.Run(New Form1) End Sub End class Public Class Form1 Dim szPath As String ' Start\Program Public Const CSIDL_PROGRAMS As Short = &H2S ' My Documents Public Const CSIDL_PERSONAL As Short = &H5S ' {User}\Bookmark Windows NT Public Const CSIDL_FAVORITES As Short = &H6S ' Start\Program\Boot Public Const CSIDL_STARTUP As Short = &H7S ' {User}\Start Windows NT Public Const CSIDL_STARTMENU As Short = &HBS ' {User}\Desktop Windows NT Public Const CSIDL_DESKTOPDIRECTORY As Short = &H10S ' {Windows}\ShellNew Public Const CSIDL_TEMPLATES As Short = &H15S
' All Users\Start Windows NT Public Const CSIDL_COMMON_STARTMENU As Short = &H16S ' All Users\Program Windows NT Public Const CSIDL_COMMON_PROGRAMS As Short = &H17S ' All Users\Boot Windows NT Public Const CSIDL_COMMON_STARTUP As Short = &H18S ' All Users\Desktop Windows NT Public Const CSIDL_COMMON_DESKTOPDIRECTORY As Short = &H19S ' {Windows}\Application Data Public Const CSIDL_APPDATA As Short = &H1AS ' All Users\Bookmark Windows NT Public Const CSIDL_COMMON_FAVORITES As Short = &H1FS ' All Users\Application Data Windows NT Public Const CSIDL_COMMON_APPDATA As Short = &H23S ' nShowCmd Public Const Public Const Public Const Public Const Public Const Public Const Public Const Public Const Public Const Public Const Public Const SW_HIDE As Short = 0 SW_SHOWNORMAL As Short = 1 SW_SHOWMINIMIZED As Short = 2 SW_SHOWMAXIMIZED As Short = 3 SW_MAXIMIZE As Short = 3 SW_SHOWNOACTIVATE As Short = 4 SW_SHOW As Short = 5 SW_MINIMIZE As Short = 6 SW_SHOWMINNOACTIVE As Short = 7 SW_SHOWNA As Short = 8 SW_RESTORE As Short = 9
' Error Code Public Const ERROR_FILE_NOT_FOUND As Short = 2 Public Const ERROR_PATH_NOT_FOUND As Short = 3 Public Const ERROR_BAD_FORMAT As Short = 11 Public Public Public Public Public Public Public Public Public Public Public Public Public Public Public Public Public Public Public Public Public Public Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const Const SE_ERR_FNF As Short = 2 SE_ERR_PNF As Short = 3 SE_ERR_ACCESSDENIED As Short = 5 SE_ERR_OOM As Short = 8 SE_ERR_SHARE As Short = 26 SE_ERR_ASSOCINCOMPLETE As Short = 27 SE_ERR_DDETIMEOUT As Short = 28 SE_ERR_DDEFAIL As Short = 29 SE_ERR_DDEBUSY As Short = 30 SE_ERR_NOASSOC As Short = 31 SE_ERR_DLLNOTFOUND As Short = 32 SHACF_DEFAULT As Integer = &H0S SHACF_FILESYSTEM As Integer = &H1S SHACF_URLHISTORY As Integer = &H2S SHACF_URLMRU As Integer = &H4S SHACF_USETAB As Integer = &H8S SHACF_FILESYS_ONLY As Integer = &H10S SHACF_AUTOSUGGEST_FORCE_ON As Integer = &H10000000 SHACF_AUTOSUGGEST_FORCE_OFF As Integer = &H20000000 SHACF_AUTOAPPEND_FORCE_ON As Integer = &H40000000 SHACF_AUTOAPPEND_FORCE_OFF As Integer = &H80000000 SHACF_URLALL As Integer = (SHACF_URLHISTORY Or SHACF_URLMRU)
Public Declare Function SHAutoComplete Lib "Shlwapi.dll" _ (ByVal hwndEdit As Integer, _ ByVal dwFlags As Integer) As Integer Public Declare Function DoAddToFavDlg _ Lib "shdocvw.dll" _ (ByVal hwnd As Integer, _ ByVal szPath As String, _ ByVal nSizeOfPath As Integer, _ ByVal szTitle As String, _ ByVal nSizeOfTitle As Integer, _ ByVal pidl As Integer) As Integer Public Declare Function SHGetSpecialFolderLocation _ Lib "shell32.dll" _ (ByVal hwndOwner As Integer, _ ByVal nFolder As Integer, _ ByRef pidl As Integer) As Integer Private Declare Function DoFileDownload Lib "shdocvw.dll" _ (ByVal lpszFile As String) As Integer Public Declare Function WritePrivateProfileString _ Lib "kernel32" Alias "WritePrivateProfileStringA" _ (ByVal lpSectionName As String, _ ByVal lpKeyName As String, _ ByVal lpString As String, _ ByVal lpFileName As String) As Integer Public Declare Function DoOrganizeFavDlg _ Lib "shdocvw.dll" _ (ByVal hWnd As Integer, _ ByVal lpszRootFolder As String) As Integer Public Declare Function SHGetFolderPath _ Lib "shfolder.dll" Alias "SHGetFolderPathA" _ (ByVal hwndOwner As Integer, _ ByVal nFolder As Integer, _ ByVal hToken As Integer, _ ByVal dwReserved As Integer, _ ByVal lpszPath As String) As Integer Private Sub AutoComplete(ByVal check1 As Boolean, ByVal check2 As Boolean) Dim dwFlags As Integer If check1 Then dwFlags = SHACF_URLALL Or SHACF_FILESYSTEM Or _ SHACF_AUTOSUGGEST_FORCE_ON If check2 Then dwFlags = dwFlags Or SHACF_AUTOAPPEND_FORCE_ON Else dwFlags = dwFlags Or SHACF_AUTOAPPEND_FORCE_OFF End If
Else dwFlags = SHACF_URLALL Or SHACF_FILESYSTEM Or _ SHACF_AUTOSUGGEST_FORCE_OFF If check2 Then dwFlags = dwFlags Or SHACF_AUTOAPPEND_FORCE_ON Else dwFlags = dwFlags Or SHACF_AUTOAPPEND_FORCE_OFF End If End If SHAutoComplete(TextBox1.Handle.ToInt32, dwFlags) End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) MenuStrip1.Top = 0 MenuStrip1.Left = 0 Panel1.Top = MenuStrip1.Height Panel1.Left = 0 Panel1.Width = Me.ClientSize.Width TextBox1.Width = Panel1.Width - TextBox1.Left - 5 WebBrowser1.Top = Panel1.Top + Panel1.Height WebBrowser1.Left = 0 WebBrowser1.Width = Me.ClientSize.Width WebBrowser1.Height = Me.ClientSize.Height - Panel1.Height - StatusStrip1.Height WebBrowser1.Navigate("c:\") End Sub
Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs MenuStrip1.Top = 0 MenuStrip1.Left = 0 Panel1.Top = MenuStrip1.Height Panel1.Left = 0 Panel1.Width = Me.ClientSize.Width TextBox1.Width = Panel1.Width - TextBox1.Left - 5 WebBrowser1.Top = Panel1.Top + Panel1.Height WebBrowser1.Left = 0 WebBrowser1.Width = Me.ClientSize.Width WebBrowser1.Height = Me.ClientSize.Height - Panel1.Height - StatusStrip1.Height End Sub
Private Sub BackBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArg WebBrowser1.GoBack() End Sub
Private Sub ForwardBtn_Click(ByVal sender As System.Object, ByVal e As System.Event WebBrowser1.GoForward() End Sub
Private Sub StopBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArg WebBrowser1.Stop() End Sub
Private Sub RefreshBtn_Click(ByVal sender As System.Object, ByVal e As System.Event WebBrowser1.Refresh() End Sub
Private Sub HomeBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArg WebBrowser1.GoHome() End Sub
Private Sub SearchBtn_Click(ByVal sender As System.Object, ByVal e As System.EventA WebBrowser1.GoSearch() End Sub
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Wind If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then WebBrowser1.Navigate(TextBox1.Text) End If End Sub
Private Sub WebBrowser1_Navigated(ByVal sender As System.Object, ByVal e As System. TextBox1.Text = WebBrowser1.Url.ToString ToolStripStatusLabel1.Text = WebBrowser1.Url.ToString End Sub
Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As Syst Dim NewForm As New Form1() Dim strURL As String = WebBrowser1.Url.ToString NewForm.Show() NewForm.Focus() NewForm.WebBrowser1.Navigate(strURL) End Sub
Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As Syst OpenFileDialog1.Filter = "All Files (*.*)|*.*" OpenFileDialog1.Title = "Open" If OpenFileDialog1.ShowDialog() = DialogResult.OK Then WebBrowser1.Navigate(OpenFileDialog1.FileName) End If End Sub
Private Sub ToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e As Syst Dim proc As New System.Diagnostics.Process() Dim SystemDir As String = System.Environment.SystemDirectory proc.Start(SystemDir & "\MOBSYNC.EXE") End Sub
Private Sub ToolStripMenuItem4_Click(ByVal sender As System.Object, ByVal e As Syst Dim proc As New System.Diagnostics.Process() Dim SystemDir As String = System.Environment.SystemDirectory proc.Start("control.exe", "Inetcpl.cpl") End Sub
Private Sub ToolStripMenuItem5_Click(ByVal sender As System.Object, ByVal e As Syst If TextBox1.Text <> "" Then WebBrowser1.Navigate("view-source:" & TextBox1.Text) End If
End Sub
Private Sub ToolStripMenuItemMail_Click(ByVal sender As System.Object, ByVal e As S WebBrowser1.Navigate("mailto:[email protected][email protected]& [email protected]&su End Sub
Private Sub ToolStripMenuItem6_Click(ByVal sender As System.Object, ByVal e As Syst ToolStripMenuItem6.Checked = Not ToolStripMenuItem6.Checked AutoComplete(ToolStripMenuItem6.Checked, ToolStripMenuItem7.Checked) End Sub
Private Sub ToolStripMenuItem7_Click(ByVal sender As System.Object, ByVal e As Syst ToolStripMenuItem7.Checked = Not ToolStripMenuItem7.Checked AutoComplete(ToolStripMenuItem6.Checked, ToolStripMenuItem7.Checked) End Sub
Private Sub ToolStripMenuItem11_Click(ByVal sender As System.Object, ByVal e As Sys Try DoFileDownload(TextBox1.Text) Catch ex As Exception MsgBox(ex.StackTrace.ToString()) End Try End Sub
Private Sub ToolStripMenuItem9_Click(ByVal sender As System.Object, ByVal e As Syst Dim proc As New System.Diagnostics.Process() Dim SystemDir As String = System.Environment.SystemDirectory Dim szPath As String = "http://www.java2s.com/" If szPath <> "" Then Try 'rundll32.exe shdocvw.dll,OpenURL %l proc.Start("rundll32.exe", "shdocvw.dll,OpenURL " & szPath) Catch ex As Exception Console.WriteLine(ex.StackTrace.ToString()) End Try End If End Sub
Private Sub ToolStripMenuItem8_Click(ByVal sender As System.Object, ByVal e As Syst Dim szTitle As String Dim dwReturn As Integer Dim pidl As Integer szTitle = "My Bookmark" & vbNullChar szPath = Space(256) & vbNullChar dwReturn = SHGetSpecialFolderLocation(Handle.ToInt32, _ CSIDL_FAVORITES, pidl) If dwReturn = 0 Then dwReturn = DoAddToFavDlg(Handle.ToInt32, szPath, _ Len(szPath), szTitle, Len(szTitle), pidl) If dwReturn = 1 Then szPath = szPath.Substring(0, szPath.IndexOf(vbNullChar)) WritePrivateProfileString("InternetShortcut", "URL", _ TextBox1.Text, szPath) End If End If End Sub
Sub ToolStripMenuItem10_Click(ByVal sender As System.Object, ByVal e As Sys lpszRootFolder As String lpszPath As String dwReturn As Integer
lpszPath = Space(256) dwReturn = SHGetFolderPath(Handle.ToInt32, _ CSIDL_FAVORITES, 0, &H0S, lpszPath) If dwReturn = 0 Then lpszRootFolder = lpszPath.Substring(0, _ lpszPath.IndexOf(vbNullChar)) End If DoOrganizeFavDlg(Handle.ToInt32, lpszRootFolder) End Sub End Class <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Partial Class Form1 Inherits System.Windows.Forms.Form 'Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso components IsNot Nothing Then components.Dispose() End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.Panel1 = New System.Windows.Forms.Panel Me.ToolStrip1 = New System.Windows.Forms.ToolStrip Me.BackBtn = New System.Windows.Forms.ToolStripButton Me.ForwardBtn = New System.Windows.Forms.ToolStripButton Me.StopBtn = New System.Windows.Forms.ToolStripButton Me.RefreshBtn = New System.Windows.Forms.ToolStripButton Me.HomeBtn = New System.Windows.Forms.ToolStripButton Me.SearchBtn = New System.Windows.Forms.ToolStripButton Me.Label1 = New System.Windows.Forms.Label Me.TextBox1 = New System.Windows.Forms.TextBox Me.ToolStripStatusLabel1 = New System.Windows.Forms.ToolStripStatusLabel Me.StatusStrip1 = New System.Windows.Forms.StatusStrip Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog Me.ToolStripMenuItem4 = New System.Windows.Forms.ToolStripMenuItem
Me.ToolStripMenuItem3 = New System.Windows.Forms.ToolStripMenuItem Me.MenuItemFile = New System.Windows.Forms.ToolStripMenuItem Me.ToolStripMenuItem1 = New System.Windows.Forms.ToolStripMenuItem Me.ToolStripMenuItem2 = New System.Windows.Forms.ToolStripMenuItem Me.ToolStripMenuItem5 = New System.Windows.Forms.ToolStripMenuItem Me.ToolStripMenuItemMail = New System.Windows.Forms.ToolStripMenuItem Me.ToolStripMenuItem6 = New System.Windows.Forms.ToolStripMenuItem Me.ToolStripMenuItem7 = New System.Windows.Forms.ToolStripMenuItem Me.MenuStrip1 = New System.Windows.Forms.MenuStrip Me.ToolStripMenuItemFav = New System.Windows.Forms.ToolStripMenuItem Me.ToolStripMenuItem8 = New System.Windows.Forms.ToolStripMenuItem Me.ToolStripMenuItem9 = New System.Windows.Forms.ToolStripMenuItem Me.ToolStripMenuItem10 = New System.Windows.Forms.ToolStripMenuItem Me.ToolStripMenuItem11 = New System.Windows.Forms.ToolStripMenuItem Me.WebBrowser1 = New System.Windows.Forms.WebBrowser Me.Panel1.SuspendLayout() Me.ToolStrip1.SuspendLayout() Me.StatusStrip1.SuspendLayout() Me.MenuStrip1.SuspendLayout() Me.SuspendLayout() ' 'Panel1 ' Me.Panel1.Controls.Add(Me.ToolStrip1) Me.Panel1.Controls.Add(Me.Label1) Me.Panel1.Controls.Add(Me.TextBox1) Me.Panel1.Location = New System.Drawing.Point(-4, 27) Me.Panel1.Name = "Panel1" Me.Panel1.Size = New System.Drawing.Size(546, 59) Me.Panel1.TabIndex = 11 ' 'ToolStrip1 ' Me.ToolStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.BackB Me.ToolStrip1.Location = New System.Drawing.Point(0, 0) Me.ToolStrip1.Name = "ToolStrip1" Me.ToolStrip1.Size = New System.Drawing.Size(546, 25) Me.ToolStrip1.TabIndex = 11 Me.ToolStrip1.Text = "ToolStrip1" ' 'BackBtn ' Me.BackBtn.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text Me.BackBtn.ImageTransparentColor = System.Drawing.Color.Magenta Me.BackBtn.Name = "BackBtn" Me.BackBtn.Size = New System.Drawing.Size(45, 22) Me.BackBtn.Text = "Back" ' 'ForwardBtn ' Me.ForwardBtn.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Tex Me.ForwardBtn.ImageTransparentColor = System.Drawing.Color.Magenta Me.ForwardBtn.Name = "ForwardBtn" Me.ForwardBtn.Size = New System.Drawing.Size(45, 22) Me.ForwardBtn.Text = "Next" '
'StopBtn ' Me.StopBtn.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text Me.StopBtn.ImageTransparentColor = System.Drawing.Color.Magenta Me.StopBtn.Name = "StopBtn" Me.StopBtn.Size = New System.Drawing.Size(33, 22) Me.StopBtn.Text = "Stop" ' 'RefreshBtn ' Me.RefreshBtn.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Tex Me.RefreshBtn.ImageTransparentColor = System.Drawing.Color.Magenta Me.RefreshBtn.Name = "RefreshBtn" Me.RefreshBtn.Size = New System.Drawing.Size(33, 22) Me.RefreshBtn.Text = "Refresh" ' 'HomeBtn ' Me.HomeBtn.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text Me.HomeBtn.ImageTransparentColor = System.Drawing.Color.Magenta Me.HomeBtn.Name = "HomeBtn" Me.HomeBtn.Size = New System.Drawing.Size(45, 22) Me.HomeBtn.Text = "Home" ' 'SearchBtn ' Me.SearchBtn.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text Me.SearchBtn.ImageTransparentColor = System.Drawing.Color.Magenta Me.SearchBtn.Name = "SearchBtn" Me.SearchBtn.Size = New System.Drawing.Size(45, 22) Me.SearchBtn.Text = "Search" ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(5, 28) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(60, 18) Me.Label1.TabIndex = 10 Me.Label1.Text = "URL:" ' 'TextBox1 ' Me.TextBox1.Location = New System.Drawing.Point(71, 28) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(463, 21) Me.TextBox1.TabIndex = 9 Me.TextBox1.Text = "c:\" ' 'ToolStripStatusLabel1 ' Me.ToolStripStatusLabel1.Name = "ToolStripStatusLabel1" Me.ToolStripStatusLabel1.Size = New System.Drawing.Size(23, 17) Me.ToolStripStatusLabel1.Text = "c:\" ' 'StatusStrip1 '
Me.StatusStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.Too Me.StatusStrip1.Location = New System.Drawing.Point(0, 228) Me.StatusStrip1.Name = "StatusStrip1" Me.StatusStrip1.Size = New System.Drawing.Size(541, 22) Me.StatusStrip1.TabIndex = 10 ' 'OpenFileDialog1 ' Me.OpenFileDialog1.FileName = "OpenFileDialog1" ' 'ToolStripMenuItem4 ' Me.ToolStripMenuItem4.Name = "ToolStripMenuItem4" Me.ToolStripMenuItem4.Size = New System.Drawing.Size(202, 22) Me.ToolStripMenuItem4.Text = "IE Option" ' 'ToolStripMenuItem3 ' Me.ToolStripMenuItem3.Name = "ToolStripMenuItem3" Me.ToolStripMenuItem3.Size = New System.Drawing.Size(202, 22) Me.ToolStripMenuItem3.Text = "Concurrent" ' 'MenuItemFile ' Me.MenuItemFile.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() ripMenuItem7}) Me.MenuItemFile.Name = "MenuItemFile" Me.MenuItemFile.Size = New System.Drawing.Size(41, 20) Me.MenuItemFile.Text = "File" ' 'ToolStripMenuItem1 ' Me.ToolStripMenuItem1.Name = "ToolStripMenuItem1" Me.ToolStripMenuItem1.Size = New System.Drawing.Size(202, 22) Me.ToolStripMenuItem1.Text = "New" ' 'ToolStripMenuItem2 ' Me.ToolStripMenuItem2.Name = "ToolStripMenuItem2" Me.ToolStripMenuItem2.Size = New System.Drawing.Size(202, 22) Me.ToolStripMenuItem2.Text = "Open" ' 'ToolStripMenuItem5 ' Me.ToolStripMenuItem5.Name = "ToolStripMenuItem5" Me.ToolStripMenuItem5.Size = New System.Drawing.Size(202, 22) Me.ToolStripMenuItem5.Text = "Source" ' 'ToolStripMenuItemMail ' Me.ToolStripMenuItemMail.Name = "ToolStripMenuItemMail" Me.ToolStripMenuItemMail.Size = New System.Drawing.Size(202, 22) Me.ToolStripMenuItemMail.Text = "Email" ' 'ToolStripMenuItem6 '
Me.ToolStripMenuItem6.Name = "ToolStripMenuItem6" Me.ToolStripMenuItem6.Size = New System.Drawing.Size(202, 22) Me.ToolStripMenuItem6.Text = "Suggestion" ' 'ToolStripMenuItem7 ' Me.ToolStripMenuItem7.Name = "ToolStripMenuItem7" Me.ToolStripMenuItem7.Size = New System.Drawing.Size(202, 22) Me.ToolStripMenuItem7.Text = "Append" ' 'MenuStrip1 ' Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.MenuI Me.MenuStrip1.Location = New System.Drawing.Point(0, 0) Me.MenuStrip1.Name = "MenuStrip1" Me.MenuStrip1.Size = New System.Drawing.Size(541, 24) Me.MenuStrip1.TabIndex = 9 Me.MenuStrip1.Text = "MenuStrip1" ' 'ToolStripMenuItemFav ' Me.ToolStripMenuItemFav.DropDownItems.AddRange(New System.Windows.Forms.ToolStr Me.ToolStripMenuItemFav.Name = "ToolStripMenuItemFav" Me.ToolStripMenuItemFav.Size = New System.Drawing.Size(53, 20) Me.ToolStripMenuItemFav.Text = "Bookmark" ' 'ToolStripMenuItem8 ' Me.ToolStripMenuItem8.Name = "ToolStripMenuItem8" Me.ToolStripMenuItem8.Size = New System.Drawing.Size(190, 22) Me.ToolStripMenuItem8.Text = "Add Bookmark" ' 'ToolStripMenuItem9 ' Me.ToolStripMenuItem9.Name = "ToolStripMenuItem9" Me.ToolStripMenuItem9.Size = New System.Drawing.Size(190, 22) Me.ToolStripMenuItem9.Text = "Internet URL Shortcut" ' 'ToolStripMenuItem10 ' Me.ToolStripMenuItem10.Name = "ToolStripMenuItem10" Me.ToolStripMenuItem10.Size = New System.Drawing.Size(190, 22) Me.ToolStripMenuItem10.Text = "Organize" ' 'ToolStripMenuItem11 ' Me.ToolStripMenuItem11.Name = "ToolStripMenuItem11" Me.ToolStripMenuItem11.Size = New System.Drawing.Size(190, 22) Me.ToolStripMenuItem11.Text = "Download File" ' 'WebBrowser1 ' Me.WebBrowser1.Location = New System.Drawing.Point(5, 93) Me.WebBrowser1.MinimumSize = New System.Drawing.Size(20, 20) Me.WebBrowser1.Name = "WebBrowser1" Me.WebBrowser1.Size = New System.Drawing.Size(536, 120)
Me.WebBrowser1.TabIndex = 12 ' 'Form1 ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(541, 250) Me.Controls.Add(Me.WebBrowser1) Me.Controls.Add(Me.Panel1) Me.Controls.Add(Me.StatusStrip1) Me.Controls.Add(Me.MenuStrip1) Me.Panel1.ResumeLayout(False) Me.Panel1.PerformLayout() Me.ToolStrip1.ResumeLayout(False) Me.ToolStrip1.PerformLayout() Me.StatusStrip1.ResumeLayout(False) Me.StatusStrip1.PerformLayout() Me.MenuStrip1.ResumeLayout(False) Me.MenuStrip1.PerformLayout() Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents End Class
Panel1 As System.Windows.Forms.Panel ToolStrip1 As System.Windows.Forms.ToolStrip BackBtn As System.Windows.Forms.ToolStripButton ForwardBtn As System.Windows.Forms.ToolStripButton StopBtn As System.Windows.Forms.ToolStripButton RefreshBtn As System.Windows.Forms.ToolStripButton HomeBtn As System.Windows.Forms.ToolStripButton SearchBtn As System.Windows.Forms.ToolStripButton Label1 As System.Windows.Forms.Label TextBox1 As System.Windows.Forms.TextBox ToolStripStatusLabel1 As System.Windows.Forms.ToolStripStatusLabe StatusStrip1 As System.Windows.Forms.StatusStrip OpenFileDialog1 As System.Windows.Forms.OpenFileDialog ToolStripMenuItem4 As System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem3 As System.Windows.Forms.ToolStripMenuItem MenuItemFile As System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem1 As System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem2 As System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem5 As System.Windows.Forms.ToolStripMenuItem MenuStrip1 As System.Windows.Forms.MenuStrip ToolStripMenuItem6 As System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem7 As System.Windows.Forms.ToolStripMenuItem ToolStripMenuItemFav As System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem8 As System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem9 As System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem10 As System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem11 As System.Windows.Forms.ToolStripMenuItem WebBrowser1 As System.Windows.Forms.WebBrowser ToolStripMenuItemMail As System.Windows.Forms.ToolStripMenuItem
Imports System.Windows.Forms public class LinkLableSample public Shared Sub Main Application.Run(New Form1) End Sub End class Public Class Form1 Inherits System.Windows.Forms.Form Public Sub New() MyBase.New() InitializeComponent() End Sub 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 Private components As System.ComponentModel.IContainer
Friend WithEvents LinkLabel1 As System.Windows.Forms.LinkLabel <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.LinkLabel1 = New System.Windows.Forms.LinkLabel Me.SuspendLayout() ' 'LinkLabel1 ' Me.LinkLabel1.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.75!, Sy Me.LinkLabel1.Location = New System.Drawing.Point(88, 32) Me.LinkLabel1.Name = "LinkLabel1" Me.LinkLabel1.Size = New System.Drawing.Size(112, 32) Me.LinkLabel1.TabIndex = 0 Me.LinkLabel1.TabStop = True Me.LinkLabel1.Text = "java2s.com" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 102) Me.Controls.Add(Me.LinkLabel1) Me.ResumeLayout(False)
End Sub
Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System sender.linkVisited = True System.Diagnostics.Process.Start("http://www.java2s.com") End Sub End Class
15.13.1.Scribble 1
Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class Scribble public Shared Sub Main Application.Run(New frmScribble) End Sub End class
'Sams Teach Yourself Visual Basic .NET in 21 Days 'By Lowell Mauer 'Published 2001 'Sams Publishing 'ISBN 0672322714 Public Class frmScribble Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call 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 Private WithEvents pnlTools As System.Windows.Forms.Panel Private WithEvents optPen As System.Windows.Forms.RadioButton Private WithEvents picDraw As System.Windows.Forms.PictureBox Private WithEvents optShape As System.Windows.Forms.RadioButton Private WithEvents optText As System.Windows.Forms.RadioButton Private WithEvents pnlOptions As System.Windows.Forms.Panel Private WithEvents mnuMain As System.Windows.Forms.MainMenu Private WithEvents mnuFile As System.Windows.Forms.MenuItem Private WithEvents mnuFileNew As System.Windows.Forms.MenuItem Private WithEvents mnuFileOpen As System.Windows.Forms.MenuItem Private WithEvents mnuFileSave As System.Windows.Forms.MenuItem Private WithEvents mnuFileSep As System.Windows.Forms.MenuItem Private WithEvents mnuFileExit As System.Windows.Forms.MenuItem Private WithEvents dlgOpen As System.Windows.Forms.OpenFileDialog Private WithEvents dlgSave As System.Windows.Forms.SaveFileDialog Private WithEvents pnlPenOptions As System.Windows.Forms.Panel Private WithEvents lblColor As System.Windows.Forms.Label Private WithEvents cboColors As System.Windows.Forms.ComboBox Private WithEvents lblPenWidth As System.Windows.Forms.Label Private WithEvents updPenWidth As System.Windows.Forms.NumericUpDown Private WithEvents pnlShapeOptions As System.Windows.Forms.Panel Private WithEvents pnlTextOptions As System.Windows.Forms.Panel Private WithEvents lblText As System.Windows.Forms.Label Private WithEvents txtText As System.Windows.Forms.TextBox Private WithEvents lblTextFont As System.Windows.Forms.Label Private WithEvents cboTextFont As System.Windows.Forms.ComboBox Private WithEvents lblFontSize As System.Windows.Forms.Label Private WithEvents updFontSize As System.Windows.Forms.NumericUpDown Private WithEvents lblShapeType As System.Windows.Forms.Label Private WithEvents cboShapeType As System.Windows.Forms.ComboBox Private WithEvents lblShapeHeight As System.Windows.Forms.Label Private WithEvents updShapeHeight As System.Windows.Forms.NumericUpDown Private WithEvents updShapeWidth As System.Windows.Forms.NumericUpDown Private WithEvents lblShapeWidth As System.Windows.Forms.Label 'Required by the Windows Form Designer Private components As System.ComponentModel.Container 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.updShapeHeight = New System.Windows.Forms.NumericUpDown() Me.cboColors = New System.Windows.Forms.ComboBox() Me.pnlShapeOptions = New System.Windows.Forms.Panel() Me.lblShapeWidth = New System.Windows.Forms.Label() Me.updShapeWidth = New System.Windows.Forms.NumericUpDown() Me.lblShapeHeight = New System.Windows.Forms.Label() Me.cboShapeType = New System.Windows.Forms.ComboBox() Me.lblShapeType = New System.Windows.Forms.Label() Me.updPenWidth = New System.Windows.Forms.NumericUpDown() Me.pnlTools = New System.Windows.Forms.Panel() Me.optText = New System.Windows.Forms.RadioButton()
Me.optShape = New System.Windows.Forms.RadioButton() Me.optPen = New System.Windows.Forms.RadioButton() Me.picDraw = New System.Windows.Forms.PictureBox() Me.pnlPenOptions = New System.Windows.Forms.Panel() Me.lblPenWidth = New System.Windows.Forms.Label() Me.mnuFileExit = New System.Windows.Forms.MenuItem() Me.updFontSize = New System.Windows.Forms.NumericUpDown() Me.mnuMain = New System.Windows.Forms.MainMenu() Me.mnuFile = New System.Windows.Forms.MenuItem() Me.mnuFileNew = New System.Windows.Forms.MenuItem() Me.mnuFileOpen = New System.Windows.Forms.MenuItem() Me.mnuFileSave = New System.Windows.Forms.MenuItem() Me.mnuFileSep = New System.Windows.Forms.MenuItem() Me.cboTextFont = New System.Windows.Forms.ComboBox() Me.pnlOptions = New System.Windows.Forms.Panel() Me.pnlTextOptions = New System.Windows.Forms.Panel() Me.lblFontSize = New System.Windows.Forms.Label() Me.lblTextFont = New System.Windows.Forms.Label() Me.txtText = New System.Windows.Forms.TextBox() Me.lblText = New System.Windows.Forms.Label() Me.lblColor = New System.Windows.Forms.Label() Me.dlgSave = New System.Windows.Forms.SaveFileDialog() Me.dlgOpen = New System.Windows.Forms.OpenFileDialog() CType(Me.updShapeHeight, System.ComponentModel.ISupportInitialize).BeginInit() Me.updShapeHeight.SuspendLayout() Me.pnlShapeOptions.SuspendLayout() CType(Me.updShapeWidth, System.ComponentModel.ISupportInitialize).BeginInit() Me.updShapeWidth.SuspendLayout() CType(Me.updPenWidth, System.ComponentModel.ISupportInitialize).BeginInit() Me.updPenWidth.SuspendLayout() Me.pnlTools.SuspendLayout() Me.pnlPenOptions.SuspendLayout() CType(Me.updFontSize, System.ComponentModel.ISupportInitialize).BeginInit() Me.updFontSize.SuspendLayout() Me.pnlOptions.SuspendLayout() Me.pnlTextOptions.SuspendLayout() Me.SuspendLayout() ' 'updShapeHeight ' Me.updShapeHeight.Location = New System.Drawing.Point(64, 32) Me.updShapeHeight.Maximum = New Decimal(New Integer() {1000, 0, 0, 0}) Me.updShapeHeight.Minimum = New Decimal(New Integer() {1, 0, 0, 0}) Me.updShapeHeight.Name = "updShapeHeight" Me.updShapeHeight.Size = New System.Drawing.Size(48, 20) Me.updShapeHeight.TabIndex = 3 Me.updShapeHeight.Value = New Decimal(New Integer() {20, 0, 0, 0}) ' 'cboColors ' Me.cboColors.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList Me.cboColors.DropDownWidth = 136 Me.cboColors.Location = New System.Drawing.Point(8, 24) Me.cboColors.Name = "cboColors" Me.cboColors.Size = New System.Drawing.Size(136, 21) Me.cboColors.TabIndex = 2
' 'pnlShapeOptions ' Me.pnlShapeOptions.Controls.AddRange(New System.Windows.Forms.Control() {Me.lbl Me.pnlShapeOptions.Location = New System.Drawing.Point(160, 8) Me.pnlShapeOptions.Name = "pnlShapeOptions" Me.pnlShapeOptions.Size = New System.Drawing.Size(274, 56) Me.pnlShapeOptions.TabIndex = 0 ' 'lblShapeWidth ' Me.lblShapeWidth.Location = New System.Drawing.Point(128, 32) Me.lblShapeWidth.Name = "lblShapeWidth" Me.lblShapeWidth.Size = New System.Drawing.Size(48, 16) Me.lblShapeWidth.TabIndex = 2 Me.lblShapeWidth.Text = "Width:" ' 'updShapeWidth ' Me.updShapeWidth.Location = New System.Drawing.Point(184, 32) Me.updShapeWidth.Maximum = New Decimal(New Integer() {1000, 0, 0, 0}) Me.updShapeWidth.Minimum = New Decimal(New Integer() {1, 0, 0, 0}) Me.updShapeWidth.Name = "updShapeWidth" Me.updShapeWidth.Size = New System.Drawing.Size(48, 20) Me.updShapeWidth.TabIndex = 3 Me.updShapeWidth.Value = New Decimal(New Integer() {20, 0, 0, 0}) ' 'lblShapeHeight ' Me.lblShapeHeight.Location = New System.Drawing.Point(8, 32) Me.lblShapeHeight.Name = "lblShapeHeight" Me.lblShapeHeight.Size = New System.Drawing.Size(48, 16) Me.lblShapeHeight.TabIndex = 2 Me.lblShapeHeight.Text = "Height:" ' 'cboShapeType ' Me.cboShapeType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList Me.cboShapeType.DropDownWidth = 121 Me.cboShapeType.Location = New System.Drawing.Point(64, 8) Me.cboShapeType.Name = "cboShapeType" Me.cboShapeType.Size = New System.Drawing.Size(121, 21) Me.cboShapeType.TabIndex = 1 ' 'lblShapeType ' Me.lblShapeType.Location = New System.Drawing.Point(8, 8) Me.lblShapeType.Name = "lblShapeType" Me.lblShapeType.Size = New System.Drawing.Size(48, 16) Me.lblShapeType.TabIndex = 0 Me.lblShapeType.Text = "Type:" ' 'updPenWidth ' Me.updPenWidth.Location = New System.Drawing.Point(96, 8) Me.updPenWidth.Maximum = New Decimal(New Integer() {10, 0, 0, 0})
Me.updPenWidth.Minimum = New Decimal(New Integer() {1, 0, 0, 0}) Me.updPenWidth.Name = "updPenWidth" Me.updPenWidth.Size = New System.Drawing.Size(48, 20) Me.updPenWidth.TabIndex = 1 Me.updPenWidth.Value = New Decimal(New Integer() {1, 0, 0, 0}) ' 'pnlTools ' Me.pnlTools.Controls.AddRange(New System.Windows.Forms.Control() {Me.optText, M Me.pnlTools.Dock = System.Windows.Forms.DockStyle.Left Me.pnlTools.Name = "pnlTools" Me.pnlTools.Size = New System.Drawing.Size(64, 332) Me.pnlTools.TabIndex = 0 ' 'optText ' Me.optText.Appearance = System.Windows.Forms.Appearance.Button Me.optText.Location = New System.Drawing.Point(8, 88) Me.optText.Name = "optText" Me.optText.Size = New System.Drawing.Size(48, 36) Me.optText.TabIndex = 0 Me.optText.Text = "Text" Me.optText.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ' 'optShape ' Me.optShape.Appearance = System.Windows.Forms.Appearance.Button Me.optShape.Location = New System.Drawing.Point(8, 48) Me.optShape.Name = "optShape" Me.optShape.Size = New System.Drawing.Size(48, 36) Me.optShape.TabIndex = 0 Me.optShape.Text = "Shape" Me.optShape.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ' 'optPen ' Me.optPen.Appearance = System.Windows.Forms.Appearance.Button Me.optPen.Checked = True Me.optPen.Location = New System.Drawing.Point(8, 8) Me.optPen.Name = "optPen" Me.optPen.Size = New System.Drawing.Size(48, 36) Me.optPen.TabIndex = 0 Me.optPen.TabStop = True Me.optPen.Text = "Pen" Me.optPen.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ' 'picDraw ' Me.picDraw.BackColor = System.Drawing.SystemColors.Window Me.picDraw.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.picDraw.Dock = System.Windows.Forms.DockStyle.Fill Me.picDraw.Location = New System.Drawing.Point(64, 0) Me.picDraw.Name = "picDraw" Me.picDraw.Size = New System.Drawing.Size(436, 260) Me.picDraw.TabIndex = 2 Me.picDraw.TabStop = False
' 'pnlPenOptions ' Me.pnlPenOptions.Controls.AddRange(New System.Windows.Forms.Control() {Me.updPe Me.pnlPenOptions.Location = New System.Drawing.Point(160, 8) Me.pnlPenOptions.Name = "pnlPenOptions" Me.pnlPenOptions.Size = New System.Drawing.Size(274, 56) Me.pnlPenOptions.TabIndex = 0 ' 'lblPenWidth ' Me.lblPenWidth.Location = New System.Drawing.Point(8, 8) Me.lblPenWidth.Name = "lblPenWidth" Me.lblPenWidth.Size = New System.Drawing.Size(80, 16) Me.lblPenWidth.TabIndex = 0 Me.lblPenWidth.Text = "Pen Width:" ' 'mnuFileExit ' Me.mnuFileExit.Index = 4 Me.mnuFileExit.Shortcut = System.Windows.Forms.Shortcut.CtrlQ Me.mnuFileExit.Text = "E&xit" ' 'updFontSize ' Me.updFontSize.Location = New System.Drawing.Point(208, 32) Me.updFontSize.Maximum = New Decimal(New Integer() {72, 0, 0, 0}) Me.updFontSize.Minimum = New Decimal(New Integer() {6, 0, 0, 0}) Me.updFontSize.Name = "updFontSize" Me.updFontSize.Size = New System.Drawing.Size(48, 20) Me.updFontSize.TabIndex = 5 Me.updFontSize.Value = New Decimal(New Integer() {12, 0, 0, 0}) ' 'mnuMain ' Me.mnuMain.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFile}) ' 'mnuFile ' Me.mnuFile.Index = 0 Me.mnuFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFileNe Me.mnuFile.Text = "&File" ' 'mnuFileNew ' Me.mnuFileNew.Index = 0 Me.mnuFileNew.Shortcut = System.Windows.Forms.Shortcut.CtrlN Me.mnuFileNew.Text = "&New" ' 'mnuFileOpen ' Me.mnuFileOpen.Index = 1 Me.mnuFileOpen.Shortcut = System.Windows.Forms.Shortcut.CtrlO Me.mnuFileOpen.Text = "&Open..." ' 'mnuFileSave
' Me.mnuFileSave.Index = 2 Me.mnuFileSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS Me.mnuFileSave.Text = "&Save" ' 'mnuFileSep ' Me.mnuFileSep.Index = 3 Me.mnuFileSep.Text = "-" ' 'cboTextFont ' Me.cboTextFont.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList Me.cboTextFont.DropDownWidth = 104 Me.cboTextFont.Location = New System.Drawing.Point(48, 32) Me.cboTextFont.Name = "cboTextFont" Me.cboTextFont.Size = New System.Drawing.Size(104, 21) Me.cboTextFont.TabIndex = 3 ' 'pnlOptions ' Me.pnlOptions.Controls.AddRange(New System.Windows.Forms.Control() {Me.pnlTextO Me.pnlOptions.Dock = System.Windows.Forms.DockStyle.Bottom Me.pnlOptions.Location = New System.Drawing.Point(64, 260) Me.pnlOptions.Name = "pnlOptions" Me.pnlOptions.Size = New System.Drawing.Size(436, 72) Me.pnlOptions.TabIndex = 1 ' 'pnlTextOptions ' Me.pnlTextOptions.Controls.AddRange(New System.Windows.Forms.Control() {Me.updF Me.pnlTextOptions.Location = New System.Drawing.Point(160, 8) Me.pnlTextOptions.Name = "pnlTextOptions" Me.pnlTextOptions.Size = New System.Drawing.Size(274, 56) Me.pnlTextOptions.TabIndex = 0 ' 'lblFontSize ' Me.lblFontSize.Location = New System.Drawing.Point(160, 32) Me.lblFontSize.Name = "lblFontSize" Me.lblFontSize.Size = New System.Drawing.Size(40, 16) Me.lblFontSize.TabIndex = 4 Me.lblFontSize.Text = "Size:" ' 'lblTextFont ' Me.lblTextFont.Location = New System.Drawing.Point(8, 32) Me.lblTextFont.Name = "lblTextFont" Me.lblTextFont.Size = New System.Drawing.Size(40, 16) Me.lblTextFont.TabIndex = 2 Me.lblTextFont.Text = "Font:" ' 'txtText ' Me.txtText.Location = New System.Drawing.Point(48, 8) Me.txtText.Name = "txtText"
Me.txtText.Size = New System.Drawing.Size(208, 20) Me.txtText.TabIndex = 1 Me.txtText.Text = "Scribble!" ' 'lblText ' Me.lblText.Location = New System.Drawing.Point(8, 8) Me.lblText.Name = "lblText" Me.lblText.Size = New System.Drawing.Size(40, 16) Me.lblText.TabIndex = 0 Me.lblText.Text = "Text:" ' 'lblColor ' Me.lblColor.Location = New System.Drawing.Point(8, 8) Me.lblColor.Name = "lblColor" Me.lblColor.Size = New System.Drawing.Size(48, 16) Me.lblColor.TabIndex = 1 Me.lblColor.Text = "Color:" ' 'dlgSave ' Me.dlgSave.DefaultExt = "bmp" Me.dlgSave.FileName = "Scribble1" Me.dlgSave.Filter = "Bitmap files|*.bmp|PNG files|*.png" ' 'dlgOpen ' Me.dlgOpen.DefaultExt = "bmp" Me.dlgOpen.Filter = "Bitmap files|*.bmp|PNG files|*.png" ' 'frmScribble ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(500, 332) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.picDraw, Me.pnlOpti Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle Me.Menu = Me.mnuMain Me.Name = "frmScribble" Me.Text = "Scribble" CType(Me.updShapeHeight, System.ComponentModel.ISupportInitialize).EndInit() Me.updShapeHeight.ResumeLayout(False) Me.pnlShapeOptions.ResumeLayout(False) CType(Me.updShapeWidth, System.ComponentModel.ISupportInitialize).EndInit() Me.updShapeWidth.ResumeLayout(False) CType(Me.updPenWidth, System.ComponentModel.ISupportInitialize).EndInit() Me.updPenWidth.ResumeLayout(False) Me.pnlTools.ResumeLayout(False) Me.pnlPenOptions.ResumeLayout(False) CType(Me.updFontSize, System.ComponentModel.ISupportInitialize).EndInit() Me.updFontSize.ResumeLayout(False) Me.pnlOptions.ResumeLayout(False) Me.pnlTextOptions.ResumeLayout(False) Me.ResumeLayout(False) End Sub
#End Region #Region "Enumerations" Public Enum DrawingTools Pen Shape Text End Enum #End Region #Region "Member variables for properties" Private m_sFileName As String Private m_bDrawing As Boolean Private m_eCurrentTool As DrawingTools #End Region #Region "Private variables" Private oGraphics As System.Drawing.Graphics Private oTool As Object Private sngX As Single Private sngY As Single #End Region #Region "Properties" Public Property FileName() As String Get Return m_sFileName End Get Set(ByVal Value As String) m_sFileName = Value End Set End Property Public Property Drawing() As Boolean Get Return m_bDrawing End Get Set(ByVal Value As Boolean) m_bDrawing = Value End Set End Property Public Property CurrentTool() As DrawingTools Get Return m_eCurrentTool End Get Set(ByVal Value As DrawingTools) m_eCurrentTool = Value 'destroy the existing tool If Not oTool Is Nothing Then CType(oTool, IDisposable).Dispose() End If End Set End Property
#End Region #Region "Menu commands" Private Sub mnuFileNew_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles mnuFileNew.Click Me.oGraphics.Clear(Color.White) 'force the refresh Me.picDraw.Refresh() End Sub Private Sub mnuFileOpen_Click() If Me.dlgOpen.ShowDialog = DialogResult.OK Then Me.picDraw.Image.FromFile(Me.dlgOpen.FileName) End If End Sub Private Sub mnuFileSave_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles mnuFileSave.Click Dim sFileName As String Dim oFormat As System.Drawing.Imaging.ImageFormat 'get the filename to save to If dlgSave.ShowDialog = DialogResult.OK Then sFileName = dlgSave.FileName Select Case dlgSave.FilterIndex Case 0 'save as bitmap oFormat = System.Drawing.Imaging.ImageFormat.Bmp Case 1 'save as PNG oFormat = System.Drawing.Imaging.ImageFormat.Png Case Else 'should never happen End Select 'possible exception on save Try Me.picDraw.Image.Save(sFileName, oFormat) Catch ex As Exception 'just display for now MessageBox.Show(ex.Message, "Error saving file", _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End If End Sub Private Sub mnuFileExit_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles mnuFileExit.Click Me.Close() End Sub #End Region #Region "PictureBox Event Handlers"
Private Sub picDraw_MouseMove(ByVal sender As Object, ByVal e As System.Windows.For If Me.Drawing Then 'this is only true if the current tool is a pen
oGraphics.DrawLine(oTool, sngX, sngY, e.X, e.Y) sngX = e.X sngY = e.Y 'force a redraw Me.picDraw.Refresh() End If End Sub
Private Sub picDraw_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms 'we can stop drawing now Me.Drawing = False End Sub
Private Sub picDraw_MouseDown(ByVal sender As Object, ByVal e As System.Windows.For 'start drawing 'Shape and Text are stamps, Pen works on MouseMove 'we need to create the tool and either draw it, or get ready to draw it Select Case Me.CurrentTool Case DrawingTools.Shape Select Case Me.cboShapeType.Text Case "Rectangle" oGraphics.FillRectangle(New SolidBrush(Color.FromName(Me.cboCol e.X, _ e.Y, _ Me.updShapeWidth.Value, _ Me.updShapeHeight.Value) Case "Ellipse" oGraphics.FillEllipse(New SolidBrush(Color.FromName(Me.cboColor e.X, _ e.Y, _ Me.updShapeWidth.Value, _ Me.updShapeHeight.Value) Case Else End Select 'force a redraw Me.picDraw.Refresh() Case DrawingTools.Text 'create a font oTool = New System.Drawing.Font(Me.cboTextFont.Text, Me.updFontSize.Val 'draw the text at the current mouse location oGraphics.DrawString(Me.txtText.Text, _ oTool, New SolidBrush(Color.FromName(Me.cboColors.Text)), _ e.X, e.Y) 'force a redraw Me.picDraw.Refresh() Case DrawingTools.Pen 'create the pen (for drawing in MouseMove) oTool = New System.Drawing.Pen(Color.FromName(Me.cboColors.Text), Me.up sngX = e.X sngY = e.Y Me.Drawing = True End Select End Sub #End Region #Region "Other Event Handlers"
Private Sub frmScribble_Load(ByVal sender As Object, ByVal e As System.EventArgs) H 'set up the Color ComboBox FillLists() 'create the graphics we'll be drawing on Me.picDraw.Image = New Bitmap(picDraw.Width, picDraw.Height, System.Drawing.Ima Me.oGraphics = Graphics.FromImage(Me.picDraw.Image) 'set the background to white Me.oGraphics.Clear(Color.White) 'set the initial tool to the Pen optPen_Click(Nothing, Nothing) End Sub
Private Sub optPen_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handl 'set the tool to a pen Me.CurrentTool = DrawingTools.Pen 'hide all the other tool's panels pnlPenOptions.Visible = True pnlShapeOptions.Visible = False pnlTextOptions.Visible = False End Sub
Private Sub optShape_Click(ByVal sender As Object, ByVal e As System.EventArgs) Han 'set the tool to a Shape Me.CurrentTool = DrawingTools.Shape 'hide all the other tool's panels pnlPenOptions.Visible = False pnlShapeOptions.Visible = True pnlTextOptions.Visible = False End Sub
Private Sub optText_Click(ByVal sender As Object, ByVal e As System.EventArgs) Hand 'set the tool to Text Me.CurrentTool = DrawingTools.Text 'hide all the other tool's panels pnlPenOptions.Visible = False pnlShapeOptions.Visible = False pnlTextOptions.Visible = True End Sub #End Region #Region "Assorted methods" Private Sub FillLists() With cboColors.Items .Add("Black") .Add("Red") .Add("Green") .Add("Blue") End With cboColors.SelectedIndex = 0 With cboShapeType.Items .Add("Rectangle") .Add("Ellipse") End With cboShapeType.SelectedIndex = 0
With cboTextFont.Items .Add("Arial") .Add("Times New Roman") .Add("Courier New") End With cboTextFont.SelectedIndex = 0 End Sub #End Region End Class
public class ScribbleApplication public Shared Sub Main Application.Run(New Form1) End Sub End class Public Class Form1 Private m_Bitmap As Bitmap Private m_Graphics As Graphics Private m_Drawing As Boolean Private m_X As Integer Private m_Y As Integer Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles MyBase.Load MakeNewBitmap() End Sub Private Sub mnuFileClear_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles mnuFileClear.Click MakeNewBitmap() End Sub Private Sub MakeNewBitmap() Dim wid As Integer = picCanvas.ClientSize.Width Dim hgt As Integer = picCanvas.ClientSize.Height m_Bitmap = New Bitmap(wid, hgt) m_Graphics = Graphics.FromImage(m_Bitmap) m_Graphics.Clear(Me.BackColor)
picCanvas.Image = m_Bitmap End Sub Private Sub picCanvas_MouseDown(ByVal sender As Object, _ ByVal e As System.Windows.Forms.MouseEventArgs) Handles picCanvas.MouseDown m_Drawing = True m_X = e.X m_Y = e.Y End Sub Private Sub picCanvas_MouseMove(ByVal sender As Object, _ ByVal e As System.Windows.Forms.MouseEventArgs) Handles picCanvas.MouseMove If Not m_Drawing Then Exit Sub m_Graphics.DrawLine(Pens.Black, m_X, m_Y, e.X, e.Y) m_X = e.X m_Y = e.Y picCanvas.Image = m_Bitmap End Sub Private Sub picCanvas_MouseUp(ByVal sender As Object, _ ByVal e As System.Windows.Forms.MouseEventArgs) Handles picCanvas.MouseUp m_Drawing = False End Sub End Class <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Partial Public Class Form1 Inherits System.Windows.Forms.Form 'Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso components IsNot Nothing Then components.Dispose() End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.picCanvas = New System.Windows.Forms.PictureBox Me.MenuStrip1 = New System.Windows.Forms.MenuStrip Me.mnuFile = New System.Windows.Forms.ToolStripMenuItem Me.mnuFileClear = New System.Windows.Forms.ToolStripMenuItem CType(Me.picCanvas, System.ComponentModel.ISupportInitialize).BeginInit() Me.MenuStrip1.SuspendLayout() Me.SuspendLayout() ' 'picCanvas
' Me.picCanvas.Dock = System.Windows.Forms.DockStyle.Fill Me.picCanvas.Location = New System.Drawing.Point(0, 24) Me.picCanvas.Name = "picCanvas" Me.picCanvas.Size = New System.Drawing.Size(303, 246) Me.picCanvas.TabIndex = 0 Me.picCanvas.TabStop = False ' 'MenuStrip1 ' Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.mnuFi Me.MenuStrip1.Location = New System.Drawing.Point(0, 0) Me.MenuStrip1.Name = "MenuStrip1" Me.MenuStrip1.Size = New System.Drawing.Size(303, 24) Me.MenuStrip1.TabIndex = 1 Me.MenuStrip1.Text = "MenuStrip1" ' 'mnuFile ' Me.mnuFile.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me. Me.mnuFile.Name = "mnuFile" Me.mnuFile.Text = "&File" ' 'mnuFileClear ' Me.mnuFileClear.Name = "mnuFileClear" Me.mnuFileClear.Text = "&Clear" ' 'Form1 ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(303, 270) Me.Controls.Add(Me.picCanvas) Me.Controls.Add(Me.MenuStrip1) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle Me.MainMenuStrip = Me.MenuStrip1 Me.Name = "Form1" Me.Text = "Scribble" CType(Me.picCanvas, System.ComponentModel.ISupportInitialize).EndInit() Me.MenuStrip1.ResumeLayout(False) Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents Friend WithEvents Friend WithEvents Friend WithEvents End Class picCanvas As System.Windows.Forms.PictureBox MenuStrip1 As System.Windows.Forms.MenuStrip mnuFile As System.Windows.Forms.ToolStripMenuItem mnuFileClear As System.Windows.Forms.ToolStripMenuItem
15.13.3.Shape Painter
'Sams Teach Yourself Microsoft Visual Basic .NET 2003 in 21 Days, Second Edition (Paper 'by Steve Holzner (Author) '# Publisher: Sams; 2 edition (April 21, 2003) '# Language: English '# ISBN-10: 0672325314 '# ISBN-13: 978-0672325311 Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class PainterShape public Shared Sub Main Application.Run(New Form1) End Sub End class Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call 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 following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents Button2 As System.Windows.Forms.Button Friend WithEvents Button3 As System.Windows.Forms.Button Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents Button4 As System.Windows.Forms.Button <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button Me.Button3 = New System.Windows.Forms.Button Me.Label1 = New System.Windows.Forms.Label Me.Button4 = New System.Windows.Forms.Button Me.SuspendLayout() ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(0, 248) Me.Button1.Name = "Button1" Me.Button1.TabIndex = 0 Me.Button1.Text = "Rectangle" ' 'Button2 ' Me.Button2.Location = New System.Drawing.Point(80, 248) Me.Button2.Name = "Button2" Me.Button2.TabIndex = 1 Me.Button2.Text = "Ellipse" ' 'Button3 ' Me.Button3.Location = New System.Drawing.Point(160, 248) Me.Button3.Name = "Button3" Me.Button3.TabIndex = 2 Me.Button3.Text = "Line" ' 'Label1 ' Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 24.0!, System. Me.Label1.Location = New System.Drawing.Point(0, 0) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(152, 48) Me.Label1.TabIndex = 3 Me.Label1.Text = "Graphics" ' 'Button4 ' Me.Button4.Location = New System.Drawing.Point(240, 248) Me.Button4.Name = "Button4" Me.Button4.TabIndex = 4 Me.Button4.Text = "Freehand" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(320, 273) Me.Controls.Add(Me.Button4) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.Button3) Me.Controls.Add(Me.Button2) Me.Controls.Add(Me.Button1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False)
End Sub #End Region Dim gphFormGraphics As Graphics Dim pt1, pt2 As Point Dim ptPointsArray() As Point Dim intNumberOfPoints As Integer = 0 Dim recDrawingRectangle As Rectangle Dim btnCurrentButton As Buttons Enum Buttons Rectangle Ellipse Line Freehand End Enum Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) gphFormGraphics = Me.CreateGraphics() End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms pt1 = New Point(e.X, e.Y) End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.M pt2 = New Point(e.X, e.Y) recDrawingRectangle = New Rectangle(Math.Min(pt2.X, pt1.X), Math.Min(pt2.Y, pt1 Math.Abs(pt2.X - pt1.X), Math.Abs(pt2.Y - pt1.Y)) Select Case btnCurrentButton Case Buttons.Rectangle gphFormGraphics.DrawRectangle(Pens.Navy, recDrawingRectangle) Case Buttons.Ellipse gphFormGraphics.DrawEllipse(Pens.Navy, recDrawingRectangle) Case Buttons.Line gphFormGraphics.DrawLine(Pens.Navy, pt2, pt1) End Select End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArg btnCurrentButton = Buttons.Rectangle End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArg btnCurrentButton = Buttons.Ellipse End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArg btnCurrentButton = Buttons.Line End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArg btnCurrentButton = Buttons.Freehand End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms If btnCurrentButton = Buttons.Freehand And e.Button = MouseButtons.Left Then
Dim ptNew As New Point(e.X, e.Y) ReDim Preserve ptPointsArray(intNumberOfPoints) ptPointsArray(intNumberOfPoints) = ptNew intNumberOfPoints += 1 If intNumberOfPoints >= 2 Then gphFormGraphics.DrawLines(Pens.Navy, ptPointsArray) End If End If End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.Pai Select Case btnCurrentButton Case Buttons.Rectangle gphFormGraphics.DrawRectangle(Pens.Navy, recDrawingRectangle) Case Buttons.Ellipse gphFormGraphics.DrawEllipse(Pens.Navy, recDrawingRectangle) Case Buttons.Line gphFormGraphics.DrawLine(Pens.Navy, pt2, pt1) Case Buttons.Freehand If intNumberOfPoints >= 2 Then gphFormGraphics.DrawLines(Pens.Navy, ptPointsArray) End If End Select End Sub End Class