VB2010从入门到精通.docx_第1页
VB2010从入门到精通.docx_第2页
VB2010从入门到精通.docx_第3页
VB2010从入门到精通.docx_第4页
VB2010从入门到精通.docx_第5页
已阅读5页,还剩162页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

很多事情失败的原因不是行动前没有计划,而是缺少计划前的行动。注意力在结果上不做准备就是准备失败开大会时说大话,开小会时说小话时间可以换取空间,空间可以换取时间当动则动,当止则止民主很重要,但群体是不能做决策的将在外君令有所不受,但一定要付出代价。自己应懂得承受,但人才是不会被埋没的。人,是留不住的,即使你能把他留住在身边,也不能把他留住在人世。但能留住的是什么?(孔子去了,儒家思想却仍生生不息;牛顿走了,可三大定律依旧在为人类造福;爱迪生也走了,可夜晚再不仅是一片漆黑;)领导力是获得追随者的能力领导者的价值在于把追随者变为领导者。勇于敢则杀,勇于不敢则活(勇敢可以杀敌,但是懂得隐蔽才能保存自己,好的战士是既会冲锋又会隐蔽的)用人所长必容人所短人生很大的误区在于见到好友不交,见到名师不败。一个境界低的人讲不出来高远的话,一个没有使命感的人讲不出来有责任的话,一个格局小的人,讲不出来大气的话。凡是能干大事的人都是能够坐得住的人。如果没有这么多人干扰我,哪有我做球星的价值。-马拉多纳不怕念起,就怕觉迟。VB2010 知识宝库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类,该类提供对强类型资源的支持.这个编译时功能通过创建包含一组静态只读属性的类封装对资源的访问,从而使得使用资源变得更加容易一. 窗体事件0. 自动调整窗体 Public xz, yz As Double Public Sub zishiying(ByVal parent As Control) xz = 75 / Form5.Button1.Width yz = 23 / Form5.Button1.Height Dim sFont As Font For Each c As Control In parent.Controls Dim zihao As Integer = c.Font.Size * xz / 1.2 1 sFont = New Font(c.Font.FontFamily, zihao, c.Font.Style) c.Font = sFont c.Width = c.Width * xz c.Height = c.Height * yz c.Left = c.Left * xz c.Top = c.Top * yz zishiying(c) Next End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click zishiying(Me) End Sub1.打印文字。方法一:在窗体上打印文字 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 Sub17.完全透明效果Me.BackColor = Color.White Me.TransparencyKey = Color.White或Public Class Form1 Public Structure MARGINS Public cxLeftWidth As Integer Public cxRightWidth As Integer Public cyTopHeight As Integer Public cyButtomheight As Integer End Structure Public Shared Function DwmExtendFrameIntoClientArea(ByVal hWnd As IntPtr, ByRef pMarinset As MARGINS) As Integer End Function Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click Me.TransparencyKey = Color.FromArgb(255, 255, 1) Me.BackColor = Me.TransparencyKey Dim margins As MARGINS = New MARGINS margins.cxLeftWidth = -1 margins.cxRightWidth = -1 margins.cyTopHeight = -1 margins.cyButtomheight = -1 DwmExtendFrameIntoClientArea(Me.Handle, margins) End SubEnd Class18.毛玻璃效果Imports System.Runtime.InteropServicesPublic Class Form1 Vista与Windows 7中的Aero界面是它们最吸引人的新功能之一,它可以实现大面积的透明界面。但是我们在编程中却不能完全利用这个功能。虽然VB.Net 2005以后的控件已经开始支持XP和Vista的风格了,但是窗体的界面却无法完全实现Aero的毛玻璃效果,只有最外面的一层窗口标题栏是透明的。网上确实有关于如何用.Net语言来实现这一效果的,但那是C#,而不是VB.Net。要VB.Net语言来实现?在网上找不到。难道为了这个功能非得去学C#才行吗?虽然网上有将C#代码转换为VB.Net代码,但它要求完整的代码结构,而网上提供的往往只是一段代码,并不是完整的一个Class,所以也难实现。本文将讲述如何用做这个界面。 Aero毛玻璃界面之所以无法在的IDE中直接使用,是因为它是Vista和Win7专有的功能,XP是不可能实现的。这个功能被放在了Vista和Win7的系统目录中的一个API库中,它就是DWMAPI.DLL.所以如果我们要做这种窗口,首先要调用这个API。 在程序开头导入这个,否则会出错 声明函数和必要的类型,在Class 后面输入 _ Public Structure MARGINS Public cxLeftWidth As Integer Public cxRightWidth As Integer Public cyTopHeight As Integer Public cyButtomheight As Integer End Structure _ Public Shared Function DwmExtendFrameIntoClientArea(ByVal hWnd As IntPtr, ByRef pMarinset As MARGINS) As Integer End Function Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click Me.TransparencyKey = Color.FromArgb(255, 255, 1) Me.BackColor = Me.TransparencyKey Dim margins As MARGINS = New MARGINS margins.cxLeftWidth = -1 margins.cxRightWidth = -1 margins.cyTopHeight = -1 margins.cyButtomheight = -1 DwmExtendFrameIntoClientArea(Me.Handle, margins) End SubEnd Class二.系统事件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:vb2010.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 Fu

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论