using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace shoupiao
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void ticket_type_Combox_SelectedValueChanged(object sender, EventArgs e)
{
total_ticket_textBox.ReadOnly = false;
payment_textBox.ReadOnly = false;
receiving_textBox.Text = "";
balance_textBox.Text = "";
discount_groupBox.Enabled = false;
switch (ticket_type_ComBox.SelectedIndex)
{
case 0:
price_textBox.Text = string.Format("{0,f2}", commonprice);
break;
case 1:
price_textBox.Text = string.Format("{0,f2}", commonprice*50/100);
break;
case 2:
discount_groupBox.Enabled = true;
price_textBox.Text = string.Format("{0,f2}", commonprice * 90 / 100);
break;
}
} private void textBox3_TextChanged(object sender, EventArgs e)
{ } private void balance_textBox_TextChanged(object sender, EventArgs e)
{ } private void button2_Click(object sender, EventArgs e)
{
Application.Exit(); } private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
price_textBox.Text = string.Format("{0,f2}", commonprice * 90 / 100);
} private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
price_textBox.Text = string.Format("{0,f2}", commonprice * 80 / 100);
} private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
price_textBox.Text = string.Format("{0,f2}", commonprice * 65 / 100);
} private void button1_Click(object sender, EventArgs e)
{
double payment, receiving, balance, price, commonprice;
int tickets;
try
{
tickets = Int32.Parse(total_ticket_textBox.Text);
payment = double.Parse(payment_textBox.Text);
price = double.Parse(price_textBox.Text);
receiving = tickets * price;
receiving_textBox.Text = string.Format("{0,f2}", receiving);
balance = payment - receiving;
balance_textBox.Text = string.Format("{0,f2}", balance);
}
catch
{
MessageBox.Show("输入有误");
return;
}
} private void groupBox1_Enter(object sender, EventArgs e)
{ } private void label1_Click(object sender, EventArgs e)
{ } }
}
程序中运行结果说commonprice在上下文中不存在,那边怎么改?
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace shoupiao
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void ticket_type_Combox_SelectedValueChanged(object sender, EventArgs e)
{
total_ticket_textBox.ReadOnly = false;
payment_textBox.ReadOnly = false;
receiving_textBox.Text = "";
balance_textBox.Text = "";
discount_groupBox.Enabled = false;
switch (ticket_type_ComBox.SelectedIndex)
{
case 0:
price_textBox.Text = string.Format("{0,f2}", commonprice);
break;
case 1:
price_textBox.Text = string.Format("{0,f2}", commonprice*50/100);
break;
case 2:
discount_groupBox.Enabled = true;
price_textBox.Text = string.Format("{0,f2}", commonprice * 90 / 100);
break;
}
} private void textBox3_TextChanged(object sender, EventArgs e)
{ } private void balance_textBox_TextChanged(object sender, EventArgs e)
{ } private void button2_Click(object sender, EventArgs e)
{
Application.Exit(); } private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
price_textBox.Text = string.Format("{0,f2}", commonprice * 90 / 100);
} private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
price_textBox.Text = string.Format("{0,f2}", commonprice * 80 / 100);
} private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
price_textBox.Text = string.Format("{0,f2}", commonprice * 65 / 100);
} private void button1_Click(object sender, EventArgs e)
{
double payment, receiving, balance, price, commonprice;
int tickets;
try
{
tickets = Int32.Parse(total_ticket_textBox.Text);
payment = double.Parse(payment_textBox.Text);
price = double.Parse(price_textBox.Text);
receiving = tickets * price;
receiving_textBox.Text = string.Format("{0,f2}", receiving);
balance = payment - receiving;
balance_textBox.Text = string.Format("{0,f2}", balance);
}
catch
{
MessageBox.Show("输入有误");
return;
}
} private void groupBox1_Enter(object sender, EventArgs e)
{ } private void label1_Click(object sender, EventArgs e)
{ } }
}
程序中运行结果说commonprice在上下文中不存在,那边怎么改?
添加全局变量
private float commonprice = 0;
{
InitializeComponent();
}
前加1行
public static float commonprice =0;