Can someone help with my C# programming code?
Im just starting off trying to learn C# and im trying some things out.
MessageBox.Show("Hello World");
i++;
if (i > 1)
label1.Text = "You clicked me " + i++ + " times!";
else
label1.Text = "You clicked me 1 time!";
if (checkBox1 == checked);
label1.Text = "You clicked me " + i + " times";
I am trying to make it so you click a button, and a box pops up that says hello world. And it tells you how many times you clicked the button. But now Im trying to make it so you can have a box checked and it stops recording how many times you clicked. Thanks!
Re: Can someone help with my C# programming code?
Hi,
You have to take checkboxclickedcontrol event function.In that if you take one public counter at the end you can know how many times you clicked that checkbox.
Thanks
Murali
Re: Can someone help with my C# programming code?
I assume you did this in your click event?
MessageBox.Show("Hello World");
i++;
if (checkBox1.Checked == true && i > 1)
{
label1.Text = "You clicked me " + i.ToString() + " times!";
}
else
{
label1.Text = "You clicked me 1 time!";
}
Re: Can someone help with my C# programming code?
General Information for all who posts. Please read the forum rules first. In especially please use codetags, because code is no longer formatted if you dont use them. [code]your code here[/code]
Additional please show all the relevant code including method's body, or the whole delegate where this code occures, declarations and all what is needed to understand what you are doing.
Re: Can someone help with my C# programming code?
I think this is what you're trying to do:
Code:
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private int i;
public Form1()
{
InitializeComponent();
i = 0;
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello World");
if (!checkBox1.Checked) return;
i++;
label1.Text = @"You clicked me " + i + @" times!";
}
}
}
Re: Can someone help with my C# programming code?
Its simple C# coding, and these are some basic things :
1. Any variable that you want to check across functions, or store it during a program's instance execution, can be stored as a member variable.
2. You can also use the Tag value of the button to store how many times they clicked, avoiding a member variable i.
button1.Tag = Int32.Parse(button1.Tag) + 1;
Regards,
CT.
Check out www.cuteassistant.com - Manage your tasks, take notes, securely store data and more!