Jump to content
Zim

RichTextBox

Recommended Posts

Zim

Ola , não manjo muito vb.net e queria fazer um sistema de sorteio aleatório com RichTextBox por exemplo :

cySGG0T.png

Quero que alguns dos nomes (RichTextBox1) aleatoriamente vão para o sorteados(RichTextBox2) e outros para o eliminados (RichTextBox3) ao clicar no botão gerar (button1) , alguem pode me passar o codigo desse sistema basico ? obrigado !

Share this post


Link to post
Share on other sites
vikcch

era mais facil usares listbox em vez de richtextbox...

com listbox:

Option Explicit On
Option Strict On

Public Class Form1

   'botão para inserir nome
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim nome As String = InputBox("Nome")

    If nome <> String.Empty Then
	    Me.ListBox1.Items.Add(nome)
    End If

   End Sub

   'botao para sortear para que listbox vai
   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    If Me.ListBox1.Items.Count = 0 Then
	    Exit Sub
    End If

    Dim rnd As Random = New Random()

    Dim n As Integer = rnd.Next(0, 2)

    Dim item As String = Me.ListBox1.Items(0).ToString
    Me.ListBox1.Items.RemoveAt(0)

    If n = 0 Then
	    Me.ListBox2.Items.Add(item)
    Else
	    Me.ListBox3.Items.Add(item)
    End If

   End Sub

End Class

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.