c# - 在现有表单 C#(Windows 表单应用程序)之间传递变量(作为整数的日、月和年)
问题描述
我是 C# 的新手。我正在做的是一个模拟器,您可以在其中订购生产 - 我已经成功创建了一个指定订单的类。我以单独的表单(用户控件)制作的这个类在单击菜单条上的某个按钮后显示在 form1 上。在 form1(Main) 中有一个包含文本框的组框,其中显示了实际的日、月和年,这要归功于三个变量日、月和年。我需要做的是将这些变量传递给实现类的 user_control 表单。
这是日期变量的代码和实现:
//#######**Form1.cs**#########
int day;
int month;
int year;
private void timer1_Tick(object sender, EventArgs e)
{
if(((month==1) || (month==3) || (month==5) || (month==7) || (month==8) || (month==10) || (month==12)) && (day==31) )
{
if(month==12)
{
day = 1;
month = 1;
year = year + 1;
Date_txtbox.Text = "0" + day + "." + "0" + month + "." + year;
}
else
{
day = 1;
month = month + 1;
if (month <= 9)
{
Date_txtbox.Text = "0" + day + "." + "0" + month + "." + year;
}
else if (month > 9)
{
Date_txtbox.Text = "0" + day + "." + month + "." + year;
}
}
}else if(((month == 4) || (month == 6) || (month == 9) || (month == 11)) && (day == 30))
{
day = 1;
month = month + 1;
if (month <= 9)
{
Date_txtbox.Text = "0" + day + "." + "0" + month + "." + year;
}
else if (month > 9)
{
Date_txtbox.Text = "0" + day + "." + month + "." + year;
}
}
else if ((month == 2) && (day == 28))
{
day = 1;
month = month + 1;
Date_txtbox.Text ="0" + day + "." + month + "." + year;
}
else
{
day++;
if (day <= 9)
{
if (month <= 9)
{
Date_txtbox.Text = "0" + day + "." + "0" + month + "." + year;
}
else if (month > 9)
{
Date_txtbox.Text = "0" + day + "." + month + "." + year;
}
}
else if (day > 9)
{
if (month <= 9)
{
Date_txtbox.Text = day + "." + "0" + month + "." + year;
}
else if (month > 9)
{
Date_txtbox.Text = day + "." + month + "." + year;
}
}
}
}
我需要做的是将以下变量:日、月、年传递给指定另一种形式的顺序的类(用户控件)。
下面是类的实现:
//#########Production_usercontrol.cs#########
public class production_ordered
{
public string production_time_obj; // A <= I've set this as a string only for testing purposes, when I'm done with this it wil be changed integer, so for now do not bother yourself with it if it does not make a sense to you
public int par_quan; // B
public int lin_quan; //C
public string type; //D
public int ID_prd;
public void Ordered_prd(string A, int B, int C, string D, int ID)
{
this.production_time_obj = A;
this.par_quan = B;
this.lin_quan = C;
this.type = D;
this.ID_prd = ID;
}
}
.
.
.
public void button1_Click_1(object sender, EventArgs e)
{
//#######################################################################################
string a = production_time;
bool ol;
int b;
ol = int.TryParse(Parallel_quantity.Text, out b );
bool rec;
int c;
rec = int.TryParse(Linear_quantity.Text, out c ) ;
string d = checkedItemText;
id++;
production_ordered prod= new production_ordered();
prod.Ordered_prd(a, b, c, d, id);
//#####################################################
.
.
.
}
这个怎么做?
任何帮助都会受到赞赏,因为我被卡住了。
解决方案
推荐阅读
- http-live-streaming - SRS how enable HTTPS for HLS stream?
- amazon-web-services - 将对象放入另一个帐户的 S3 存储桶
- java - 在具有重复项的排序列表中查找第一次出现的整数
- typescript - Typescript - 延迟指定泛型类型直到调用函数
- c# - Calling PHP class in C#
- mysql - read Statement not working in Linux script
- javascript - 如何在传单 React 中查找纬度/经度属性
- php - echo session variable on ajax post call
- javascript - React Native AWS Amplify AuthError : Amplify has not been configured correctly
- angular - sharing data between two routes angular