C#点击按钮控制进度条 20
请使用ProgressBar编写一个小应用,当用户点击左边的按钮时,进度条向前走,点击右边的按钮时,进度条向后退。求具体步骤...
请使用ProgressBar编写一个小应用,当用户点击左边的按钮时,进度条向前走,点击右边的按钮时,进度条向后退。求具体步骤
展开
展开全部
1、我们在ProgressBar的Value属性中设置为100。 Name 为pgbBlood
2、一个button,name属性为btnPuse,click事件设置为btnPush_Click
3、一个button,name为btnDecrese,click事件为btnDecrese_Click
4、在btnPush_Click事件中写
private void btnPush_Click(object sender, RoutedEventArgs e)
{
if (pgbBlood.Value==100)
{
MessageBox.Show("已经满了");
}
}
pgbBlood.Value += 10;
5在btnDecrese_Click事件中写
private void btnDecrese_Click(object sender, RoutedEventArgs e)
{
if (pgbBlood.Value==0)
{
MessageBox.Show("不能再减了");
}
pgbBlood.Value -= 10;
}
这就够了,布局在前台做就好了,需要上面那么多代码吗?
2、一个button,name属性为btnPuse,click事件设置为btnPush_Click
3、一个button,name为btnDecrese,click事件为btnDecrese_Click
4、在btnPush_Click事件中写
private void btnPush_Click(object sender, RoutedEventArgs e)
{
if (pgbBlood.Value==100)
{
MessageBox.Show("已经满了");
}
}
pgbBlood.Value += 10;
5在btnDecrese_Click事件中写
private void btnDecrese_Click(object sender, RoutedEventArgs e)
{
if (pgbBlood.Value==0)
{
MessageBox.Show("不能再减了");
}
pgbBlood.Value -= 10;
}
这就够了,布局在前台做就好了,需要上面那么多代码吗?
展开全部
public partial class Form1 : Form
{
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private int step;//前进后退的步幅
public Form1()
{
step = 5;
// InitializeComponent();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// progressBar1
//
this.progressBar1.Location = new System.Drawing.Point(39, 30);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(465, 23);
this.progressBar1.Step = 5;
this.progressBar1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(50, 76);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(107, 23);
this.button1.TabIndex = 1;
this.button1.Text = "度条向前走";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(386, 76);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(107, 23);
this.button2.TabIndex = 2;
this.button2.Text = "进度条向后退";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(529, 136);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.progressBar1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
private void button1_Click(object sender, EventArgs e)
{
progressBar1.Increment(step);//前进
}
private void button2_Click(object sender, EventArgs e)
{
progressBar1.Increment(-step);//后退
}
}
{
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private int step;//前进后退的步幅
public Form1()
{
step = 5;
// InitializeComponent();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// progressBar1
//
this.progressBar1.Location = new System.Drawing.Point(39, 30);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(465, 23);
this.progressBar1.Step = 5;
this.progressBar1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(50, 76);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(107, 23);
this.button1.TabIndex = 1;
this.button1.Text = "度条向前走";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(386, 76);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(107, 23);
this.button2.TabIndex = 2;
this.button2.Text = "进度条向后退";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(529, 136);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.progressBar1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
private void button1_Click(object sender, EventArgs e)
{
progressBar1.Increment(step);//前进
}
private void button2_Click(object sender, EventArgs e)
{
progressBar1.Increment(-step);//后退
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-04-07
展开全部
使用ProgressBar需要用到多线程,占用时间太长会使主线程卡死
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
进度条value加或减
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询