Portfolio

Monday, November 9, 2015

How to do a Random Number Form

This teaches you how to generate a random number form in Visual Studio using C#.
Check out my website for more projects http:\\www.logizticsinc.com

You will need:
  •  a windows form application
  • 3 labels
  • 3 textboxes
  • a button

Here is the source code:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RandomNumForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Random rand = new Random();
            txtBoxAns.Text = rand.Next(Convert.ToInt32(txtBoxMin.Text),
                Convert.ToInt32(txtBoxMax.Text)).ToString();


        }
    }
}

No comments:

Post a Comment