[C#, Win7, Visual C# 2010 express] Help on creating a particular form!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: [C#, Win7, Visual C# 2010 express] Help on creating a particular form!

Hybrid View

  1. #1
    Join Date
    Dec 2013
    Posts
    2

    Question [C#, Win7, Visual C# 2010 express] Help on creating a particular form!

    Hey guys,
    I'm a total beginner in programming and C# is my first chosen language. I'm enjoying it so far, however, I've run into my first problem that's been bugging me for some hours now! I may just not be thinking outside some box lol so I'd appreciate if anyone can enlighten me.

    I'm trying to make a form application using Visual C# 2010 express that allows a user to enter an hourly pay rate. Once entered and they click a button, if the value's under 7.50 or over 49.99, ideally I'd display an error message and give them a second crack at it. If they fail on the second attempt, then I make the button invisible, display an error message and essentially end the program. Also, if they enter a valid value whether on the first or second attempt, I'd make the button disappear and display the hourly and weekly pay rate. I think I got most of the code right but I keep getting stuck on how to make the button disappear in case they fail on the second attempt. Keep in mind I haven't learned about loops as of yet so I'm trying to get this done without the use of any loops, just if/if-else statements. Here's my code:

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace SecondChancePayRateGUI
    {
    public partial class SecondChancePayRateForm : Form
    {
    public SecondChancePayRateForm()
    {
    InitializeComponent();
    }
    
    private void button1_Click(object sender, EventArgs e)
    {
    resultDisplay.Visible = true;
    const double lowLimit = 7.50,
    highLimit = 49.99;
    string inputString;
    double hourlyPayRate,
    weeklyPayRate;
    inputString = textBox1.Text;
    hourlyPayRate = Convert.ToDouble(inputString);
    weeklyPayRate = hourlyPayRate * 40;
    if (hourlyPayRate < lowLimit || hourlyPayRate > highLimit)
    {
    resultDisplay.Text = String.Format("Invalid, you get one more chance!");
    }
    else
    {
    resultDisplay.Text = String.Format("Here's your hourly pay rate: {0}" +
    "...and your weekly pay rate: {1}", hourlyPayRate.ToString("C"), weeklyPayRate.ToString("C"));
    button1.Visible = false;
    }
    } 
    }
    }
    If I didn't mention something that's needed to know, please ask! Any help would be appreciated!

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: [C#, Win7, Visual C# 2010 express] Help on creating a particular form!

    You could do something like this.
    Code:
            static int buttonClickCount = 0;
            private void button1_Click(object sender, EventArgs e)
            {
                buttonClickCount++;
                if (buttonClickCount == 1)
                {
                    //button was clicked the first time 
                }
                else if (buttonClickCount == 2)
                {
                    //button was clicked the second time
                }
            }

  3. #3
    Join Date
    Dec 2013
    Posts
    2

    Lightbulb Re: [C#, Win7, Visual C# 2010 express] Help on creating a particular form!

    I was trying the count method before but I was declaring the buttonClickCount variable inside the button1_Click method instead of outside it! I never realized I can declare variables there without them being affected by the button1_Click method! Thanks a ton for your help Shuja! Appreciate it!

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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center