vb.net类继承接口 类继承接口需要重写方法吗( 五 )


InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
'用来绑定label
BindArray()
End Sub
……Windows窗体设计器生成的其他代码……
#End Region
Dim Labels As New LabelArray(Me)
Public Sub BindArray()
Me.Label1.Tag = "1111"
Me.Label2.Tag = "222"
Labels.AddItem(Me.Label1)
Labels.AddItem(Me.Label2)
End Sub
End Class
然后可以测试点击两个label可以显示相应的Tag的信息 。
VB.NET我要用鼠标轨迹画一个矩形框 然后选中控件 。就像星际和魔兽争霸里对部队单位的选中一样~等大神回答这个类继承自Panelvb.net类继承接口,把它加到vb.net类继承接口你vb.net类继承接口的项目里面vb.net类继承接口,先运行一下,然后从工具箱里把它拖到窗体上,然后再向里面添加其它控件就可以vb.net类继承接口了,支持Shift加?。珹lt减选
Imports System.Linq
Imports System.Collections
Public Class MyPanel
Inherits Panel
' 选择模式 , 相交还是包含
Enum SelectMode
Intersects
Contains
End Enum
Dim down As New Point(-1, -1)
Dim rect As Rectangle
Dim selected As New List(Of Control)
Dim editting As IEnumerable(Of Control)
Dim mode As SelectMode = SelectMode.Contains
Dim shift, alt As Boolean
Public Sub New()
Me.DoubleBuffered = True
End Sub
Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
MyBase.OnMouseDown(e)
down = e.Location
editting = selected.ToArray().ToList()
OnMouseMove(e)
End Sub
Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
MyBase.OnMouseMove(e)
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim loc As New Point(Math.Min(down.X, e.X), Math.Min(down.Y, e.Y))
Dim size As New Size(Math.Abs(down.X - e.X), Math.Abs(down.Y - e.Y))
rect = New Rectangle(loc, size)
Dim cs As New List(Of Control)
For Each c In Controls
cs.Add(c)
Next
Dim a = cs.Where(Function(n As Control) (mode = SelectMode.Contains And rect.Contains(n.Bounds)) Or (mode = SelectMode.Intersects And rect.IntersectsWith(n.Bounds)))
If shift Then editting = a.Union(selected) Else If alt Then editting = selected.Except(a) Else editting = a
Invalidate()
End If
End Sub
Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
MyBase.OnMouseUp(e)
down = New Point(-1, -1)
selected = editting.ToList()
editting = Nothing
Invalidate()
End Sub
Protected Overrides Function ProcessKeyPreview(ByRef m As Message) As Boolean
Dim KeyCode As Keys = CInt(m.WParam) And CInt(Keys.KeyCode)
Dim d As Boolean
If m.Msg = H100 Or m.Msg = H104 Then d = True Else If m.Msg = H101 Or m.Msg = H105 Then d = False Else Return MyBase.ProcessKeyPreview(m)
If KeyCode = Keys.ShiftKey Then
shift = d
ElseIf KeyCode = Keys.Menu Then
alt = d
End If
Return MyBase.ProcessKeyPreview(m)
End Function
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
For Each c As Control In IIf(editting Is Nothing, selected, editting)
e.Graphics.DrawRectangle(New Pen(Color.Gray) With {.DashStyle = Drawing2D.DashStyle.DashDot}, c.Left - 1, c.Top - 1, c.Width + 1, c.Height + 1)
Next
If (down.X0) Then e.Graphics.DrawRectangle(New Pen(Color.Gray) With {.DashStyle = Drawing2D.DashStyle.DashDot}, rect)
End Sub
End Class
VB.NET 里 结构(Structure)和类(Class)有什么区别?如题 谢谢了Structure是值类型 , classe是引用类型Structure用栈来分配; classe用堆来分配structure的成员默认情况下是公共的,而Class的成员变量和常量默认情况下是私有的而其它成员默认情况下是公共的.这与VB6是相兼容的 。structure必须至少有一个非共享的成员变量或事件成员,class可以完全是空的.Structure的成员不能声明成Protected; class成员可以.一个structure过程只能在它是一个Shared Sub时才能handle events而且只能通过AddHandler语句;而任何class过程都可以handle events,既可以用Handles关键字或 AddHandler语句 。Structure variable declarations cannot specify initializers, the New keyword, or initial sizes for arrays; class variable declarations can.Structure继承自ValueType类 , 不能从其它任何类型继承; classes可以从任何不是ValueType的类继承Structure不能继承而Class可以Structure从来不析构terminated因此common language runtime (CLR)从来不调用它的Finalize方法,classe由垃圾回收器进行析构, 当没有任何对该类的引用时调用它的Finalize方法structure 不需要一个构造函数 , 而Class需要Structure只能有带参数的非共享的构造函数; classes 可以有带或不带参数的构造函数. 每个Structure都有一个默认的不带参数的构造函数以对其成员进行初始化,你可以重新定义该函数

推荐阅读