画像ファイル
画像ファイル インデクサ(C#、VB.NET)
VB.NETコード
Public Class Form1

'テキストボックスの配列を持つクラス
Dim aBox As ArryTextBox

'テキストボックスの配列
Dim tBox(5) As TextBox

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
For i As Integer = 0 To 4
'新しいテキストボックスを作成して配列に格納
tBox(i) = New TextBox()
'表示の為に必要
tBox(i).Parent = Me
'テキストボックスの位置を設定
tBox(i).Location = New Point(tBox(i).Width * i + 5, 10)
'個別のTextを設定する
tBox(i).Text = "textBox-" + i.ToString()
Next
'配列の参照を持つクラスに配列を設定する
aBox = New ArryTextBox(tBox)
End Sub

Private Sub Form1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Click
'一番右のテキストを保存
Dim btext As String = aBox(4)
'右にシフト
For i As Integer = 3 To 0 Step -1
aBox(i + 1) = aBox(i)
Next
'一番左のテキストボックスに一番右の文字を入れる
aBox(0) = btext
End Sub
End Class

'テキストボックスの配列を持つクラス
Public Class ArryTextBox

Private tb As TextBox() '内部の配列

'コンストラクタ、引数にテキストボックスの配列を持つ
Public Sub New(ByVal formsTextBox() As TextBox)
'内部の配列に参照を設定する
tb = formsTextBox
End Sub

'インデクサ
Default Property textBoxText(ByVal index As Integer) As String
Get
'テキストクスのテキストを返す
Return tb(index).Text
End Get

Set(ByVal value As String)
'テキストボックスのテキストにに値を設定する
tb(index).Text = value
End Set
End Property
End Class
画像 上記C#コードのダウンロード
画像 上記VB2005のコードのダウンロード

画像ファイル