Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3
This is the forum to discuss the Wrox book Beginning C# 3.0 : An Introduction to Object Oriented Programming by Jack Purdum; ISBN: 9780470261293
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 9th, 2010, 11:25 PM
Registered User
 
Join Date: Mar 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 3 exercise 2

When I click the buttons nothing happens. Can't figure out why.

Code:
using System;
using System.Windows.Forms;

public class frmMain : Form
{
    private TextBox txtOperand1;
    private Label txtResult;
    private Button btnCalc;
    private Button btnExit;
    private Label label1;
    #region Windows code
    private void InitializeComponent()
    {
        this.label1 = new System.Windows.Forms.Label();
        this.txtOperand1 = new System.Windows.Forms.TextBox();
        this.txtResult = new System.Windows.Forms.Label();
        this.btnCalc = new System.Windows.Forms.Button();
        this.btnExit = new System.Windows.Forms.Button();
        this.SuspendLayout();
        // 
        // label1
        // 
        this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
        this.label1.Location = new System.Drawing.Point(24, 19);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(100, 23);
        this.label1.TabIndex = 0;
        this.label1.Text = "enter temp";
        this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
        // 
        // txtOperand1
        // 
        this.txtOperand1.Location = new System.Drawing.Point(144, 21);
        this.txtOperand1.Name = "txtOperand1";
        this.txtOperand1.Size = new System.Drawing.Size(100, 20);
        this.txtOperand1.TabIndex = 1;
        // 
        // txtResult
        // 
        this.txtResult.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
        this.txtResult.Location = new System.Drawing.Point(24, 64);
        this.txtResult.Name = "txtResult";
        this.txtResult.Size = new System.Drawing.Size(220, 23);
        this.txtResult.TabIndex = 2;
        // 
        // btnCalc
        // 
        this.btnCalc.Location = new System.Drawing.Point(24, 121);
        this.btnCalc.Name = "btnCalc";
        this.btnCalc.Size = new System.Drawing.Size(126, 23);
        this.btnCalc.TabIndex = 3;
        this.btnCalc.Text = "click here to calculate";
        this.btnCalc.UseVisualStyleBackColor = true;
        // 
        // btnExit
        // 
        this.btnExit.Location = new System.Drawing.Point(169, 121);
        this.btnExit.Name = "btnExit";
        this.btnExit.Size = new System.Drawing.Size(75, 23);
        this.btnExit.TabIndex = 4;
        this.btnExit.Text = "exit";
        this.btnExit.UseVisualStyleBackColor = true;
        // 
        // frmMain
        // 
        this.ClientSize = new System.Drawing.Size(284, 167);
        this.Controls.Add(this.btnExit);
        this.Controls.Add(this.btnCalc);
        this.Controls.Add(this.txtResult);
        this.Controls.Add(this.txtOperand1);
        this.Controls.Add(this.label1);
        this.Name = "frmMain";
        this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        this.Text = "Temp Convertor";
        this.ResumeLayout(false);
        this.PerformLayout();

    }
    #endregion

    public frmMain()
    {
        InitializeComponent();
        txtResult.Visible = false;
    }

    public static void Main()
    {
        frmMain main = new frmMain();
        Application.Run(main);
    }

    private void btnCalc_Click(object sender, EventArgs e)
    {
        bool flag;
        double operand1;
        double answer;

        flag = double.TryParse(txtOperand1.Text, out operand1);
        if (flag == false)
        {
            MessageBox.Show("Please enter in a correct temp", "Input Eror");
            txtOperand1.Focus();
            return;
        }

        answer = 5.0 / 9.0 * (operand1 - 32);

        txtResult.Text = operand1.ToString() + "is" + answer.ToString() + "Celsius";
        txtResult.Visible = true;
    }

    private void btnExit_Click(object sender, EventArgs e)
    {
        Close();
    }

}
  #2 (permalink)  
Old March 11th, 2010, 01:44 AM
Friend of Wrox
Points: 1,166, Level: 13
Points: 1,166, Level: 13 Points: 1,166, Level: 13 Points: 1,166, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default

I typed in the program as you wrote it and it worked fine. Did you set the project properties so the output is a Windows type?

If that fails, copy the calc code to the clipboard, delete the current calc button, add a new calc button, and then copy the old calc code into the button's click event. Sometimes I think VS get lost and this fixes it. Give it a try.
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
The Following User Says Thank You to DrPurdum For This Useful Post:
weekapaugh (March 11th, 2010)
  #3 (permalink)  
Old March 11th, 2010, 02:28 AM
Registered User
 
Join Date: Mar 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks. I tried that and got everything working.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 5 Exercise 2 diango BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 4 February 1st, 2011 03:24 PM
Chapter 5 exercise 3 Will BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4 2 September 27th, 2009 02:41 PM
Chapter 3 - Exercise 3 AndyN BOOK: Beginning Cryptography with Java 3 August 16th, 2006 03:09 PM
Chapter 5 - Exercise 1 scgtman BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 3 May 16th, 2006 08:10 PM
Chapter 8, Exercise 4 cjo BOOK: Beginning ASP.NET 1.0 0 November 3rd, 2003 02:26 PM



All times are GMT -4. The time now is 05:05 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.