当前位置:K88软件开发文章中心编程语言.NET.NET02 → 文章内容

VB.Net - 高级表单

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-15 15:59:10

由 yiyohunter 创建,youj 最后一次修改 2016-12-12 在本章中,我们将研究以下概念: 在应用程序中添加菜单和子菜单在表单中添加剪切,复制和粘贴功能锚定和对接控制在一种形式模态形式在应用程序中添加菜单和子菜单传统上,Menu,MainMenu,ContextMenu和MenuItem类用于在Windows应用程序中添加菜单,子菜单和上下文菜单。现在,MenuStrip,ToolStripMenuItem,ToolStripDropDown和ToolStripDropDownMenu控件替换和添加功能到以前版本的菜单相关的控件。 但是,旧的控制类保留为向后兼容和未来使用。让我们首先使用旧版本控件创建典型的Windows主菜单栏和子菜单,因为这些控件在旧应用程序中仍然很常用。以下是一个示例,显示了如何使用菜单项创建菜单栏:文件,编辑,视图和项目。 文件菜单有子菜单新建,打开和保存。让我们双击窗体,并在打开的窗口中放下面的代码。 Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'defining the main menu bar Dim mnuBar As New MainMenu() 'defining the menu items for the main menu bar Dim myMenuItemFile As New MenuItem("&File") Dim myMenuItemEdit As New MenuItem("&Edit") Dim myMenuItemView As New MenuItem("&View") Dim myMenuItemProject As New MenuItem("&Project") 'adding the menu items to the main menu bar mnuBar.MenuItems.Add(myMenuItemFile) mnuBar.MenuItems.Add(myMenuItemEdit) mnuBar.MenuItems.Add(myMenuItemView) mnuBar.MenuItems.Add(myMenuItemProject) ' defining some sub menus Dim myMenuItemNew As New MenuItem("&New") Dim myMenuItemOpen As New MenuItem("&Open") Dim myMenuItemSave As New MenuItem("&Save") 'add sub menus to the File menu myMenuItemFile.MenuItems.Add(myMenuItemNew) myMenuItemFile.MenuItems.Add(myMenuItemOpen) myMenuItemFile.MenuItems.Add(myMenuItemSave) 'add the main menu to the form Me.Menu = mnuBar ' Set the caption bar text of the form. Me.Text = "tutorialspoint.com" End SubEnd Class当使用Microsoft Visual Studio工具栏上的“开始”按钮执行并运行上述代码时,将显示以下窗口: Windows窗体包含一组丰富的类,用于创建您自己的具有现代外观,外观和感觉的自定义菜单。 MenuStrip,ToolStripMenuItem,ContextMenuStrip控件用于有效地创建菜单栏和上下文菜单。点击以下链接查看他们的详细信息:S.N.Control & Description1MenuStripIt provides a menu system for a form.它为表单提供了一个菜单系统。2ToolStripMenuItemIt represents a selectable option displayed on a MenuStrip orContextMenuStrip. The ToolStripMenuItem control replaces and adds functionality to the MenuItem control of previous versions.它表示在MenuStrip或ContextMenuStrip上显示的可选选项。 ToolStripMenuItem控件替换和添加以前版本的MenuItem控件的功能。2ContextMenuStripIt represents a shortcut menu.它代表一个快捷菜单。在表单中添加剪切,复制和粘贴功能ClipBoard类公开的方法用于在应用程序中添加剪切,复制和粘贴功能。 ClipBoard类提供了在系统剪贴板上放置数据和检索数据的方法。它有以下常用的方法: SN方法名称和说明1 ClearRemoves all data from the Clipboard. 删除从剪贴板中的所有数据。 2 ContainsData Indicates whether there is data on the Clipboard that is in the specified format or can be converted to that format.指示是否有上是在指定的格式或可转换成此格式的剪贴板中的数据。 3 ContainsImage Indicates whether there is data on the Clipboard that is in the Bitmap format or can be converted to that format.指示是否有关于那就是在Bitmap格式或可转换成该格式剪贴板数据。 4 ContainsText Indicates whether there is data on the Clipboard in the Text or UnicodeText format, depending on the operating system.指示是否在文本或UnicodeText格式剪贴板中的数据,根据不同的操作系统。 5GetData Retrieves data from the Clipboard in the specified format.从指定格式的剪贴板中检索数据。 6 GetDataObject Retrieves the data that is currently on the system Clipboard.检索是目前系统剪贴板中的数据。 7getImage Retrieves an image from the Clipboard.检索从剪贴板中的图像。 8getText Retrieves text data from the Clipboard in the Text or UnicodeText format, depending on the operating system.从文本或UnicodeText格式剪贴板中检索文本数据,根据不同的操作系统。 9getText(TextDataFormat) Retrieves text data from the Clipboard in the format indicated by the specified TextDataFormat value.从由指定TextDataFormat值指示的格式剪贴板中检索文本数据。 10 SetDataClears the Clipboard and then adds data in the specified format.清除剪贴板,然后以指定的格式将数据添加。 11setText(String) Clears the Clipboard and then adds text data in the Text or UnicodeText format, depending on the operating system.清除剪贴板,然后添加在文本或UnicodeText格式的文本数据,根据不同的操作系统。 以下是一个示例,其中显示了如何使用Clipboard类的方法剪切,复制和粘贴数据。 执行以下步骤: 在表单上添加丰富的文本框控件和三个按钮控件。 将按钮的文本属性分别更改为“剪切”,“复制”和“粘贴”。 双击按钮,在代码编辑器中添加以下代码: Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) _ Handles MyBase.Load ' Set the caption bar text of the form. Me.Text = "tutorialspoint.com" End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) _ Handles Button1.Click Clipboard.SetDa

[1] [2]  下一页


VB.Net - 高级表单