Click here to Skip to main content
15,914,416 members
Home / Discussions / C#
   

C#

 
GeneralRe: Expressions(calculations) Pin
Stefan Troschuetz24-May-04 21:16
Stefan Troschuetz24-May-04 21:16 
GeneralRe: Expressions(calculations) Pin
sreejith ss nair24-May-04 22:07
sreejith ss nair24-May-04 22:07 
GeneralRe: Expressions(calculations) Pin
Stefan Troschuetz24-May-04 22:38
Stefan Troschuetz24-May-04 22:38 
GeneralRe: Expressions(calculations) Pin
stevemasters2225-May-04 17:09
stevemasters2225-May-04 17:09 
GeneralRe: Expressions(calculations) Pin
Dave Kreskowiak25-May-04 17:24
mveDave Kreskowiak25-May-04 17:24 
GeneralRe: Expressions(calculations) Pin
stevemasters2225-May-04 17:46
stevemasters2225-May-04 17:46 
GeneralRe: Expressions(calculations) Pin
Dave Kreskowiak26-May-04 0:46
mveDave Kreskowiak26-May-04 0:46 
GeneralRe: Expressions(calculations) [EDITED} Pin
Dave Kreskowiak26-May-04 3:35
mveDave Kreskowiak26-May-04 3:35 
[EDIT]
I've reposted this because I found a couple typos after I posted it...

OK. Here's the modified sample. Warning!!!! This is COMPLETELY UNTESTED CODE!
I'm still at work, with nothing much else to do Big Grin | :-D and wrote this from memory using Notepad of all things!

But, Stephan is right about experimenting with the events. Just try writing code for the various event handlers. It doesn't have to be anything special, maybe just displaying a descriptive MsgBox when the event handler is called.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
 
namespace WindowsApplication5
{
    /// 
    /// Summary description for Form1.
    /// 
    public class Form1 : System.Windows.Forms.Form
    {
        Single m_Labour = 0.0;
        Single m_Material = 0.0;
        private System.Windows.Forms.TextBox textBox3;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.TextBox textBox2;
        /// 
        /// Required designer variable.
        /// 
        private System.ComponentModel.Container components = null;
 
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
 
        /// 
        /// Clean up any resources being used.
        /// 
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
 
#region Windows Form Designer generated code
        /// 
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// 
        private void InitializeComponent()
        {
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.textBox3 = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(64, 56);
            this.textBox1.Name = "textBox1";
            this.textBox1.TabIndex = 0;
            this.textBox1.Text = "";
            this.textBox1.Leave += new System.EventHandler(this.textBox1_Leave);
            // 
            // textBox2
            // 
            this.textBox2.Location = new System.Drawing.Point(184, 56);
            this.textBox2.Name = "textBox2";
            this.textBox2.TabIndex = 1;
            this.textBox2.Text = "";
            this.textBox2.Leave += new System.EventHandler(this.textBox2_Leave);
            // 
            // textBox3
            // 
            this.textBox3.Location = new System.Drawing.Point(112, 104);
            this.textBox3.Name = "textBox3";
            this.textBox3.TabIndex = 2;
            this.textBox3.Text = "";
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.Add(this.textBox3);
            this.Controls.Add(this.textBox2);
            this.Controls.Add(this.textBox1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);
        }
#endregion
 
        /// 
        /// The main entry point for the application.
        /// 
        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }
 
        private void textBox1_Leave(object sender, System.EventArgs e)
        {
            m_Labour = ValidateInput(textbox1);
            textbox1.Text = m_Labour.ToString("##,###.00");
            UpdateTotalTextBox();
        }
 
        private void textBox2_TextChanged(object sender, System.EventArgs e)
        {
            m_Material = ValidateInput(textbox2);
            textbox2.Text = m_Material.ToString("##,###.00");
            UpdateTotalTextBox();
        }
 
        private Single ValidateInput(ref TextBox textboxToValidate)
        {
            Single returnValue;
 
            try
            {
                returnValue = Single.Parse(textboxToValidate.Text);
            }
            catch (Exception e)
            {
                returnValue = 0;
            }
            return returnValue;
        }
 
        private void UpdateTotalTextbox()
        {
            Single jobTotal = m_Labour + m_Material;
            textBox3.Text = jobTotal.ToString("##,###.00");
        }
    }
}



RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome

GeneralRe: Expressions(calculations) Pin
Stefan Troschuetz25-May-04 21:25
Stefan Troschuetz25-May-04 21:25 
GeneralExpressions Pin
Anonymous24-May-04 18:37
Anonymous24-May-04 18:37 
GeneralRe: Expressions Pin
sreejith ss nair24-May-04 20:03
sreejith ss nair24-May-04 20:03 
GeneralRe: Expressions Pin
sreejith ss nair24-May-04 20:03
sreejith ss nair24-May-04 20:03 
GeneralRe: Expressions Pin
Dave Kreskowiak25-May-04 0:35
mveDave Kreskowiak25-May-04 0:35 
Generalhelp! Pin
agu989924-May-04 18:14
agu989924-May-04 18:14 
GeneralRe: help! Pin
Heath Stewart25-May-04 2:44
protectorHeath Stewart25-May-04 2:44 
GeneralEnable/Disable of texbox Pin
HappyKim24-May-04 15:56
HappyKim24-May-04 15:56 
GeneralRe: Enable/Disable of texbox Pin
Dave Kreskowiak24-May-04 16:58
mveDave Kreskowiak24-May-04 16:58 
GeneralRe: Enable/Disable of texbox Pin
sreejith ss nair24-May-04 20:02
sreejith ss nair24-May-04 20:02 
GeneralRe: Enable/Disable of texbox Pin
HappyKim25-May-04 15:41
HappyKim25-May-04 15:41 
GeneralRe: Enable/Disable of texbox Pin
sreejith ss nair26-May-04 20:51
sreejith ss nair26-May-04 20:51 
GeneralRe: Enable/Disable of texbox Pin
HappyKim27-May-04 14:01
HappyKim27-May-04 14:01 
GeneralRe: Enable/Disable of texbox Pin
sreejith ss nair27-May-04 17:51
sreejith ss nair27-May-04 17:51 
GeneralRe: Enable/Disable of texbox Pin
sreejith ss nair27-May-04 18:14
sreejith ss nair27-May-04 18:14 
GeneralAccessing objects Pin
John L. DeVito24-May-04 10:29
professionalJohn L. DeVito24-May-04 10:29 
GeneralRe: Accessing objects Pin
frank2124-May-04 10:58
frank2124-May-04 10:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.