首页 VB20从入门到精通

VB20从入门到精通

举报
开通vip

VB20从入门到精通很多事情失败的原因不是行动前没有计划,而是缺少计划前的行动。注意力在结果上不做准备就是准备失败开大会时说大话,开小会时说小话时间可以换取空间,空间可以换取时间当动则动,当止则止民主很重要,但群体是不能做决策的将在外君令有所不受,但一定要付出代价。自己应懂得承受,但人才是不会被埋没的。人,是留不住的,即使你能把他留住在身边,也不能把他留住在人世。但能留住的是什么?(孔子去了,儒家思想却仍生生不息;牛顿走了,可三大定律依旧在为人类造福;爱迪生也走了,可夜晚再不仅是一片漆黑;)领导力是获得追随者的能力领导者的价值在于把追...

VB20从入门到精通
很多事情失败的原因不是行动前没有计划,而是缺少计划前的行动。注意力在结果上不做准备就是准备失败开大会时说大话,开小会时说小话时间可以换取空间,空间可以换取时间当动则动,当止则止民主很重要,但群体是不能做决策的将在外君令有所不受,但一定要付出代价。自己应懂得承受,但人才是不会被埋没的。人,是留不住的,即使你能把他留住在身边,也不能把他留住在人世。但能留住的是什么?(孔子去了,儒家思想却仍生生不息;牛顿走了,可三大定律依旧在为人类造福;爱迪生也走了,可夜晚再不仅是一片漆黑;)领导力是获得追随者的能力领导者的价值在于把追随者变为领导者。勇于敢则杀,勇于不敢则活(勇敢可以杀敌,但是懂得隐蔽才能保存自己,好的战士是既会冲锋又会隐蔽的)用人所长必容人所短人生很大的误区在于见到好友不交,见到名师不败一个境界低的人讲不出来高远的话,一个没有使命感的人讲不出来有责任的话,一个格局小的人,讲不出来大气的话。凡是能干大事的人都是能够坐得住的人。如果没有这么多人干扰我,哪有我做球星的价值。马拉多纳不怕念起,就怕觉迟VB2010知识宝库VB.NET常用命名空间和类介绍一、基础命名空间System.Collections包含了一些与集合相关的类型,比如列 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf ,队列,位数组,哈希表和字典等.(数据结构)System」。包含了一些数据流类型并提供了文件和目录同步异步读写System.Text包含了一些表示字符编码的类型并提供了字符串的操作和格式化System.Reflection包括了一些提供加载类型, 方法 快递客服问题件处理详细方法山木方法pdf计算方法pdf华与华方法下载八字理论方法下载 和字段的托管视图以及动态创建和调用类型功能的类型.System.Threading提供启用多线程的类和接口二、图形命名空间System.Drawing这个主要的GDI+命名空间定义了许多类型,实现基本的绘图类型(字体,钢笔,基本画笔等)和无所不能的Graphics对象.System.Drawing2D这个命名空间提供高级的二维和失量图像功能.System.Drawing」maging这个命名空间定义了一些类型实现图形图像的操作.System.Drawing.Text这个命名空间提供了操作字体集合的功能.System.Drawing.Printing这个命名空间定义了一些类型实现在打印纸上绘制图像,和打印机交互以及格式化某个打印任务的总体外观等功能.三、数据命名空间System.Data包含了数据访问使用的一些主要类型.System.Data.Common包含了各种数据库访问共享的一些类型.System.XML包含了根据 标准 excel标准偏差excel标准偏差函数exl标准差函数国标检验抽样标准表免费下载红头文件格式标准下载 来支持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.Ul.HtmIControls这个命名空间包含用于HTML特定控件的类,这些控件可以添加到Web窗体中以创建Web用户界面System.Web.Ul.WebControls包含创建ASP.NET服务器控件的类,当添加到窗体时,这些控件将呈现浏览器特定的HTML和脚本,用于创建和设备无关的Web用户界面.System.Web.Mobile包含生成ASP.NET移动应用程序所需要的核心功能,包括身份验证和错误处理.System.Web.Ul.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.自动调整窗体Publicxz,yzAsDoublePublicSubzishiying(ByVaiparentAsControl)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(MeEndSub打印文字。方法一:在窗体上打印文字DimgAsGraphics=Me.CreateGraphicsDimmBrushAsNewSolidBrush(Color.Red)DimmFontAsNewFont("宋体",18)g.DrawString("测试",mFont,mBrush,0,10)(0为横坐标,10为纵坐标)方法二:在窗体上画文字DimmAsGraphicsm=MeCreateGraphicsm.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)HandlesMeLoad'DockthePictureBoxtotheformandsetitsbackgroundtowhite.pictureBox1.Dock=DockStyle.FillpictureBoxl.BackColor=Color.White'ConnectthePainteventofthePictureBoxtotheeventhandlermethod.AddHandlerpictureBox1.Paint,AddressOfMepictureBox1_Paint'AddthePictureBoxcontroltotheForm.MeControls.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.PensRed,PictureBox1.Left,_PictureBox1.Top,PictureBox1.Right,PictureBox1.Bottom)EndSub'pictureBox1_PaintEndClass关闭窗体窗体.Dispose创建一个透明度为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()用代码在窗体添加一个按钮.Dimbutton1AsNewButton()SetthebuttontoreturnavalueofOKwhenclicked.buttonl.DialogResult=DialogResult.OK'Addthebuttontotheform.Controls.Add(button1)button1.Text=123自动生成一个窗体并创建两个按钮MyDMIogPoxCancel(点击Cancle窗体自动关闭,如果他失去焦点,他不仅会响还会晃)PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click'Createanewinstaneeoftheform.DimformlAsNewForm()'Createtwobuttonstouseastheacceptandcancelbuttons.Dimbutton1AsNewButton()Dimbutton2AsNewButton()'Setthetextofbutton1to"OK".buttonl.Text="OK"'Setthepositionofthebuttonontheform.buttonI.Location=NewPoint(10,10)'Setthetextofbutton2to"Cancel".button2.Text="Cancel"'Setthepositionofthebuttonbasedonthelocationofbutton1.button2.Location=_NewPoint(buttonI.Left,buttonI.Height+buttonI.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.forml.Controls.Add(button1)'Addbutton2totheform.forml.Controls.Add(button2)'Displaytheformasamodaldialogbox.forml.ShowDialog()EndSub演练:使用WPF 设计 领导形象设计圆作业设计ao工艺污水处理厂设计附属工程施工组织设计清扫机器人结构设计 器生成视频浏览器6.产生此效果PublicClassForm1'Createanewform.AsNewFormAsNewFormAsNewFormDimmdiChildFormDimmdiChildForm1DimmdiChildForm2PrivateSubForm1_Load(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesMyBaseLoad'SettheIsMdiContainerpropertytotrue.IsMdiContainer=True'Setthechildform'sMdiParentpropertyto'thecurrentform.TOC\o"1-5"\h\zmdiChildForm.MdiParent=MemdiChildForm1.MdiParent=MemdiChildForm2.MdiParent=MemdiChildForm.Show()mdiChildForm1.Show()mdiChildForm2.Show()mdiChildForm.Text=1mdiChildForm1.Text=2mdiChildForm2.Text=3EndSubEndClass改变窗体的背景颜色DimctlAsControlIsMdiContainer=True'Loopthroughcontrols,'lookingforcontrolsofMdiClienttype.ForEachctlInMeControlsIfTypeOf(ctl)IsMdiClientThen'Ifthecontrolisthecorrecttype,'changethecolor.Color.PaleGreenctl.BackColor=System.Drawing.EndIfNextEndSub7(2)PrivateSubForm1_Click(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesMeClickBackColor=System.Drawing.Color.PaleGreenEndSub或BackColor=Color.Blue系统颜色:GroupBox3.BackColor=Control.DefaultBackColor绘制椭圆窗体DimshapeAsNewSystem.Drawing.Drawing2D.GraphicsPathshape.AddEllipse(O,0,MeWidth,MeHeight)MeRegion=NewSystem.Drawing.Region(shape)获取当前时间'DisplaythetimeText1.Text=Now.ToLongTimeString(只有时间20:55:36)Text1.Text=Now(有日期和时间2012/1/2920:57:36)Text1.Text=Today(只有日期2012/1/29)Handles用鼠标滚轮调整窗体的透明度PrivateSubForm1_MouseWheel(ByValsenderAsObject,ByValeAsSystem.Windows.Forms.MouseEventArgs)MeMouseWheelStaticmAsIntegerIfm>1Andm<=100Ande.Delta>0Thenm=m+5ElseIfm>1Andm<=100Ande.Delta<0Thenm=m-5Elsem=100EndIfMeOpacity=m*0.01TextBox1.Text=mMeTopMost=TrueEndSub绝对坐标Control.MousePosition.X-25Control.MousePosition.YControl.MousePosition相对坐标.e.Xe.Y13.调用窗体的Paint事件Melnvalidate()禁用窗体的关闭按钮PublicClassFormlPrivateDeclareFunctionGetSystemMenuLib"User32"(ByValhwndAsInteger,ByValbRevertAsInteger)AsIntegerPrivateAsInteger)PrivateDeclareFunctionRemoveMenLib"User32"(ByValhMenuAsInteger,ByValnPositionAsInteger,ByValwFlagsAsIntegerDeclareFunctionDrawMenuBarLib"User32"(ByValhwndAsInteger)AsIntegerPrivatePrivateDeclareFunctionGetMenultemCountLib"User32"(ByValhMenuAsInteger)AsIntegerConstMF_BYPOSITION=&H400&PrivateConstMF_DISABLED=&H2&PrivateSubdisableX(ByValwndAsForm)DimhMenuAsInteger,nCountAsInteger'得到系统MenuhMenu=GetSystemMenu(wnd.Handle.ToInt32,0)'得到系统Meni的个数nCount=GetMenultemCount(hMenu)'去除系统MenuOrMF_DISABLED)CallRemoveMenu(hMenu,nCount-1,MF_BYPOSITION重画MenuBarDrawMenuBar(MeHandle.ToInt32)EndSubPrivatedisableX(EndSubSubButton1_Click(senderMe'屏蔽关闭按钮AsSystem.Object,eAsSystem.EventArgs)HandlesButton1.ClickPrivateSubButton2_Click(senderAsSystem.Object,eAsSystem.EventArgs)HandlesButton2.ClickMeMaximizeBox=False'屏蔽最大化按钮EndSubPrivateSubButton3_Click(senderAsSystem.Object,eAsSystem.EventArgs)HandlesButton3.ClickMeMinimizeBox=False'屏蔽最小化按钮EndSubEndClass移动窗体PublicClassForm1Dimx%,y%PrivateSubLabel1_MouseDown(senderAsObject,eAsSystem.Windows.Forms.MouseEventArgs)HandlesLabel1.MouseDownx=e.Xy=e.YTimer1.Enabled=TrueEndSubSubyidong()MeLeft=Control.MousePosition.X-Labell.Left-x-9MeTop=Control.MousePosition.Y-Labell.Top-36-yEndSubPrivateSubLabel1_MouseUp(senderAsObject,eAsSystem.Windows.Forms.MouseEventArgs)HandlesLabel1.MouseUpTimer1.Enabled=FalseEndSubEndClass最小化窗体MeWindowState=System.Windows.Forms.FormWindowState.Minimized'最小化窗体在窗体的指定位置截取指定的形状PrivateSubForm1_Paint(senderAsObject,eAsSystem.Windows.Forms.PaintEventArgs)HandlesMePaint'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))MeRegion=NewRegion(myPath)EndSub17.完全透明效果■[B?]MeBackColor=Color.WhiteMeTransparencyKey=Color.WhiteButtonl五二澤I'无程;互vsnetElIDE中E先蛊称》后iit(Lsjr-yutEir.^.ial)>-;turcL'F>IN't^idthAejntrjTTLightMidf0r-?BuLtciiliEickiAjItitE-£eJ-PublicClassForm1PublicStructureMARGINSPubliccxLeftWidthAsIntegerPubliccxRightWidthAsIntegerPubliccyTopHeightAsIntegerPubliccyButtomheightAsIntegerEndStructurePublicSharedFunctionDwmExtendFramelntoClientArea(ByValhWndAsIntPtr,ByRefpMarinsetAsMARGIN)SAsIntegerEndFunctionPrivateSubButton1_Click(senderAsSystem.Object,eAsSystem.EventArgs)HandlesButton1.ClickMeTransparencyKey=Color.FromArgb(255,255,1)MeBackColor=MeTransparencyKeyDimmarginsAsMARGINSNewMARGINSmargins.cxLeftWidth=-1margins.cxRightWidth=-1margins.cyTopHeight=-1margins.cyButtomheight=-1DwmExtendFrameIntoClientArea(MeHandle,margins)EndSubEndClass毛玻璃效果ImportsSystem.Runtime.lnteropServicesPublicClassForm1'Vista与Windows7中的Aero界面是它们最吸引人的新功能之一,它可以实现大面积的透明界面。但是我们在编程中却不能完全利用这个功能。虽然VB.Net2005以后的控件已经开始支持XF和Vista的风格了,但是窗体的界面却无法完全实现Aero的毛玻璃效果,只有最外面的一层窗口标题栏是透明的。网上确实有关于如何用.Net语言来实现这一效果的,但那是C#,而不是VB.Net。要VB.Net语言来实现?在网上找不到。难道为了这个功能非得去学C#才行吗?虽然网上有将C#弋码转换为VB.Net代码,但它要求完整的代码结构,而网上提供的往往只是一段代码,并不是完整的一个Class,所以也难实现。本文将讲述如何用vb.net做这个界面。'Aero毛玻璃界面之所以无法在vb.net的IDE中直接使用,是因为它是Vista和Win7专有的功能,XF是不可能实现的。这个功能被放在了Vista和Win7的系统目录中的一个API库中,它就是DWMAPI.DLL所以如果我们要做这种窗口,首先要调用这个API。'在程序开头导入这个,否则会出错'声明函数和必要的类型,在Class<类名称>后面输入StructLayout(LayoutKind.Sequential)>_PublicStructureMARGINSPubliccxLeftWidthAsIntegerPubliccxRightWidthAsIntegerPubliccyTopHeightAsIntegerPubliccyButtomheightAsIntegerEndStructureDllImport("dwmapi.dll")>_PublicSharedFunctionDwmExtendFramelntoClientArea(ByValhWndAsIntPtr,ByRefpMarinsetAsMARGIN)SAsIntegerEndFunctionPrivateSubButton2_Click(senderAsSystem.Object,eAsSystem.EventArgs)HandlesButton2.ClickMeTransparencyKey=Color.FromArgb(255,255,1)MeBackColor=MeTransparencyKeyDimmarginsAsMARGINSNewMARGINSmargins.cxLeftWidth=-1margins.cxRightWidth=-1margins.cyTopHeight=-1margins.cyButtomheight=-1DwmExtendFrameIntoClientArea(EndSubMeHandle,margins)EndClass二.系统事件0.系统监控ImportsSystem.IOPrivateSubFileSystemWatcher1_Changed(senderAsObject,eAsSystem.IO.FileSystemEventArgs)HandlesFileSystemWatcher1.ChangedFileSystemWatcher1.NotifyFilter=IO.NotifyFilters丄astWritelujing=e.FullPath.ToStringEndSub1.系统睡觉System.Threading.Thread.SIeep(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=Truemnulabel4Left=e.X+MeLeft+(Label4)对象丄eft+8mnulabel4.Top=e.Y+MeTop+(Label4)对象.Top+35EndSub4.dll文件的调用vb.net如何引用C++写DLL文件?及函数的调用方法?C++函数如下:boolwinapiconnectplayserver(char*address,DWORDPort,DWORDDataPart,char*Usernamepublicdeclarefuncitontestlib"你的dll名字"(byrefpxasxtest,byvalx,byvaly)publicdeclarefuncitontestlib"你的dll名字"(byrefpxasxtest,byvalx,byvaly)vb.net引用C++写DLL文件及函数的方法?PrivateSharedFunctionConnectPlayServer(ByValAddressAsString,ByVaiPortAsInteger,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里你要写一个同样的结构PublicStructurextestPublicaAsStringPublicbAsStringEndStructure三•对话框打开文件'SettheOpendialogpropertiesWithOpenFileDialogl.Filter="TextDocuments(*.txt)|*.txt|AIIFiles(**)|**".FilterIndex=1.Title="打开文件"EndWith'ShowtheOpendialogandiftheuserclickstheOpenbutton,'loadthefileIfOpenFileDialog1.ShowDialog=Windows.Forms.DialogResult.OKThen或IfOpenFileDialog1.ShowDialog=Windows.Forms.DialogResult.CancelThenTry'SavethefilepathandnamestrFileName=OpenFileDialog1.FileNameDimfileContentsAsStringfileContents=MyComputer.FileSystem.ReadAllText(strFileName)'DisplaythefilecontentsinthetextboxText1.Text=fileContentsCatchexAsExceptionMessageBoxShow(ex.Message,MyApplication.lnfo.Title,_MessageBoxButtons.OK,MessageBoxIcon.Error)EndTryEndIf或获取文件的绝对路径OpenFileDialog1.ShowDialog()AxShockwaveFlash1.Movie=OpenFileDialog1.FileName保存文件WithSaveFileDialogl'获?取…?或八设|••…置?默?认…?文?件t的[扩O?展1名?.DefaultExt="txt".FileName=strFileName'文?件t类型二筛|?选?Files(*.*)|*.*".Filter="TextDocuments(*.txt)|*.txt|AII.FilterIndex=1如…?果?用??户?[指?定?§的[文?件t名?已°?存??在T另C••存??为aM?话??框八显?示o?警?¥告?.OverwritePrompt=True.Title="文件另存为"EndWith'ShowtheSavedialogandiftheuserclickstheSavebutton,'savethefile.OKIfSaveFileDialog1.ShowDialog=Windows.Forms.DialogResultThenTry'SavethefilepathandnamestrFileName=SaveFileDialog1.FileNameMyComputer.FileSystem.WriteAllText(strFileName,txtFile.Text,False)CatchexAsExceptionMessageBoxShow(ex.Message,MyApplication.lnfo.Title,_MessageBoxButtons.OK,MessageBoxIcon.Error)EndTryEndIf浏览文件(只选择在哪个具体的文件夹下)FolderBrowserDialog1.ShowDialog()FileSystemWatcher1.Path=FolderBrowserDialog1.SelectedPathEndIfEndIf弹出字体、颜色对话框一、字体'SettheFontdialogpropertiesFontDialogl.ShowColor=True'ShowtheFontdialogandiftheuserclickstheOKbutton,'updatethefontandcolorinthetextbox.OKThen.OKThenIfFontDialog1.ShowDialog=Windows.Forms.DialogResult(txtFile.Font)对象.Font=FontDialog1.FonttxtFile.ForeColor=FontDialog1.ColorEndIf二、颜色'ShowtheColordialogandiftheuserclickstheOKbutton,'updatethebackgroundcoloroftheformIfColorDialog1.ShowDialog=Windows.Forms.DialogResult(MeBackColor)对象.属性=ColorDialog1.ColorEndIf打印'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()EndIf浏览硬盘文件'SettheFolderBrowserdialogpropertiesWithFolderBrowserDialogl.Description="Selectabackupfolder".RootFolder=Environment.SpecialFolder.MyComputer.ShowNewFolderButton=FalseEndWith'ShowtheFolderBrowserdialogandiftheuserclicksthe'OKbutton,displaytheselectedfolderIfFolderBrowserDialog1.ShowDialog=Windows.Forms.DialogResult.OKThen(txtFile.Text)对象.属性=FolderBrowserDialog1.SelectedPathEndIfMessageBox对话框的弹出并获取返回值使用方法:一设置焦点型If(MessageBoxShow(”此操作将永久性删除所有空文件夹”&vbCrLf&”是否希望查看被保护的文件夹?","温馨提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2)=Windows.Forms.DialogResult.Yes)ThenCallScanFolder11(TextBox1.Text,5)ElseExitSubEndIfIf(MessageBoxShow("内容","标题",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=MessageBoxShow(Me,Message,Caption,MessageBoxButtons.YesNo)'GetstheresultoftheMessageBoxdisplay.IfResult=System.Windows.Forms.DialogResult.YesThen'Closestheparentform.MeClose()EndIfEndIfEndSub四•控件文本框操作清空文本框内容'ClearthetextboxesTextBox1.Text=String.Empt设置焦点'SetfocustothefirsttextboxTextBox1.Focus()撤销(Ctrl+Z'UndothelastoperationIfTypeOfMeActiveControlIsTextBoxThenCType(MeActiveControl,TextBox).Undo()4.剪切(Ctrl+X)加调用PrivateSubCutToolStripMenultem_Click(ByVaisenderAsObject,ByVaieAsSystem.EventArgs)HandiesCutToolStripMenultem.Click'CopythetexttotheclipboardandclearthefieldIfTypeOfMeActiveControlIsTextBoxThenCType(MeActiveControl,TextBox).Cut()EndIfEndSub选中文本(复制的新方法)'Takestheselectedtextfromatextboxandputsitontheclipboard.IfTextBoxl.SelectedText<>""ThenClipboard.SetDataObject(TextBoxl.SelectedText)ElseTextBox2.Text="NotextselectedintextBoxl"EndIf粘贴的新方法'DeclaresanIDataObjecttoholdthedatareturnedfromtheclipboard.'Retrievesthedatafromtheclipboard.DimiDataAsIDataObject=Clipboard.GetDataObject()'Determineswhetherthedataisinaformatyoucanuse.IfiData.GetDataPresent(DataFormats.Text)ThenString)'Yesitis,sodisplayitinatextbox.TextBox2.Text=CType(iData.GetData(DataFormats.Text),Else'Noitisnot.TextBox2.Text="Couldnotretrievedataofftheclipboard."EndIf全部选中一、出现右键菜单If(e.Button=Windows.Forms.MouseButtons.Right)ThenTextBox1.Select(0,TextBoxl.Text丄ength)EndIf二、不出现右键菜单TextBoxl.ContextMenu=NewContextMenu()If(e.Button=Windows.Forms.MouseButtons.Right)ThenTextBox1.Select(0,TextBoxl.Text丄ength)EndIf复制(Ctrl+C
本文档为【VB20从入门到精通】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
个人认证用户
天方夜谭
暂无简介~
格式:doc
大小:581KB
软件:Word
页数:51
分类:
上传时间:2022-03-01
浏览量:0