CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Jun 2010
    Posts
    1

    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!

  2. #2
    Join Date
    Jun 2010
    Posts
    1

    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

  3. #3
    Join Date
    Apr 2005
    Posts
    7

    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!";
    }

  4. #4
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    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.
    Last edited by JonnyPoet; June 15th, 2010 at 02:54 PM.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  5. #5
    Join Date
    Jul 2010
    Posts
    4

    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!";
            }
        }
    }

  6. #6
    Join Date
    Jul 2010
    Posts
    82

    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!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured