我试图放一个label1.text = progressbar1.value.ToString();
但它不会读出它进展了多少。到目前为止,这是我的帮助。
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
progressBar1.Value = s_Checks * (progressBar1.Maximum / TOTAL_CHECKBOXES);
label1.Text = progressBar1.Value.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private const Int32 TOTAL_CHECKBOXES = 4;
private static Int32 s_Checks = 0;
private void OnCheckedChanged(object sender, EventArgs e)
{
if (((CheckBox)sender).Checked)
++s_Checks;
else
--s_Checks;
progressBar1.Value = s_Checks * (progressBar1.Maximum / TOTAL_CHECKBOXES);
}
private void progressBar1_Click(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (((CheckBox)sender).Checked)
++s_Checks;
else
--s_Checks;
progressBar1.Value = s_Checks * (progressBar1.Maximum / TOTAL_CHECKBOXES);
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
if (((CheckBox)sender).Checked)
++s_Checks;
else
--s_Checks;
progressBar1.Value = s_Checks * (progressBar1.Maximum / TOTAL_CHECKBOXES);
}
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
if (((CheckBox)sender).Checked)
++s_Checks;
else
--s_Checks;
progressBar1.Value = s_Checks * (progressBar1.Maximum / TOTAL_CHECKBOXES);
}
private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
if (((CheckBox)sender).Checked)
++s_Checks;
else
--s_Checks;
progressBar1.Value = s_Checks * (progressBar1.Maximum / TOTAL_CHECKBOXES);
}
private void button1_Click(object sender, EventArgs e)
{
if (checkBox1.Checked || checkBox2.Checked || checkBox3.Checked || checkBox4.Checked == true)
{
checkBox1.Checked = false;
checkBox2.Checked = false;
checkBox3.Checked = false;
checkBox4.Checked = false;
}
}
private void clearCheckBoxToolStripMenuItem_Click(object sender, EventArgs e)
{
if (checkBox1.Checked || checkBox2.Checked || checkBox3.Checked || checkBox4.Checked == true)
{
checkBox1.Checked = false;
checkBox2.Checked = false;
checkBox3.Checked = false;
checkBox4.Checked = false;
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
label1.Text = progressBar1.Value.ToString();
}
}
}
答案 0 :(得分:0)
public Form1()
{
InitializeComponent();
progressBar1.Value = s_Checks * (progressBar1.Maximum / TOTAL_CHECKBOXES);
label1.Text = progressBar1.Value.ToString();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 1000;
timer1.Enabled = true;
timer1.Start();
}