troubleshooting Question

C# Math in Windows Form

Avatar of madhatter5501
madhatter5501Flag for United States of America asked on
7 Comments2 Solutions715 ViewsLast Modified:

I have been trying for a week to get this to work and have tried many different ways and I am sure it is a lot simpler than I am making it.  I was able to do this in VB and it worked good, but I want to do this in C#.  Basically on Form load, fill Textbox1 and Textbox2 with Random numbers between 0 and 15.  I will add a textbox later for user to type answer.  right now I just want to know how to make these two textboxes do a math calculation and return the answer to the label1.

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

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

                private void Form1_Load(object sender, EventArgs e)

                            //On FormLoad:
                            //Create Two New Random Numbers between 0 and 15 
                            //and Automatically Assign them to 
                            //Textbox1 & Textbox2

                        Random r = new Random();
                        Random v = new Random();

                        Double randomnumber1 = r.Next(0, 15);
                        Double randomnumber2 = v.Next(0, 15);

                        Double num1 = Convert.ToDouble(textBox1.Text);
                        Double num2 = Convert.ToDouble(textBox2.Text);


                public void button1_Click(object sender, EventArgs e)
                            //On Button1_Click
                            //Run Math Problem and Display the answer
                            //on label1
Freelance programmer / Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros