第 12 章 创建程序的可视外观 ——Windows Form 编程基础. 用户界面是在用户运行程序时所看到的程序部分。用户界面通常由一个主窗口或窗体以及若干个控件(如按钮、用于输入文本的字段等)组成。这些 Visual Basic 程序类型称为 Windows Form 应用程序,并且使用 Windows 窗体控件来创建用户界面。
An Image/Link below is provided (as is) to download presentation
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.Content is provided to you AS IS for your information and personal use only.Download presentation by click this link.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.During download, if you can't get a presentation, the file might be deleted by the publisher.
KeyDown事件的事件处理过程,以TextBox控件为例,代码如下。KeyDown事件的事件处理过程,以TextBox控件为例,代码如下。 • 1 Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown • 2 • 3 End Sub
编写该控件的LinkClicked事件处理过程。 • 1 Private Sub lnkSingleLink_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lnkSingleLink.LinkClicked • 2 lnkSingleLink.LinkVisited = True • 3 System.Diagnostics.Process.Start ("http://mail.163.com") • 4 End Sub
1 Public Class Form1 2 Private num As Integer = 0 3 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 4 num += 1 5 MessageBox.Show("Clicked me " & num & " times!") 6 End Sub 7 8 Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter 9 Button1.ForeColor = Color.Red 10 End Sub 11 12 Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave 13 Button1.ForeColor = Color.Black 14 End Sub 15 End Class
下面代码演示了在文本框中实现使用键盘组合键实现复制、剪切和粘贴操作。下面代码演示了在文本框中实现使用键盘组合键实现复制、剪切和粘贴操作。 1 Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown 2 If e.Control And e.KeyData = Keys.C Then 3 TextBox1.Copy( ) 4 End If 5 If e.Control And e.KeyData = Keys.X Then 6 TextBox1.Cut( ) 7 End If 8 If e.Control And e.KeyData = Keys.V Then 9 TextBox1.Paste( ) 10 End If 11 If e.Control And e.KeyData = Keys.A Then 12 TextBox1.SelectAll( ) 13 End If 14 End Sub
下面代码演示了使用Label控件显示当前选定的文本。下面代码演示了使用Label控件显示当前选定的文本。 1 Private Sub TextBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseMove 2 If e.Button = Windows.Forms.MouseButtons.Left Then 3 Label1.Text = "当前选中的文本为:" & TextBox1.SelectedText 4 End If 5 End Sub