为了正常的体验网站,请在浏览器设置里面开启Javascript功能!
首页 > VB2010完美代码库

VB2010完美代码库

2022-07-10 7页 doc 1MB 21阅读

用户头像 个人认证

is_767976

暂无简介

举报
VB2010完美代码库VB2010知识宝库VB.NET常用命名空间和类介绍一、基础命名空间System.Collections包含了一些与集合相关的类型,比如列表,队列,位数组,哈希表和字典等.(数据结构)System.IO包含了一些数据流类型并提供了文件和目录同步异步读写.System.Text包含了一些表示字符编码的类型并提供了字符串的操作和格式化System.Reflection包括了一些提供加载类型,方法和字段的托管视图以及动态创建和调用类型功能的类型.System.Threading提供启用多线程的类和接口...
VB2010完美代码库
VB2010知识宝库VB.NET常用命名空间和类介绍一、基础命名空间System.Collections包含了一些与集合相关的类型,比如列表,队列,位数组,哈希表和字典等.(数据结构)System.IO包含了一些数据流类型并提供了文件和目录同步异步读写.System.Text包含了一些表示字符编码的类型并提供了字符串的操作和格式化System.Reflection包括了一些提供加载类型,方法和字段的托管视图以及动态创建和调用类型功能的类型.System.Threading提供启用多线程的类和接口二、图形命名空间System.Drawing这个主要的GDI+命名空间定义了许多类型,实现基本的绘图类型(字体,钢笔,基本画笔等)和无所不能的Graphics对象.System.Drawing2D这个命名空间提供高级的二维和失量图像功能.System.Drawing.Imaging这个命名空间定义了一些类型实现图形图像的操作.System.Drawing.Text这个命名空间提供了操作字体集合的功能.System.Drawing.Printing这个命名空间定义了一些类型实现在打印纸上绘制图像,和打印机交互以及格式化某个打印任务的总体外观等功能.三、数据命名空间System.Data包含了数据访问使用的一些主要类型.System.Data.Common包含了各种数据库访问共享的一些类型.System.XML包含了根据来支持XML处理的类.System.Data.OleDb包含了一些操作OLEDB数据源的类型.System.Data.Sql能使你枚举安装在当前本地网络的SQL Server实例.System.Data.SqlClient包含了一些操作MS SQL Server数据库的类型,提供了和 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包含能使你使用和生成XML Web Service的类,这些服务是驻留在服务器中的 可编程实体,并通过标准Internet协议公开.五、框架服务命名空间System.Diagnostics这个命名空间所提供的类允许你启动系统进程,读取和写入事件日志以及使用性 能计数器监视系统性能.System.DirectoryServices这个命名空间所提供的类可便于从托管代码中访问Active Directory.此命名空 间中的类可以与任何Active Directory服务提供程序一起使用.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这个命名空间包含用于以编程方式访问.Net Framework配置设置并处理配置 文件中错误的类.System.Configuration.Assemblies这个命名空间包含用于配置程序集的类.System.Configuration.Provider这个命名空间包含由服务器和客户端应用程序共享,以支持可插接式模型轻松添 加或移除功能的基类.九、本地化命名空间System.Globalization包含的类定义与区域性相关的信息,其中包括语言,国家\地区,所使用的日历,日期 格式的模式,货币与数字以及字符串的排序顺序.System.Resources这个命名空间提供一些类和接口,它们使开发人员得以创建,存储并管理应用程 序中使用的各种区域性特定资源.System.Resources.Tools这个命名空间包含StronglyTypedResourceBuilder类,该类提供对强类型资源 的支持.这个编译时功能通过创建包含一组静态只读属性的类封装对资源的访问, 从而使得使用资源变得更加容易窗体事件自动调整窗体Publicxz,yzAsDoublePublicSubzishiying(ByValparentAsControl)xz=75/Form5.Button1.Widthyz=23/Form5.Button1.HeightDimsFontAsFontForEachcAsControlInparent.ControlsDimzihaoAsInteger=c.Font.Size*xz/1.2\1sFont=NewFont(c.Font.FontFamily,zihao,c.Font.Style)c.Font=sFontc.Width=c.Width*xzc.Height=c.Height*yzc.Left=c.Left*xzc.Top=c.Top*yzzishiying(c)NextEndSubPrivateSubButton2_Click(senderAsSystem.Object,eAsSystem.EventArgs)HandlesButton2.Clickzishiying(Me)EndSub1.打印文字。方法一:在窗体上打印文字DimgAsGraphics=Me.CreateGraphicsDimmBrushAsNewSolidBrush(Color.Red)DimmFontAsNewFont("宋体",18)g.DrawString("测试",mFont,mBrush,0,10)(0为横坐标,10为纵坐标)方法二:在窗体上画文字DimmAsGraphicsm=Me.CreateGraphicsm.DrawString("Thisisadiagonallinedrawnonthecontrol",_NewFont("Arial",10),Brushes.Gold,NewPointF(300.0F,444.0F))m.Dispose()方法三:在图片框上打印文字PublicClassForm2'ThisexamplecreatesaPictureBoxcontrolontheformanddrawstoit.'ThisexampleassumesthattheForm_Loadeventhandlermethodisconnected'totheLoadeventoftheform.PrivatepictureBox1AsNewPictureBox()PrivateSubForm1_Load(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesMe.Load'DockthePictureBoxtotheformandsetitsbackgroundtowhite.pictureBox1.Dock=DockStyle.FillpictureBox1.BackColor=Color.White'ConnectthePainteventofthePictureBoxtotheeventhandlermethod.AddHandlerpictureBox1.Paint,AddressOfMe.pictureBox1_Paint'AddthePictureBoxcontroltotheForm.Me.Controls.Add(pictureBox1)EndSub'Form1_Load00:00:03.9522260PrivateSubpictureBox1_Paint(ByValsenderAsObject,ByValeAsSystem.Windows.Forms.PaintEventArgs)'CreatealocalversionofthegraphicsobjectforthePictureBox.DimgAsGraphics=e.Graphics'DrawastringonthePictureBox.g.DrawString("Thisisadiagonallinedrawnonthecontrol",_NewFont("Arial",10),Brushes.Red,NewPointF(30.0F,30.0F))'DrawalineinthePictureBox.g.DrawLine(System.Drawing.Pens.Red,PictureBox1.Left,_PictureBox1.Top,PictureBox1.Right,PictureBox1.Bottom)EndSub'pictureBox1_PaintEndClass2.关闭窗体窗体.Dispose3.创建一个透明度为75%的窗体PrivateSubCreateMyOpaqueForm()'Createanewform.Dimform2AsNewForm()'Setthetextdisplayedinthecaption.form2.Text="MyForm"'Settheopacityto75%.form2.Opacity=0.75'Sizetheformtobe300pixelsinheightandwidth.form2.Size=NewSize(300,300)'Displaytheforminthecenterofthescreen.form2.StartPosition=FormStartPosition.CenterScreen'Displaytheformasamodaldialogbox.form2.ShowDialog()4.用代码在窗体添加一个按钮.Dimbutton1AsNewButton()'SetthebuttontoreturnavalueofOKwhenclicked.button1.DialogResult=DialogResult.OK'Addthebuttontotheform.Controls.Add(button1)button1.Text=1235.自动生成一个窗体并创建两个按钮(点击Cancle窗体自动关闭,如果他失去焦点,他不仅会响还会晃)PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click'Createanewinstanceoftheform.Dimform1AsNewForm()'Createtwobuttonstouseastheacceptandcancelbuttons.Dimbutton1AsNewButton()Dimbutton2AsNewButton()'Setthetextofbutton1to"OK".button1.Text="OK"'Setthepositionofthebuttonontheform.button1.Location=NewPoint(10,10)'Setthetextofbutton2to"Cancel".button2.Text="Cancel"'Setthepositionofthebuttonbasedonthelocationofbutton1.button2.Location=_NewPoint(button1.Left,button1.Height+button1.Top+10)'Setthecaptionbartextoftheform.form1.Text="MyDialogBox"'Displayahelpbuttonontheform.form1.HelpButton=True'Definetheborderstyleoftheformtoadialogbox.form1.FormBorderStyle=FormBorderStyle.FixedDialog'SettheMaximizeBoxtofalsetoremovethemaximizebox.form1.MaximizeBox=False'SettheMinimizeBoxtofalsetoremovetheminimizebox.form1.MinimizeBox=False'Settheacceptbuttonoftheformtobutton1.form1.AcceptButton=button1'Setthecancelbuttonoftheformtobutton2.form1.CancelButton=button2'Setthestartpositionoftheformtothecenterofthescreen.form1.StartPosition=FormStartPosition.CenterScreen'Addbutton1totheform.form1.Controls.Add(button1)'Addbutton2totheform.form1.Controls.Add(button2)'Displaytheformasamodaldialogbox.form1.ShowDialog()EndSub演练:使用WPF设计器生成视频浏览器6.产生此效果PublicClassForm1'Createanewform.DimmdiChildFormAsNewFormDimmdiChildForm1AsNewFormDimmdiChildForm2AsNewFormPrivateSubForm1_Load(ByValsenderAsObject,_ByValeAsSystem.EventArgs)HandlesMyBase.Load'SettheIsMdiContainerpropertytotrue.IsMdiContainer=True'Setthechildform'sMdiParentpropertyto'thecurrentform.mdiChildForm.MdiParent=MemdiChildForm1.MdiParent=MemdiChildForm2.MdiParent=MemdiChildForm.Show()mdiChildForm1.Show()mdiChildForm2.Show()mdiChildForm.Text=1mdiChildForm1.Text=2mdiChildForm2.Text=3EndSubEndClass7.改变窗体的背景颜色DimctlAsControlIsMdiContainer=True'Loopthroughcontrols,'lookingforcontrolsofMdiClienttype.ForEachctlInMe.ControlsIfTypeOf(ctl)IsMdiClientThen'Ifthecontrolisthecorrecttype,'changethecolor.ctl.BackColor=System.Drawing.Color.PaleGreenEndIfNextEndSub7(2)PrivateSubForm1_Click(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesMe.ClickBackColor=System.Drawing.Color.PaleGreenEndSub或BackColor=Color.Blue系统颜色:GroupBox3.BackColor=Control.DefaultBackColor8.绘制椭圆窗体DimshapeAsNewSystem.Drawing.Drawing2D.GraphicsPathshape.AddEllipse(0,0,Me.Width,Me.Height)Me.Region=NewSystem.Drawing.Region(shape)9.获取当前时间'DisplaythetimeText1.Text=Now.ToLongTimeString(只有时间20:55:36)Text1.Text=Now(有日期和时间2012/1/2920:57:36)Text1.Text=Today(只有日期2012/1/29)10.用鼠标滚轮调整窗体的透明度PrivateSubForm1_MouseWheel(ByValsenderAsObject,ByValeAsSystem.Windows.Forms.MouseEventArgs)HandlesMe.MouseWheelStaticmAsIntegerIfm>1Andm<=100Ande.Delta>0Thenm=m+5ElseIfm>1Andm<=100Ande.Delta<0Thenm=m-5Elsem=100EndIfMe.Opacity=m*0.01TextBox1.Text=mMe.TopMost=TrueEndSub11.绝对坐标Control.MousePosition.X-25Control.MousePosition.YControl.MousePosition12.相对坐标.e.Xe.Y13.调用窗体的Paint事件Me.Invalidate()14.禁用窗体的关闭按钮PublicClassForm1PrivateDeclareFunctionGetSystemMenuLib"User32"(ByValhwndAsInteger,ByValbRevertAsInteger)AsIntegerPrivateDeclareFunctionRemoveMenuLib"User32"(ByValhMenuAsInteger,ByValnPositionAsInteger,ByValwFlagsAsInteger)AsIntegerPrivateDeclareFunctionDrawMenuBarLib"User32"(ByValhwndAsInteger)AsIntegerPrivateDeclareFunctionGetMenuItemCountLib"User32"(ByValhMenuAsInteger)AsIntegerPrivateConstMF_BYPOSITION=&H400&PrivateConstMF_DISABLED=&H2&PrivateSubdisableX(ByValwndAsForm)DimhMenuAsInteger,nCountAsInteger'得到系统MenuhMenu=GetSystemMenu(wnd.Handle.ToInt32,0)'得到系统Menu的个数nCount=GetMenuItemCount(hMenu)'去除系统MenuCallRemoveMenu(hMenu,nCount-1,MF_BYPOSITIONOrMF_DISABLED)'重画MenuBarDrawMenuBar(Me.Handle.ToInt32)EndSubPrivateSubButton1_Click(senderAsSystem.Object,eAsSystem.EventArgs)HandlesButton1.ClickdisableX(Me)'屏蔽关闭按钮EndSubPrivateSubButton2_Click(senderAsSystem.Object,eAsSystem.EventArgs)HandlesButton2.ClickMe.MaximizeBox=False'屏蔽最大化按钮EndSubPrivateSubButton3_Click(senderAsSystem.Object,eAsSystem.EventArgs)HandlesButton3.ClickMe.MinimizeBox=False'屏蔽最小化按钮EndSubEndClass15.移动窗体PublicClassForm1Dimx%,y%PrivateSubLabel1_MouseDown(senderAsObject,eAsSystem.Windows.Forms.MouseEventArgs)HandlesLabel1.MouseDownx=e.Xy=e.YTimer1.Enabled=TrueEndSubSubyidong()Me.Left=Control.MousePosition.X-Label1.Left-x-9Me.Top=Control.MousePosition.Y-Label1.Top-36-yEndSubPrivateSubLabel1_MouseUp(senderAsObject,eAsSystem.Windows.Forms.MouseEventArgs)HandlesLabel1.MouseUpTimer1.Enabled=FalseEndSubEndClass16.最小化窗体Me.WindowState=System.Windows.Forms.FormWindowState.Minimized'最小化窗体17.在窗体的指定位置截取指定的形状PrivateSubForm1_Paint(senderAsObject,eAsSystem.Windows.Forms.PaintEventArgs)HandlesMe.Paint'CreateaGraphicsPathobjectandaddarectangletoit.DimmyPathAsNewSystem.Drawing.Drawing2D.GraphicsPath()DimpathRectAsNewRectangle(0,0,100,200)myPath.AddRectangle(pathRect)'Drawthepathtothescreen.DimmyPenAsNewPen(Color.Black,2)e.Graphics.DrawPath(myPen,myPath)'myGraphicsPath.AddEllipse(NewRectangle(0,0,200,450))Me.Region=NewRegion(myPath)EndSub17.完全透明效果Me.BackColor=Color.WhiteMe.TransparencyKey=Color.White或PublicClassForm1PublicStructureMARGINSPubliccxLeftWidthAsIntegerPubliccxRightWidthAsIntegerPubliccyTopHeightAsIntegerPubliccyButtomheightAsIntegerEndStructurePublicSharedFunctionDwmExtendFrameIntoClientArea(ByValhWndAsIntPtr,ByRefpMarinsetAsMARGINS)AsIntegerEndFunctionPrivateSubButton1_Click(senderAsSystem.Object,eAsSystem.EventArgs)HandlesButton1.ClickMe.TransparencyKey=Color.FromArgb(255,255,1)Me.BackColor=Me.TransparencyKeyDimmarginsAsMARGINS=NewMARGINSmargins.cxLeftWidth=-1margins.cxRightWidth=-1margins.cyTopHeight=-1margins.cyButtomheight=-1DwmExtendFrameIntoClientArea(Me.Handle,margins)EndSubEndClass18.毛玻璃效果ImportsSystem.Runtime.InteropServicesPublicClassForm1'Vista与Windows7中的Aero界面是它们最吸引人的新功能之一,它可以实现大面积的透明界面。但是我们在编程中却不能完全利用这个功能。虽然VB.Net2005以后的控件已经开始支持XP和Vista的风格了,但是窗体的界面却无法完全实现Aero的毛玻璃效果,只有最外面的一层窗口标栏是透明的。网上确实有关于如何用.Net语言来实现这一效果的,但那是C#,而不是VB.Net。要VB.Net语言来实现?在网上找不到。难道为了这个功能非得去学C#才行吗?虽然网上有将C#代码转换为VB.Net代码,但它要求完整的代码结构,而网上提供的往往只是一段代码,并不是完整的一个Class,所以也难实现。本文将讲述如何用vb.net做这个界面。'Aero毛玻璃界面之所以无法在vb.net的IDE中直接使用,是因为它是Vista和Win7专有的功能,XP是不可能实现的。这个功能被放在了Vista和Win7的系统目录中的一个API库中,它就是DWMAPI.DLL.所以如果我们要做这种窗口,首先要调用这个API。'在程序开头导入这个,否则会出错'声明函数和必要的类型,在Class<类名称>后面输入_PublicStructureMARGINSPubliccxLeftWidthAsIntegerPubliccxRightWidthAsIntegerPubliccyTopHeightAsIntegerPubliccyButtomheightAsIntegerEndStructure_PublicSharedFunctionDwmExtendFrameIntoClientArea(ByValhWndAsIntPtr,ByRefpMarinsetAsMARGINS)AsIntegerEndFunctionPrivateSubButton2_Click(senderAsSystem.Object,eAsSystem.EventArgs)HandlesButton2.ClickMe.TransparencyKey=Color.FromArgb(255,255,1)Me.BackColor=Me.TransparencyKeyDimmarginsAsMARGINS=NewMARGINSmargins.cxLeftWidth=-1margins.cxRightWidth=-1margins.cyTopHeight=-1margins.cyButtomheight=-1DwmExtendFrameIntoClientArea(Me.Handle,margins)EndSubEndClass二.系统事件0.系统监控ImportsSystem.IOPrivateSubFileSystemWatcher1_Changed(senderAsObject,eAsSystem.IO.FileSystemEventArgs)HandlesFileSystemWatcher1.ChangedFileSystemWatcher1.NotifyFilter=IO.NotifyFilters.LastWritelujing=e.FullPath.ToStringEndSub1.系统睡觉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.右键菜单的弹出PrivateSubLabel4_MouseClick(ByValsenderAsObject,ByValeAsSystem.Windows.Forms.MouseEventArgs)HandlesLabel4.MouseClickIfe.Button=Windows.Forms.MouseButtons.RightThenmnulabel4.Visible=Truemnulabel4.Left=e.X+Me.Left+(Label4)对象.Left+8mnulabel4.Top=e.Y+Me.Top+(Label4)对象.Top+35EndSub4.dll文件的调用vb.net如何引用C++写DLL文件?及函数的调用方法?C++函数如下:boolwinapiconnectplayserver(char*address,DWORDPort,DWORDDataPart,char*Username)vb.net引用C++写DLL文件及函数的方法?PrivateSharedFunctionConnectPlayServer(ByValAddressAsString,ByValPortAsInteger,ByValDataPortAsInteger,ByValUsernameAsString)AsBooleanEndFunctionPrivateDeclareAutoFunctionaLib\"Lib.dll\"(ByValiAsInteger)AsString例如:Typedefstructxtest{chara[100];charb[100];}*px;__declspec(dllexport)void__stdcalltest(*px,char*x,char*y);void__stdcalltest(*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里你要写一个同样的结构PublicStructurextestPublicaAsStringPublicbAsStringEndStructurepublicdeclarefuncitontestlib"你的dll名字"(byrefpxasxtest,byvalx,byvaly)三.对话框1.打开文件'SettheOpendialogpropertiesWithOpenFileDialog1.Filter="TextDocuments(*.txt)|*.txt|AllFiles(*.*)|*.*".FilterIndex=1.Title="打开文件"EndWith'ShowtheOpendialogandiftheuserclickstheOpenbutton,'loadthefileIfOpenFileDialog1.ShowDialog=Windows.Forms.DialogResult.OKThen或IfOpenFileDialog1.ShowDialog=Windows.Forms.DialogResult.CancelThenTry'SavethefilepathandnamestrFileName=OpenFileDialog1.FileNameDimfileContentsAsStringfileContents=My.Computer.FileSystem.ReadAllText(strFileName)'DisplaythefilecontentsinthetextboxText1.Text=fileContentsCatchexAsExceptionMessageBox.Show(ex.Message,My.Application.Info.Title,_MessageBoxButtons.OK,MessageBoxIcon.Error)EndTryEndIf或获取文件的绝对路径OpenFileDialog1.ShowDialog()AxShockwaveFlash1.Movie=OpenFileDialog1.FileName2.保存文件WithSaveFileDialog1'获?取¨?或¨°设¦¨¨置?默?认¨?文?件t的Ì?扩¤?展1名?.DefaultExt="txt".FileName=strFileName'文?件t类¤¨¤型¨ª筛¦?选?.Filter="TextDocuments(*.txt)|*.txt|AllFiles(*.*)|*.*".FilterIndex=1'如¨?果?用®?户¡ì指?定¡§的Ì?文?件t名?已°?存ä?在¨²另¢¨ª存ä?为a对?话¡ã框¨°显?示º?警¡¥告?.OverwritePrompt=True.Title="文件另存为"EndWith'ShowtheSavedialogandiftheuserclickstheSavebutton,'savethefileIfSaveFileDialog1.ShowDialog=Windows.Forms.DialogResult.OKThenTry'SavethefilepathandnamestrFileName=SaveFileDialog1.FileNameMy.Computer.FileSystem.WriteAllText(strFileName,txtFile.Text,False)CatchexAsExceptionMessageBox.Show(ex.Message,My.Application.Info.Title,_MessageBoxButtons.OK,MessageBoxIcon.Error)EndTryEndIf3.浏览文件(只选择在哪个具体的文件夹下)FolderBrowserDialog1.ShowDialog()FileSystemWatcher1.Path=FolderBrowserDialog1.SelectedPath4.弹出字体、颜色对话框一、字体'SettheFontdialogpropertiesFontDialog1.ShowColor=True'ShowtheFontdialogandiftheuserclickstheOKbutton,'updatethefontandcolorinthetextboxIfFontDialog1.ShowDialog=Windows.Forms.DialogResult.OKThen(txtFile.Font)对象.Font=FontDialog1.FonttxtFile.ForeColor=FontDialog1.ColorEndIf二、颜色'ShowtheColordialogandiftheuserclickstheOKbutton,'updatethebackgroundcoloroftheformIfColorDialog1.ShowDialog=Windows.Forms.DialogResult.OKThen(Me.BackColor)对象.属性=ColorDialog1.ColorEndIf5.打印'InstantiateanewinstanceofthePrintDocumentDialogsPrintDocument=NewPrintDocument'SetthePrintDialogpropertiesWithPrintDialog1.AllowCurrentPage=False.AllowPrintToFile=False.AllowSelection=False.AllowSomePages=False.Document=DialogsPrintDocument.PrinterSettings.DefaultPageSettings.Margins.Top=25.PrinterSettings.DefaultPageSettings.Margins.Bottom=25.PrinterSettings.DefaultPageSettings.Margins.Left=25.PrinterSettings.DefaultPageSettings.Margins.Right=25EndWithIfPrintDialog1.ShowDialog=DialogResult.OKThen'SettheselectedprintersettingsinthePrintDocumentDialogsPrintDocument.PrinterSettings=_PrintDialog1.PrinterSettings'GettheprintdatastrPrintRecord=txtFile.Text'InvokethePrintmethodonthePrintDocumentDialogsPrintDocument.Print()EndIf6.浏览硬盘文件'SettheFolderBrowserdialogpropertiesWithFolderBrowserDialog1.Description="Selectabackupfolder".RootFolder=Environment.SpecialFolder.MyComputer.ShowNewFolderButton=FalseEndWith'ShowtheFolderBrowserdialogandiftheuserclicksthe'OKbutton,displaytheselectedfolderIfFolderBrowserDialog1.ShowDialog=Windows.Forms.DialogResult.OKThen(txtFile.Text)对象.属性=FolderBrowserDialog1.SelectedPathEndIf7.MessageBox对话框的弹出并获取返回值使用方法:一设置焦点型If(MessageBox.Show("此操作将永久性删除所有空文件夹"&vbCrLf&"是否希望查看被保护的文件夹?","温馨提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2)=Windows.Forms.DialogResult.Yes)ThenCallScanFolder11(TextBox1.Text,5)ElseExitSubEndIfIf(MessageBox.Show("","标题",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning)=Windows.Forms.DialogResult.OK)ThenEndIf使用方法:二PrivateSubValidateUserEntry5()'Checksthevalueofthetext.IfTextBox1.Text.Length=0Then'InitializesvariablestopasstotheMessageBox.Showmethod.DimMessageAsString="Youdidnotenteraservername.Cancelthisoperation?"DimCaptionAsString="NoServerNameSpecified"DimButtonsAsInteger=MessageBoxButtons.YesNoDimResultAsDialogResult'DisplaysaMessageBoxusingtheQuestioniconandspecifyingtheNobuttonasthedefault.Result=MessageBox.Show(Me,Message,Caption,MessageBoxButtons.YesNo)'GetstheresultoftheMessageBoxdisplay.IfResult=System.Windows.Forms.DialogResult.YesThen'Closestheparentform.Me.Close()EndIfEndIfEndSub四.控件1.文本框操作1.清空文本框内容'ClearthetextboxesTextBox1.Text=String.Empt2.设置焦点'SetfocustothefirsttextboxTextBox1.Focus()3.撤销(Ctrl+Z)'UndothelastoperationIfTypeOfMe.ActiveControlIsTextBoxThenCType(Me.ActiveControl,TextBox).Undo()EndIf4.剪切(Ctrl+X)加调用PrivateSubCutToolStripMenuItem_Click(ByValsenderAsObject,_ByValeAsSystem.EventArgs)HandlesCutToolStripMenuItem.Click'CopythetexttotheclipboardandclearthefieldIfTypeOfMe.ActiveControlIsTextBoxThenCType(Me.ActiveControl,TextBox).Cut()EndIfEndSub5.选中文本(复制的新方法)'Takestheselectedtextfromatextboxandputsitontheclipboard.IfTextBox1.SelectedText<>""ThenClipboard.SetDataObject(TextBox1.SelectedText)ElseTextBox2.Text="NotextselectedintextBox1"EndIf6.粘贴的新方法'DeclaresanIDataObjecttoholdthedatareturnedfromtheclipboard.'Retrievesthedatafromtheclipboard.DimiDataAsIDataObject=Clipboard.GetDataObject()'Determineswhetherthedataisinaformatyoucanuse.IfiData.GetDataPresent(DataFormats.Text)Then'Yesitis,sodisplayitinatextbox.TextBox2.Text=CType(iData.GetData(DataFormats.Text),String)Else'Noitisnot.TextBox2.Text="Couldnotretrievedataofftheclipboard."EndIf7.全部选中一、出现右键菜单If(e.Button=Windows.Forms.MouseButtons.Right)ThenTextBox1.Select(0,TextBox1.Text.Length)EndIf二、不出现右键菜单TextBox1.ContextMenu=NewContextMenu()If(e.Button=Windows.Forms.MouseButtons.Right)ThenTextBox1.Select(0,TextBox1.Text.Length)EndIf8.复制(Ctrl+C)'CopythetexttotheclipboardIfTypeOfMe.ActiveControlIsTextBoxThenCType(Me.ActiveControl,TextBox).Copy()EndIf9.粘贴(Ctrl+V)从剪切板中还原文件'CopythetextfromtheclipboardtothetextboxIfTypeOfMe.ActiveControlIsTextBoxThenCType(Me.ActiveControl,TextBox).Paste()EndIf2.ListBox'AddanemptystringtotheListBoxlstData.Items.Add(String.Empty)1.将列表框ListBox1中的文件保存在"E:\2.text"中PrivateSubButton3_Click(senderAsSystem.Object,eAsSystem.EventArgs)HandlesButton3.ClickDimobjfile1AsNewSystem.IO.StreamWriter("E:\2.text")DimintcounterAsLong=ListBox1.Items.CountForintcounter=0ToListBox1.
/
本文档为【VB2010完美代码库】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索