タイトル | : Re: VB.NET テキストボックス 改行 ランダム表示 |
記事No | : 11554 |
投稿日 | : 2015/12/18(Fri) 17:10 |
投稿者 | : 魔界の仮面弁士 |
Public Class Form1
Private TextBoxes() As TextBox
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load 'TextBox2〜7を配列にセット TextBoxes = Me.Controls.OfType(Of TextBox)() _ .Where(Function(txt) txt.Name Like "TextBox[234567]").ToArray() End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 'TextBox2〜7には、TextBox1の各行からランダムで表示 Dim r As New Random() Dim shuffled() As String = TextBox1.Lines.OrderBy(Function(s) r.Next()) _ .Concat(Enumerable.Repeat("", TextBoxes.Length)).ToArray()
For n As Integer = 0 To TextBoxes.GetUpperBound(0) TextBoxes(n).Text = shuffled(n) Next
End Sub
End Class
|