Using this code in C# Windows Form, I need the Form1.Designer.cs code to make it look like the picture. This code is wor

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Using this code in C# Windows Form, I need the Form1.Designer.cs code to make it look like the picture. This code is wor

Post by answerhappygod »

Using this code in C# Windows Form, I need the Form1.Designer.cs
code to make it look like the picture. This code is working.
Using This Code In C Windows Form I Need The Form1 Designer Cs Code To Make It Look Like The Picture This Code Is Wor 1
Using This Code In C Windows Form I Need The Form1 Designer Cs Code To Make It Look Like The Picture This Code Is Wor 1 (34.3 KiB) Viewed 72 times
Form1.cs :
//namespace
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;
//application namespace
namespace DiceclassApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//object of Dice class with same number of sides
Dice dice1 = new Dice(5);
Dice dice2 = new Dice(5);
//This variable stores number of rolls
int numberOfRolls = 0;
//Button click event for Roll Dice
private void btnRollDice_Click(object sender, EventArgs e)
{
//call method rollDie()
int roll1=dice1.rollDie();
int roll2=dice2.rollDie();
//show dice face on the labels
lblDice1.Text = roll1.ToString();
lblDice2.Text = roll2.ToString();
//increment the value of numberOfRolls
numberOfRolls++;
//checking for the snake eyes
if(roll1==1 && roll2==1)
{
//when double 1's on the die face then
//disable button
btnRollDice.Enabled = false;
//show MessageBox
MessageBox.Show("It took " + numberOfRolls + " rolls to get snake
eyes!");
}
}//enf for button click
}
//C# class
class Dice
{
//A private field for the number of sides of the die
private int numberOfSides;
// constructor that takes an integer between 4 and 20, inclusive
and sets the number of sides of the die
public Dice(int numbeSides)
{
//checking number of sides
if (numbeSides >= 4 && numbeSides <= 20)
{
//when numbeSides between 4 to 20 inclusive then
numberOfSides = numbeSides;
}
else
{
//when invalid sides are entered then
MessageBox.Show("Number of sides should be between 4 to 20
inclusive");
}
}//end of Constructor
//A method, rollDie(), returns the face value when the die is
rolled
public int rollDie()
{
//Object of Random class
Random randomDie = new Random();
//a Random number to “roll” the die
return randomDie.Next(1, numberOfSides);
}//end of method rollDie()
}//end of class Dice
}
Form1 Х Roll Dice
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply