|
-
May 23rd, 2012, 06:15 AM
#1
Thread Starter
Addicted Member
user control ubound for array
Hi to bound user control to create an array. in VB6 I have this code which is working fine:
For j = 1 To 10
Load iProject(iProject.UBound + 1)
Next
How to make this work in VB.NET 2010?
-
May 23rd, 2012, 08:22 AM
#2
Re: user control ubound for array
first forget about arrays.
Next, search MSDN for "List(of T)" .... it'll be easier to work with than arrays.
Then hopefully the following code sample will make sense:
Code:
Dim myProjects as new List(of Project) ' I'm guessing at the class type here...
....
dim newProject as New Project
'Set properties here if needed
myProjects.Add(newProject)
-tg
-
May 23rd, 2012, 10:51 AM
#3
Re: user control ubound for array
If they are controls why not add them to the container instead of a List<T> ?
vbnet Code:
Me.Controls.Add(New Project)
The above dynamically adds a control to a container like a Form.
-
May 23rd, 2012, 11:19 AM
#4
Re: user control ubound for array
True... true... I hadn't considered that. Depends on what you want to do with it later... with the list you can jsut do
myProjects.items(2) and get the third item in the list, not nearly as easily done if it's only in the Controls collection....
that said, you'll actually probably need to add it to both...
-tg
-
May 23rd, 2012, 07:43 PM
#5
Thread Starter
Addicted Member
Re: user control ubound for array
Hi guys thanks for the response... I found a class file on the net to create timer basically this is what I would like to achieve but I need to create a lot of timers which will be bound to list view row number. on Form main I will load this to generate timer base on the row number of my list view. Each timer is independent to each other. Please guide me how to accomplish it.
HTML Code:
Imports System.ComponentModel
<DesignerAttribute(GetType(MyControlDesigner)), System.Serializable()> _
Public Class cdTimer
Inherits Label
Dim tmr As Timer
Dim ts As TimeSpan
Dim tsElapsed As TimeSpan
Dim canUpDate As Boolean = False
Private _countDownTime As New time
<TypeConverter(GetType(timeConverter)), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
Description("Expand to set countdown time.")> _
Public Property countDownTime() As time
Get
Return _countDownTime
End Get
Set(ByVal value As time)
_countDownTime = value
ts = New TimeSpan(countDownTime.hours, countDownTime.minutes, countDownTime.seconds)
tsElapsed = TimeSpan.Zero
MyBase.Text = countDownTime.ToString
End Set
End Property
<EditorBrowsable(EditorBrowsableState.Never)> _
<Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Public Overrides Property Text As String
Get
Return MyBase.Text
End Get
Set(ByVal value As String)
End Set
End Property
<EditorBrowsable(EditorBrowsableState.Never)> _
<Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Public Overrides Property AutoSize As Boolean
Get
Return True
End Get
Set(ByVal value As Boolean)
End Set
End Property
Protected Overrides Sub OnInvalidated(ByVal e As System.Windows.Forms.InvalidateEventArgs)
If canUpDate AndAlso tsElapsed = TimeSpan.Zero Then
MyBase.Text = countDownTime.ToString
ts = New TimeSpan(countDownTime.hours, countDownTime.minutes, countDownTime.seconds)
End If
MyBase.OnInvalidated(e)
End Sub
''' <summary>
''' OnCreateControl
''' </summary>
''' <remarks>initializes the countdownTimer</remarks>
Protected Overrides Sub OnCreateControl()
MyBase.Text = countdownTime.ToString
ts = New TimeSpan(countDownTime.hours, countDownTime.minutes, countDownTime.seconds)
tsElapsed = TimeSpan.Zero
tmr = New Timer
tmr.Interval = 1000
AddHandler tmr.Tick, AddressOf tmr_tick
canUpDate = True
MyBase.OnCreateControl()
End Sub
''' <summary>
''' tmr_tick
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks>tmr.tick event - performs the countdown</remarks>
Private Sub tmr_tick(ByVal sender As Object, ByVal e As System.EventArgs)
If ts.TotalSeconds > 0 Then
ts = ts.Subtract(New TimeSpan(0, 0, 1))
tsElapsed = tsElapsed.Add(New TimeSpan(0, 0, 1))
MyBase.Text = ts.ToString
Me.Refresh()
Else
tmr.Enabled = False
End If
End Sub
''' <summary>
''' cdStart
''' </summary>
''' <remarks>starts the countdown</remarks>
Public Sub cdStart()
canUpDate = False
tmr.Enabled = True
End Sub
''' <summary>
''' cdStop
''' </summary>
''' <remarks>stops the countdown</remarks>
Public Sub cdStop()
canUpDate = True
tmr.Enabled = False
End Sub
''' <summary>
''' cdReset
''' </summary>
''' <remarks>resets the countdownTimer</remarks>
Public Sub cdReset()
canUpDate = True
tmr.Enabled = False
tsElapsed = TimeSpan.Zero
Me.Invalidate()
End Sub
End Class
Note: this class code is not mine
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|