jeudi 22 novembre 2018

How to make randomized button names

Please put 3 buttons into your project and named them as Button1, Button2 and Button3.

Then run following code in order to see what following code is doing.

Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    Dim myRandom As New Random
    Dim myList As New List(Of String)(New String() {"A", "B", "C"})
    myList.OrderBy(Function(i) myRandom.Next).ToList()
    Dim myButtons As Button() = {Button1, Button2, Button3}
    Dim x As Integer = 0
    For Each y As String In myList
        myButtons(x).Text = y.ToString
        x += 1
    Next
End Sub
End Class

When you run the above code you will see that I cant randomize button mames.

So how to make randomized button names?

P.S. Using Linq is must.




Aucun commentaire:

Enregistrer un commentaire