主题:急切求助:控件数组如何应用
xinying2005
[专家分:0] 发布于 2006-03-06 11:59:00
现在欲将窗体中的控件,其名称为p11 p12 p13…… 放在一个数组中,以便程序的简洁
我的问题如下
1 可不可以将这些控件的名称组成一个数组
2 倘若可以 ,此数组是什么类型的
谢谢!!
回复列表 (共3个回复)
沙发
xinying2005 [专家分:0] 发布于 2006-03-07 09:06:00
如果是系统自带的控件,则可以这样创建:
比如 dim cm() as ComboBox={combobox1,combobox2,combobox3,combobox4}
但是如果是自定义控件
比如 dim l() as Line={line1,line2,line3}
系统就会提示错误 Line需要类型
这是怎么回事
谢谢
板凳
xinying2005 [专家分:0] 发布于 2006-03-07 09:45:00
Line自定义控件的程序如下::
Imports System.Drawing.Drawing2D
Public Class Line
Inherits System.Windows.Forms.UserControl
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'UserControl1 重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents Timer1 As System.Timers.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Timer1 = New System.Timers.Timer
CType(Me.Timer1, System.ComponentModel.ISupportInitialize).BeginInit()
'
'Timer1
'
Me.Timer1.Enabled = True
Me.Timer1.SynchronizingObject = Me
'
'Line
'
Me.Name = "Line"
CType(Me.Timer1, System.ComponentModel.ISupportInitialize).EndInit()
End Sub
#End Region
Dim typeL As Type
Enum Type
horizonal
vetical
End Enum
Public Property settype() As type
Get
Return typeL
End Get
Set(ByVal Value As type)
typeL = Value
End Set
End Property
Dim etimeE As Integer
Public Property etime() As Integer
Get
Return etimeE
End Get
Set(ByVal Value As Integer)
etimeE = Value
End Set
End Property
Dim emarkE As Boolean
Public Property emark() As Boolean
Get
Return emarkE
End Get
Set(ByVal Value As Boolean)
emarkE = Value
End Set
End Property
Dim Logic As Boolean
Public Property LogicEnable() As Boolean
Get
Return Logic
End Get
Set(ByVal Value As Boolean)
Logic = Value
End Set
End Property
Dim E As Integer
Public Property etim() As Integer
Get
Return E
End Get
Set(ByVal Value As Integer)
E = Value
End Set
End Property
Public Sub Line_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim startX As Integer
Dim startY As Integer
Dim pen As New Pen(Color.FromArgb(255, 0, 100, 255), 2)
Select Case typeL
Case Type.horizonal
e.Graphics.DrawLine(pen, startX, startY, startX + Me.Width - 1, startY)
Case Type.vetical
e.Graphics.DrawLine(pen, startX, startY, startX, startY + Me.Height - 1)
End Select
End Sub
Public Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Timer1.Interval = 1000
Me.Refresh()
End Sub
End Class
谢谢帮忙!!
3 楼
xinying2005 [专家分:0] 发布于 2006-03-07 09:46:00
是不是我的Line自定义控件有问题呢??? 还是自定义控件无法创建控件数组?
我来回复