如何引用类?例如,我有一个Price.cs
计算项目的费用,但我不能使用我的任何 windows 窗体控件Price.cs
,必须引用我Main.cs
的才能使用属性和控件。对不起,如果我听起来很混乱。英语不是我的主要语言。
主文件:
private float? PricePlacement()
{
if (serviceDesc.Text != "Multiple")
{
if (serviceDesc.Text == "Phone Repair")
{
textBlock_Price.Text = "$20.00 + Parts";
return 20.00f;
}
if (serviceDesc.Text == "Virus Removal")
{
textBlock_Price.Text = "$10.00";
return 10.00f;
}
if (serviceDesc.Text == "Hardware Repair/Installation")
{
textBlock_Price.Text = "$10.00";
return 10.00f;
}
if (serviceDesc.Text == "Software Installation")
{
textBlock_Price.Text = "$5.00";
return 5.00f;
}
textBlock_Price.Text = "$0.00";
return 0f;
}
else if (serviceDesc.Text == "Multiple")
{
//TODO: Implement a function to check if an item on the itemList is checked or not
textBlock_Price.Text = "$-.--";
return null;
}
return 0f;
}
价格.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TicketingSystem
{
class Price
{
}
}
我的解决方案如下。
在Price.cs
我添加using static TicketingSystem.TicketingSystem;
在设计器中
我变了 private System.Windows.Forms.ComboBox serviceDesc;
至
public System.Windows.Forms.ComboBox serviceDesc;``
所以完全我的新代码是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TicketingSystem;
using System.Windows.Forms;
using static TicketingSystem.TicketingSystem;
namespace TicketingSystem
{
class Price
{
TicketingSystem ticketingSystem = new TicketingSystem();
public ComboBox serviceDesc = new ComboBox();
public Label textBlock_Price = new Label();
public float? PricePlacement()
{
if (ticketingSystem.serviceDesc.Text != "Multiple")
{
if (ticketingSystem.serviceDesc.Text == "Phone Repair")
{
textBlock_Price.Text = "$20.00 + Parts";
return 20.00f;
}
if (ticketingSystem.serviceDesc.Text == "Virus Removal")
{
textBlock_Price.Text = "$10.00";
return 10.00f;
}
if (ticketingSystem.serviceDesc.Text == "Hardware Repair/Installation")
{
textBlock_Price.Text = "$10.00";
return 10.00f;
}
if (ticketingSystem.serviceDesc.Text == "Software Installation")
{
textBlock_Price.Text = "$5.00";
return 5.00f;
}
textBlock_Price.Text = "$0.00";
return 0f;
}
else if (serviceDesc.Text == "Multiple")
{
//TODO: Implement a function to check if an item on the itemList is checked or not
textBlock_Price.Text = "$-.--";
return null;
}
return 0f;
}
}
}
如果不清楚,我深表歉意。我还是个初学者,只是想帮助别人。如果这对您有帮助,请加油!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句