Class coursework asked us to create a simple energy bill. an ID number is generated on the 1st from that I want to copy to the 2nd form however I keep getting the following :
Error CS0122 'Form1.idgen' is inaccessible due to its protection level
Since I'm going to referencing a lot of values from the 1st Form I just want to learn what the issue is and how to overcome it for future use
This is the code for Form1:
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 Bill_Generator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
timer1.Enabled = true;
Random r = new Random();
var x = r.Next(0, 1000000);
string v = x.ToString("000");
idgen.Text = v;
}
public void Timer1_Tick(object sender, EventArgs e)
{
date.Text = DateTime.Now.ToString("dddd , MMM dd yyyy hh:mm:ss");
}
public void Gen_button_Click(object sender, EventArgs e)
{
Form2 openform = new Form2();
openform.Show();
}
public void Calc_Click(object sender, EventArgs e)
{
double preamt = Convert.ToDouble(prebox.Text);
double curramt = Convert.ToDouble(currbox.Text);
double billamt = curramt - preamt;
billbox.Text = Convert.ToString(billamt);
}
}
}
This is the code so far for Form2:
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 Bill_Generator
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
System.Windows.Forms.Form f = System.Windows.Forms.Application.OpenForms["Form1"];
iddisp.Text = ((Form1)f).idgen.Text();
}
private void Form2_Load(object sender, EventArgs e)
{
date.Text = DateTime.Now.ToString("dddd , MMM dd yyyy hh:mm:ss");
}
}
}