快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

vb.net新建组件类的简单介绍

VB.NET 如何动态添加组件,如FileSystemWatcher,并且响应同一事件?

For Each i In My.Computer.FileSystem.Drives

成都创新互联公司成立于2013年,先为察布查尔锡伯等服务建站,察布查尔锡伯等地企业,进行企业商务咨询服务。为察布查尔锡伯企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

Dim FSW As New FileSystemWatcher

FSW.NotifyFilter = NotifyFilters.FileName

FSW.Path = i.Name.ToString

FSW.Filter = "*.txt"

AddHandler FSW.Changed, AddressOf FileSystemWatcher1_Changed '与FileSystemWatcher1_Changed事件绑定,以下同。

AddHandler FSW.Created, AddressOf FileSystemWatcher1_Created

AddHandler FSW.Deleted, AddressOf FileSystemWatcher1_Deleted

AddHandler FSW.Disposed, AddressOf FileSystemWatcher1_Disposed

AddHandler FSW.Error, AddressOf FileSystemWatcher1_Error

AddHandler FSW.Renamed, AddressOf FileSystemWatcher1_Renamed

FSW.EnableRaisingEvents = True

Next

上面代码放到一个调用过程中

Private Sub FileSystemWatcher1_Created(sender As Object, e As FileSystemEventArgs) Handles FileSystemWatcher1.Created

‘我用fsw的path属性区别多个分区,你用自己的代码就行,如果你没有创建FileSystemWatcher1,就把Handles FileSystemWatcher1.Created删除。

If sender.path = "C:\" Then

'代码

ElseIf sender.path = "D:\" Then

'代码

ElseIf sender.path = "F:\" Then

ElseIf sender.path = "H:\" Then

'……

End If

End Sub

vb.net 如何在一个项目中创建类,并且使用他?

在任意form类或模块中都可以创建类,跟建立函数和过程一样。

示例:

public class form1

‘创建一个属于form的子类,名称为【类名】。

public class 类名

’定义类成员text

public text as string

end class

‘定义一个【类名】类的公共变量。

dim 类名1 as 类名

’定义一个过程,使用【类名】类的text成员

public sub 过程

‘实例化【类名1】

类名1=new 类名

类名1.text=“赋值”

’定义一个【新类】类的私用变量,并实例化。

dim 新类1 as new 新类

新类1.name=“一个字符串”

新类1.age=12

end sub

end class

‘’‘创建一个与form同级的类,名称为【新类】

public class 新类

public sub new()

end sub

public name as string

public age as integer

end class

在模块中使用:

public class module1

dim a as new form1.类名

end module

vb.net的COM组件的编写问题

我想了两种思路,winform没有findControl,只有个this.Controls.Contains("textBox1"),因此除了遍历没办法了。。。

思路1:遍历Controls,具体你自己完善下,

if(this.Controls.Count0)

{

foreach(Control c in this.Controls)

if(c.GetTepy==Tepyof(TextBox))

string str += ((TextBox)c).Text;

}


网页题目:vb.net新建组件类的简单介绍
标题网址:http://6mz.cn/article/dsgodcc.html

其他资讯