




已阅读5页,还剩141页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
VB2013 知识宝库VB.NET常用命名空间和类介绍一、基础命名空间System.Collections包含了一些与集合相关的类型,比如列表,队列,位数组,哈希表和字典等. (数据结构)System.IO包含了一些数据流类型并提供了文件和目录同步异步读写.System.Text包含了一些表示字符编码的类型并提供了字符串的操作和格式化System.Reflection包括了一些提供加载类型,方法和字段的托管视图以及动态创建和调用类型功能的类型.System.Threading提供启用多线程的类和接口二、图形命名空间System.Drawing这个主要的命名空间定义了许多类型,实现基本的绘图类型(字体,钢笔,基本画笔等)和无所不能的Graphics对象System.Drawing2D这个命名空间提供高级的二维和失量图像功能System.Drawing.Imaging这个命名空间定义了一些类型实现图形图像的操作System.Drawing.Text这个命名空间提供了操作字体集合的功能System.Drawing.Printing这个命名空间定义了一些类型实现在打印纸上绘制图像,和打印机交互以及格式化某个打印任务的总体外观等功能三、数据命名空间System.Data包含了数据访问使用的一些主要类型 System.Data.Common包含了各种数据库访问共享的一些类型 System.XML包含了根据标准来支持处理的类System.Data.OleDb包含了一些操作OLEDB数据源的类型 System.Data.Sql能使你枚举安装在当前本地网络的SQLServer实例System.Data.SqlClient包含了一些操作MSSQLServer数据库的类型,提供了和System.Data.OleDb相似的功能,但是针对SQL做了优化(优化后的SQL操作类库)System.Data.SqlTypes提供了一些表示SQL数据类型的类System.Data.Odbc包含了操作Odbc数据源的类型System.Data.OracleClient包含了操作Odbc数据库的类型System.Transactions这个命名空间提供了编写事务性应用程序和资源管理器的一些类四、WEB命名空间System.Web这个命名空间包含启用浏览器/服务器通信的类和接口.这些命名空间类用于管理到客户端的HTTP输出和读取HTTP请求.附加的类则提供了一些功能,用于服务器端的应用程序以及进程,Cookie管理,文件传输,异常信息和输出缓存的控制.System.Web.UI这个命名空间包含Web窗体的类,包括Page类和用于创建Web用户界面的其他标准类.System.Web.UI.HtmlControls这个命名空间包含用于HTML特定控件的类,这些控件可以添加到Web窗体中以创建Web用户界面System.Web.UI.WebControls包含创建ASP.NET服务器控件的类,当添加到窗体时,这些控件将呈现浏览器特定的HTML和脚本,用于创建和设备无关的Web用户界面.System.Web.Mobile包含生成ASP.NET移动应用程序所需要的核心功能,包括身份验证和错误处理.System.Web.UI.MobileControls包括一组ASP.NET服务器控件,这些控件可以针对不同的移动设备呈现应用程序.System.Web.Services包含能使你使用和生成XMLWebService的类,这些服务是驻留在服务器中的可编程实体,并通过标准Internet协议公开.五、框架服务命名空间System.Diagnostics这个命名空间所提供的类允许你启动系统进程,读取和写入事件日志以及使用性能计数器监视系统性能.System.DirectoryServices这个命名空间所提供的类可便于从托管代码中访问ActiveDirectory.此命名空间中的类可以与任何ActiveDirectory服务提供程序一起使用.System.Media包含用于播放声音文件和访问系统提供的声音的类.System.Management这个命名空间提供的类用于管理一些信息和事件,它们关系到系统,设备和WMI基础结构所使用的应用程序.System.Messaging这个命名空间提供的类用于连接到网络上的消息队列,向队列发送消息,从队列接收或查看消息.System.ServiceProcess这个命名空间提供的类用于安装和运行服务,服务是长期运行的可执行文件,它们不通过用户界面来运行.System.Timers这个命名空间提供基于服务器的计时器组件,用以按指定的间隔引发事件.六、安全性命名空间System.Security这个命名空间提供公共语言运行库安全性系统的基础结构.System.Net.Security这个命名空间提供用于主机间安全通信的网络流.System.Web.Security这个命名空间包含的类用于在Web应用程序中实现ASP.NET安全性.七、网络命名空间System.Net包含的类可为当前网络上的多种协议提供简单的编程接口.System.Net.Cache这个命名空间定义了一些类和枚举,用于为使用WebRequest和HttpWebRequest类获取的资源定义缓存策略.System.Net.Configuration这个命名空间包含了以编程方式访问和更新System.Net命名空间的配置设置的类.System.Net.Mime这个命名空间包含了用于将电子邮件发送到SMTP服务器进行传送的类.System.Net.Networkinformation这个命名空间提供对网络流量数据,网络地址信息和本地计算机的地址更改通知的访问,还包含实现Ping实用工具的类.你可以使用Ping和相关的类来检查是否可通过网络访问某台计算机.System.Net.Sockets这个命名空间为严格控制网络访问的开发人员提供Windows套接字接口的托管实现八、配置命名空间System.Configuration这个命名空间包含用于以编程方式访问.NetFramework配置设置并处理配置文件中错误的类.System.Configuration.Assemblies这个命名空间包含用于配置程序集的类.System.Configuration.Provider这个命名空间包含由服务器和客户端应用程序共享,以支持可插接式模型轻松添加或移除功能的基类.九、本地化命名空间System.Globalization包含的类定义与区域性相关的信息,其中包括语言,国家地区,所使用的日历,日期格式的模式,货币与数字以及字符串的排序顺序.System.Resources这个命名空间提供一些类和接口,它们使开发人员得以创建,存储并管理应用程序中使用的各种区域性特定资源.System.Resources.Tools这个命名空间包含StronglyTypedResourceBuilder类,该类提供对强类型资源的支持.这个编译时功能通过创建包含一组静态只读属性的类封装对资源的访问,从而使得使用资源变得更加容易一.窗体事件1.打印文字。方法一:在窗体上打印文字 Dim g As Graphics = Me.CreateGraphics Dim mBrush As New SolidBrush(Color.Red) Dim mFont As New Font(宋体, 18) g.DrawString(测试, mFont, mBrush, 0, 10)(0 为横坐标,10 为纵坐标)方法二:在窗体上画文字 Dim m As Graphics m = Me.CreateGraphics m.DrawString(This is a diagonal line drawn on the control, _ New Font(Arial, 10), Brushes.Gold, New PointF(300.0F, 444.0F) m.Dispose()方法三:在图片框上打印文字Public Class Form2 This example creates a PictureBox control on the form and draws to it. This example assumes that the Form_Load event handler method is connected to the Load eventof the form. Private pictureBox1 As New PictureBox() Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dock the PictureBox to the form andset its background to white. pictureBox1.Dock = DockStyle.Fill pictureBox1.BackColor = Color.White Connect the Paint eventof the PictureBox to the event handler method. AddHandler pictureBox1.Paint, AddressOf Me.pictureBox1_Paint Add the PictureBox control to the Form. Me.Controls.Add(pictureBox1) End Sub Form1_Load00:00:03.9522260 Private Sub pictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Create a local version of the graphics objectfor the PictureBox. Dim g As Graphics = e.Graphics Draw a stringon the PictureBox. g.DrawString(This is a diagonal line drawn on the control, _ New Font(Arial, 10), Brushes.Red, New PointF(30.0F, 30.0F) Draw a line in the PictureBox. g.DrawLine(System.Drawing.Pens.Red, PictureBox1.Left, _ PictureBox1.Top, PictureBox1.Right, PictureBox1.Bottom) End Sub pictureBox1_PaintEnd Class2.关闭窗体窗体.Dispose3. 创建一个透明度为75%的窗体 Private Sub CreateMyOpaqueForm() Create a new form. Dim form2 As New Form() Set the text displayed in the caption. form2.Text = My Form Set the opacity to 75%. form2.Opacity = 0.75 Size the form to be 300 pixels in height and width. form2.Size = New Size(300, 300) Display the form in the center of the screen. form2.StartPosition = FormStartPosition.CenterScreen Display the form as a modal dialog box. form2.ShowDialog()4用代码在窗体添加一个按钮. Dim button1 As New Button() Set the button to return a value of OK when clicked. button1.DialogResult = DialogResult.OK Add the button to the form. Controls.Add(button1) button1.Text = 1235.自动生成一个窗体并创建两个按钮(点击Cancle窗体自动关闭,如果他失去焦点,他不仅会响还会晃)Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Create a new instance of the form. Dim form1 As New Form() Create two buttons to use as the accept and cancel buttons. Dim button1 As New Button() Dim button2 As New Button() Set the text of button1 to OK. button1.Text = OK Set the position of the button on the form. button1.Location = New Point(10, 10) Set the text of button2 to Cancel. button2.Text = Cancel Set the position of the button based on the location of button1. button2.Location = _ New Point(button1.Left, button1.Height + button1.Top + 10) Set the caption bar text of the form. form1.Text = My Dialog Box Display a help button on the form. form1.HelpButton = True Define the border style of the form to a dialog box. form1.FormBorderStyle = FormBorderStyle.FixedDialog Set the MaximizeBox to false to remove the maximize box. form1.MaximizeBox = False Set the MinimizeBox to false to remove the minimize box. form1.MinimizeBox = False Set the accept button of the form to button1. form1.AcceptButton = button1 Set the cancel button of the form to button2. form1.CancelButton = button2 Set the start position of the form to the center of the screen. form1.StartPosition = FormStartPosition.CenterScreen Add button1 to the form. form1.Controls.Add(button1) Add button2 to the form. form1.Controls.Add(button2) Display the form as a modal dialog box. form1.ShowDialog()End Sub演练:使用 WPF 设计器生成视频浏览器6.产生此效果 Public Class Form1 Create a new form. Dim mdiChildForm As New Form Dim mdiChildForm1 As New Form Dim mdiChildForm2 As New Form Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.Load Set the IsMdiContainer property to true. IsMdiContainer = True Set the child forms MdiParent property to the current form. mdiChildForm.MdiParent = Me mdiChildForm1.MdiParent = Me mdiChildForm2.MdiParent = Me mdiChildForm.Show() mdiChildForm1.Show() mdiChildForm2.Show() mdiChildForm.Text = 1 mdiChildForm1.Text = 2 mdiChildForm2.Text = 3 End SubEnd Class7. 改变窗体的背景颜色Dim ctl As Control IsMdiContainer = True Loop through controls, looking for controls of MdiClient type. For Each ctl In Me.Controls If TypeOf (ctl) Is MdiClient Then If the control is the correct type, change the color. ctl.BackColor = System.Drawing.Color.PaleGreen End If Next End Sub7(2) Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click BackColor = System.Drawing.Color.PaleGreen End Sub或BackColor= Color.Blue系统颜色:GroupBox3.BackColor = Control.DefaultBackColor8.绘制椭圆窗体 Dim shape As New System.Drawing.Drawing2D.GraphicsPath shape.AddEllipse(0, 0, Me.Width, Me.Height) Me.Region = New System.Drawing.Region(shape)9.获取当前时间Display the time Text1.Text = Now.ToLongTimeString (只有时间 20 :55 :36) Text1.Text = Now (有日期和时间 2012/1/29 20 :57 :36)Text1.Text = Today (只有日期 2012/1/29)10.用鼠标滚轮调整窗体的透明度Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel Static m As Integer If m 1 And m 0 Then m = m + 5 ElseIf m 1 And m = 100 And e.Delta 0 Then m = m - 5 Else m = 100 End If Me.Opacity = m * 0.01 TextBox1.Text = m Me.TopMost = True End Sub11.绝对坐标Control.MousePosition.X - 25 Control.MousePosition.YControl.MousePosition12.相对坐标.e.X e.Y13.调用窗体的Paint事件Me.Invalidate() 14. 禁用窗体的关闭按钮Public Class Form1 Private Declare Function GetSystemMenu Lib User32 (ByVal hwnd As Integer, ByVal bRevert As Integer) As Integer Private Declare Function RemoveMenu Lib User32 (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer Private Declare Function DrawMenuBar Lib User32 (ByVal hwnd As Integer) As Integer Private Declare Function GetMenuItemCount Lib User32 (ByVal hMenu As Integer) As Integer Private Const MF_BYPOSITION = &H400& Private Const MF_DISABLED = &H2& Private Sub disableX(ByVal wnd As Form) Dim hMenu As Integer, nCount As Integer 得到系统Menu hMenu = GetSystemMenu(wnd.Handle.ToInt32, 0) 得到系统Menu的个数 nCount = GetMenuItemCount(hMenu) 去除系统Menu Call RemoveMenu(hMenu, nCount - 1, MF_BYPOSITION Or MF_DISABLED) 重画MenuBar DrawMenuBar(Me.Handle.ToInt32) End Sub Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click disableX(Me) 屏蔽关闭按钮 End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click Me.MaximizeBox = False 屏蔽最大化按钮 End Sub Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click Me.MinimizeBox = False 屏蔽最小化按钮 End SubEnd Class15.移动窗体Public Class Form1 Dim x%, y% Private Sub Label1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseDown x = e.X y = e.Y Timer1.Enabled = True End Sub Sub yidong() Me.Left = Control.MousePosition.X - Label1.Left - x - 9 Me.Top = Control.MousePosition.Y - Label1.Top - 36 - y End Sub Private Sub Label1_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseUp Timer1.Enabled = False End SubEnd Class16.最小化窗体 Me.WindowState = System.Windows.Forms.FormWindowState.Minimized 最小化窗体17.在窗体的指定位置截取指定的形状 Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Create a GraphicsPath object and add a rectangle to it. Dim myPath As New System.Drawing.Drawing2D.GraphicsPath() Dim pathRect As New Rectangle(0, 0, 100, 200) myPath.AddRectangle(pathRect) Draw the path to the screen. Dim myPen As New Pen(Color.Black, 2) e.Graphics.DrawPath(myPen, myPath) myGraphicsPath.AddEllipse(New Rectangle(0, 0, 200, 450) Me.Region = New Region(myPath) End Sub二.系统事件0.系统监控Imports System.IOPrivate Sub FileSystemWatcher1_Changed(sender As Object, e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Changed FileSystemWatcher1.NotifyFilter = IO.NotifyFilters.LastWrite lujing = e.FullPath.ToString End Sub1.系统睡觉System.Threading.Thread.Sleep(9000) 2.调用.exe程序1.指定路径: i = Shell(E:vb2013.exe, 1)2.相对路径: i = Shell(定时关机.exe, 1) (直接弹出) i = Shell(定时关机.exe, 2) (直接隐藏在任务栏) i = Shell(定时关机.exe,3) (以最大化方式弹出)3.右键菜单的弹出 Private Sub Label4_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label4.MouseClick If e.Button = Windows.Forms.MouseButtons.Right Then mnulabel4.Visible = True mnulabel4.Left = e.X + Me.Left +( Label4)对象.Left + 8 mnulabel4.Top = e.Y + Me.Top +( Label4)对象.Top + 35 End Sub4.dll文件的调用如何引用C+写DLL文件?及函数的调用方法?C+函数如下:bool winapi connectplayserver( char* address, DWORD Port, DWORD DataPart, char* Username)引用C+写DLL文件及函数的方法? Private Shared Function ConnectPlayServer(ByVal Address As String, ByVal Port As Integer, ByVal DataPort As Integer, ByVal Username As String) As Boolean End FunctionPrivate Declare Auto Function a Lib Lib.dll (ByVal i As Integer) As String例如:Typedef struct xtestchar a100;char b100;*px;_declspec(dllexport) void _stdcall test (*px,char *x,char *y);void _stdcall test (*px,char *x,char *y)if(strlen(x)100) *(x+99)=0;if(strlen(y)100)*(y+99)=0;strcpy(px-a,x);strcpy(px-b,y);return;在vb里你要写一个同样的结构 Public Structure xtest Public a As String Public b As String End Structurepublic declare funciton test lib你的dll名字 (byref px as xtest,byval x,byval y)三对话框1.打开文件Set the Open dialog properties With OpenFileDialog1 .Filter = Text Documents (*.txt)|*.txt|All Files (*.*)|*.* .FilterIndex = 1 .Title = 打开文件 End With Show the Open dialog and if the user clicks the Open button, load the file If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then或 If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then Try Save the file path and name strFileName = OpenFileDialog1.FileName Dim fileContents As String fileContents = My.Computer.FileSystem.ReadAllText(strFileName) Display the file contents in the text box Text1.Text = fileContents Catch ex As Exception MessageBox.Show(ex.Message, My.Application.Info.Title, _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End If或获取文件的绝对路径OpenFileDialog1.ShowDialog() AxShockwaveFlash1.Movie = OpenFileDialog1.FileName2.保存文件 With SaveFileDialog1 获?取?或设置?默?认?文?件t的?扩?展1名? .DefaultExt = txt .FileName = strFileName 文?件t类型筛?选? .Filter = Text Documents (*.txt)|*.txt|All Files (*.*)|*.* .FilterIndex = 1 如?果?用?户指?定的?文?件t名?已?存?在另存?为a对?话框显?示?警告? .OverwritePrompt = True .Title = 文件另存为 End With Show the Save dialog and if the user clicks the Save button, save the file If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then Try Save the file path and name strFileName = SaveFileDialog1.FileName My.Computer.FileSystem.WriteAllText(strFileName, txtFile.Text, False) Catch ex As Exception MessageBox.Show(ex.Message, My.Application.Info.Title, _ MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End If3.浏览文件(只选择在哪个具体的文件夹下) FolderBrowserDialog1.ShowDialog() FileSystemWatcher1.Path = FolderBrowserDialog1.SelectedPath4.弹出字体、颜色对话框一、字体Set the Font dialog properties FontDialog1.ShowColor = True Show the Font dialog and if the user clicks the OK button, update the font and color in the text box If FontDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then ( txtFile.Font)对象.Font = FontDialog1.Font txtFile.ForeColor = FontDialog1.Color End If二、颜色 Show the Color dialog and if the user clicks the OK button, update the background color of the form If ColorDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then ( Me.BackColor)对象.属性= ColorDialog1.Color End If5.打印Instantiat
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【正版授权】 ISO/IEC 6523-2:2025 EN Information technology - Structure for the identification of organizations and organization parts - Part 2: Registration of organization identificatio
- 课件模板老师说课
- 旅行的蜗牛课件
- 拖鞋创意画课件
- 技能培训助理面试
- 电影《找到你》解析课件
- 中班课堂游戏课件
- 历年化学考试题及答案
- 广东关于自考试题及答案
- 老年自考试题及答案
- 岁儿童行为量表CBCL
- 汽车起重机吊装专项施工方案
- 2讲-良肢位摆放课件
- 2022年枣庄专业人员继续教育公需课答案
- 踝关节镜技术PPT
- 妊娠合并心脏病及课件
- 私募股权投资基金激励制度(包含募资奖励、投成奖励、退出奖励等)
- 现代写作教程全套课件
- 幸福中国一起走总谱图片格式-总谱
- 2022版《语文课程标准》
- 机械优化设计完整版PPT课件.ppt
评论
0/150
提交评论