Sunday, February 19, 2012

voice calculator

Here is the prerequisite.
Add System.Speech as a reference. Right click on references, choose add a reference. Then click on Net, then find System.Speech.
The program in this example is named CalcualtorDict

---------- Form1.Designer.cs ----------
namespace CalculatorDict
{
partial class Form1
{
///
/// Required designer variable.
///

private System.ComponentModel.IContainer components = null;

///
/// Clean up any resources being used.
///

/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (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.num1Label = new System.Windows.Forms.Label();
this.signLabel = new System.Windows.Forms.Label();
this.num2Label = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
this.equalLabel = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// num1Label
//
this.num1Label.AutoSize = true;
this.num1Label.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.num1Label.Location = new System.Drawing.Point(194, 95);
this.num1Label.Name = "num1Label";
this.num1Label.Size = new System.Drawing.Size(0, 31);
this.num1Label.TabIndex = 0;
//
// signLabel
//
this.signLabel.AutoSize = true;
this.signLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.signLabel.Location = new System.Drawing.Point(103, 133);
this.signLabel.Name = "signLabel";
this.signLabel.Size = new System.Drawing.Size(86, 31);
this.signLabel.TabIndex = 1;
this.signLabel.Text = "label1";
//
// num2Label
//
this.num2Label.AutoSize = true;
this.num2Label.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.num2Label.Location = new System.Drawing.Point(197, 176);
this.num2Label.Name = "num2Label";
this.num2Label.Size = new System.Drawing.Size(0, 31);
this.num2Label.TabIndex = 2;
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.Black;
this.panel1.Location = new System.Drawing.Point(109, 211);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(228, 11);
this.panel1.TabIndex = 3;
//
// equalLabel
//
this.equalLabel.AutoSize = true;
this.equalLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.equalLabel.Location = new System.Drawing.Point(172, 242);
this.equalLabel.Name = "equalLabel";
this.equalLabel.Size = new System.Drawing.Size(0, 29);
this.equalLabel.TabIndex = 4;
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(297, 13);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(160, 21);
this.comboBox1.TabIndex = 5;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(487, 302);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.equalLabel);
this.Controls.Add(this.panel1);
this.Controls.Add(this.num2Label);
this.Controls.Add(this.signLabel);
this.Controls.Add(this.num1Label);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.Text = "CalculatorDict";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label num1Label;
private System.Windows.Forms.Label signLabel;
private System.Windows.Forms.Label num2Label;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label equalLabel;
private System.Windows.Forms.ComboBox comboBox1;
}
}

-------------------- Form1.cs ---------------
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;
using System.Speech.Recognition;
using System.Speech.Synthesis;


namespace CalculatorDict
{
public partial class Form1 : Form
{

private SpeechRecognizer rec = new SpeechRecognizer();
private String recordedText = "";
private String num1, num2;
private SpeechSynthesizer reader = new SpeechSynthesizer();

public Form1()
{
InitializeComponent();
rec.SpeechRecognized += rec_SpeechRecognized;
}

private void goDefault()
{
num1 = null; num1Label.Text = null;
num2 = null; num2Label.Text = null;
signLabel.Text = null; equalLabel.Text = null; recordedText = "";
}

private void Form1_Load(object sender, EventArgs e)
{
goDefault();
var c = new Choices();
for (var i = 0; i <= 10; i++)
c.Add(i.ToString());
c.Add("plus"); c.Add("add");
c.Add("subtract"); c.Add("minus");
c.Add("divide");
c.Add("multiply"); c.Add("times");
c.Add("equal"); c.Add("result");
c.Add("start"); c.Add("again");
var gb = new GrammarBuilder(c);
var g = new Grammar(gb);
rec.LoadGrammar(g);
rec.Enabled = true;
}

private bool check(String value)
{
switch (value.ToLower())
{
case "plus":
case "add":
signLabel.Text = "+"; return true;

case "subtract":
case "minus":
signLabel.Text = "-";
return true;
case "divide":
signLabel.Text = ":";
return true;
case "multiply":
case "times":
signLabel.Text = "X";
return true;
default:
break;
}
return false;
}

private int calculate(int n, int nn)
{
switch (signLabel.Text.ToLower())
{
case "+":
return n + nn;
case "-":
return n - nn;
case "x":
return n * nn;
case ":":
return n / nn;
default:
break;
}
return -1;
}

void rec_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
String value=comboBox1.Text = e.Result.Text;
bool num = false;
for (var i = 0; i <= 10; i++)
{
if (value.Equals(i.ToString()))
{
recordedText += i; num = true; break;
}
}
if (!num && num1==null && recordedText.Trim().Length>0) {
if (check(value)) { num1Label.Text=num1 = recordedText; recordedText = ""; }
}
if ( (value.ToLower().Equals("equal") || value.ToLower().Equals("result") ) && num1!=null && signLabel.Text!=null && recordedText.Trim().Length>0)
{
num1 = null;
num2Label.Text=num2 = recordedText; recordedText = "";
int n = Convert.ToInt32(num1);
int nn = Convert.ToInt32(num2);
int result=calculate(n, nn);
equalLabel.Text = "" + result;
reader.SpeakAsync(equalLabel.Text);
}
if(value.ToLower().Equals("again") )
{
goDefault();
}
}
}
}

=================






It took time to write this app. To show support to the author and to keep this site free and running, please donate or do one of the following. Thank you.

- Visit irap123.com many times a day
- Join irap123.com
- Buy my app irap123 (rhyming dictionary) available for android, and iphone. On windows phone, it is called iLyrics. If you not you can get the desktop version at www.irap123.com/apps/webstore/
- Include irap123.com in your blogs, forums, facebook walls, email footers, comments
- send a donation at my paypal address at cbdsigned.vevo@gmail.com

Wholesale Fleece Blankets

Sunday, September 25, 2011

Calculator Example

This is the calculator example.
The first is Form1.cs
=====================
//Author Cheikh Drame
/*
//Author: Cheikh Drame
//To support, please do one of the following
//- Visit irap123.com many times a day
//- Join irap123.com
//- Buy my app irap123 (rhyming dictionary) available for android, and iphone. On windows phone, it is called iLyrics. If you not you can get the desktop version at www.irap123.com/apps/webstore/
//- Include irap123.com in your blogs, forums, facebook walls, email footers, comments
//- send a donation at my paypal address at cbdsigned.vevo@gmail.com
//- Buy a story at http://shop.pparzygnat.com
*/
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 CalculatorSample1
{
public partial class Form1 : Form
{
private Button[] ops;
private char choice = ' ';
private long firstNumber = 0;
private bool fN = false;

public Form1()
{
InitializeComponent();
ops = new Button[] { addButton, minusButton, divButton, MulButton, ModButton};
}

private void highlightOperation(int i)
{
ops[i].BackColor = Color.Red;
for (int j = 0; j < ops.Length; ++j)
{
if (j != i) ops[j].BackColor = Color.White;
}
if (fN == false) { fN = true; firstNumber = getNumber(); textBox1.Text = ""; this.Text = "" + firstNumber + " "+choice+" "; }
else { textBox1.Text = ""; this.Text = "" + firstNumber + " " + choice + " "; }
textBox1.Select();
}

private void uncheckOps()
{
for (int j = 0; j < ops.Length; ++j)
{
ops[j].BackColor = Color.White;
}
}

private void appendText(String c)
{
if (textBox1.Text.Length < 10) { textBox1.AppendText(c); }
textBox1.Select();
}

private long getNumber()
{
long num = 0;
try
{
num = Convert.ToInt64(textBox1.Text);
}
catch (OverflowException)
{
num = 0;
}

return num;
}

private void calculate(long n2)
{
switch (choice)
{
case '+':
firstNumber += n2;
break;
case '-':
firstNumber -= n2;
break;
case '/':
firstNumber /= n2;
break;
case '*':
firstNumber *= n2;
break;
case '%':
firstNumber %= n2;
break;
default:
firstNumber = 0;
break;
}
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void addButton_Click(object sender, EventArgs e)
{
choice = '+';
highlightOperation(0);
}

private void minusButton_Click(object sender, EventArgs e)
{
choice = '-';
highlightOperation(1);
}

private void divButton_Click(object sender, EventArgs e)
{
choice = '/';
highlightOperation(2);
}

private void MulButton_Click(object sender, EventArgs e)
{
choice = '*';
highlightOperation(3);
}

private void ModButton_Click(object sender, EventArgs e)
{
choice = '%';
highlightOperation(4);
}

private void oneButton_Click(object sender, EventArgs e)
{
appendText("1");
}

private void TwoButton_Click(object sender, EventArgs e)
{
appendText("2");
}

private void ThreeButton_Click(object sender, EventArgs e)
{
appendText("3");
}

private void fourButton_Click(object sender, EventArgs e)
{
appendText("4");
}

private void fiveButton_Click(object sender, EventArgs e)
{
appendText("5");
}

private void sixButton_Click(object sender, EventArgs e)
{
appendText("6");
}

private void sevenButton_Click(object sender, EventArgs e)
{
appendText("7");
}

private void eightButton_Click(object sender, EventArgs e)
{
appendText("8");
}

private void nineButton_Click(object sender, EventArgs e)
{
appendText("9");
}

private void zeroButton_Click(object sender, EventArgs e)
{
appendText("0");
}

private void clearButton_Click(object sender, EventArgs e)
{
textBox1.Text = ""; choice = ' '; fN = false;
this.Text = "";
uncheckOps();
}

private void equalButton_Click(object sender, EventArgs e)
{
if (choice != ' ' && textBox1.Text.Length>0)
{
long num2 = getNumber();
calculate(num2);
this.Text += ""+num2+" = " + firstNumber;
textBox1.Text = "" + firstNumber;
}
}

private void Form1_DoubleClick(object sender, EventArgs e)
{

}

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{/*we limit the number of chars, and we only take digits*/
if ( (textBox1.Text.Length < 10 && Char.IsDigit((char)e.KeyValue)) || e.KeyData==Keys.Back) { }
else { e.SuppressKeyPress = true; }
}
}
}

======================
The second one is Form1.designer.cs
====================================
namespace CalculatorSample1
{
partial class Form1
{
///
/// Required designer variable.
///

private System.ComponentModel.IContainer components = null;

///
/// Clean up any resources being used.
///

/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (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.addButton = new System.Windows.Forms.Button();
this.minusButton = new System.Windows.Forms.Button();
this.divButton = new System.Windows.Forms.Button();
this.MulButton = new System.Windows.Forms.Button();
this.ModButton = new System.Windows.Forms.Button();
this.oneButton = new System.Windows.Forms.Button();
this.TwoButton = new System.Windows.Forms.Button();
this.ThreeButton = new System.Windows.Forms.Button();
this.fourButton = new System.Windows.Forms.Button();
this.fiveButton = new System.Windows.Forms.Button();
this.sixButton = new System.Windows.Forms.Button();
this.sevenButton = new System.Windows.Forms.Button();
this.eightButton = new System.Windows.Forms.Button();
this.nineButton = new System.Windows.Forms.Button();
this.zeroButton = new System.Windows.Forms.Button();
this.clearButton = new System.Windows.Forms.Button();
this.equalButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(1, 2);
this.textBox1.MaxLength = 10;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(339, 20);
this.textBox1.TabIndex = 0;
this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.textBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown);
//
// addButton
//
this.addButton.BackColor = System.Drawing.Color.White;
this.addButton.Location = new System.Drawing.Point(1, 29);
this.addButton.Name = "addButton";
this.addButton.Size = new System.Drawing.Size(33, 23);
this.addButton.TabIndex = 1;
this.addButton.Text = "+";
this.addButton.UseVisualStyleBackColor = false;
this.addButton.Click += new System.EventHandler(this.addButton_Click);
//
// minusButton
//
this.minusButton.BackColor = System.Drawing.Color.White;
this.minusButton.Location = new System.Drawing.Point(72, 29);
this.minusButton.Name = "minusButton";
this.minusButton.Size = new System.Drawing.Size(33, 23);
this.minusButton.TabIndex = 2;
this.minusButton.Text = "-";
this.minusButton.UseVisualStyleBackColor = false;
this.minusButton.Click += new System.EventHandler(this.minusButton_Click);
//
// divButton
//
this.divButton.BackColor = System.Drawing.Color.White;
this.divButton.Location = new System.Drawing.Point(149, 29);
this.divButton.Name = "divButton";
this.divButton.Size = new System.Drawing.Size(33, 23);
this.divButton.TabIndex = 3;
this.divButton.Text = "/";
this.divButton.UseVisualStyleBackColor = false;
this.divButton.Click += new System.EventHandler(this.divButton_Click);
//
// MulButton
//
this.MulButton.BackColor = System.Drawing.Color.White;
this.MulButton.Location = new System.Drawing.Point(224, 29);
this.MulButton.Name = "MulButton";
this.MulButton.Size = new System.Drawing.Size(33, 23);
this.MulButton.TabIndex = 4;
this.MulButton.Text = "*";
this.MulButton.UseVisualStyleBackColor = false;
this.MulButton.Click += new System.EventHandler(this.MulButton_Click);
//
// ModButton
//
this.ModButton.BackColor = System.Drawing.Color.White;
this.ModButton.Location = new System.Drawing.Point(295, 28);
this.ModButton.Name = "ModButton";
this.ModButton.Size = new System.Drawing.Size(33, 23);
this.ModButton.TabIndex = 5;
this.ModButton.Text = "%";
this.ModButton.UseVisualStyleBackColor = false;
this.ModButton.Click += new System.EventHandler(this.ModButton_Click);
//
// oneButton
//
this.oneButton.BackColor = System.Drawing.SystemColors.Highlight;
this.oneButton.Location = new System.Drawing.Point(40, 74);
this.oneButton.Name = "oneButton";
this.oneButton.Size = new System.Drawing.Size(33, 23);
this.oneButton.TabIndex = 6;
this.oneButton.Text = "1";
this.oneButton.UseVisualStyleBackColor = false;
this.oneButton.Click += new System.EventHandler(this.oneButton_Click);
//
// TwoButton
//
this.TwoButton.BackColor = System.Drawing.SystemColors.Highlight;
this.TwoButton.Location = new System.Drawing.Point(90, 74);
this.TwoButton.Name = "TwoButton";
this.TwoButton.Size = new System.Drawing.Size(33, 23);
this.TwoButton.TabIndex = 7;
this.TwoButton.Text = "2";
this.TwoButton.UseVisualStyleBackColor = false;
this.TwoButton.Click += new System.EventHandler(this.TwoButton_Click);
//
// ThreeButton
//
this.ThreeButton.BackColor = System.Drawing.SystemColors.Highlight;
this.ThreeButton.Location = new System.Drawing.Point(139, 74);
this.ThreeButton.Name = "ThreeButton";
this.ThreeButton.Size = new System.Drawing.Size(33, 23);
this.ThreeButton.TabIndex = 8;
this.ThreeButton.Text = "3";
this.ThreeButton.UseVisualStyleBackColor = false;
this.ThreeButton.Click += new System.EventHandler(this.ThreeButton_Click);
//
// fourButton
//
this.fourButton.BackColor = System.Drawing.SystemColors.Highlight;
this.fourButton.Location = new System.Drawing.Point(189, 74);
this.fourButton.Name = "fourButton";
this.fourButton.Size = new System.Drawing.Size(33, 23);
this.fourButton.TabIndex = 9;
this.fourButton.Text = "4";
this.fourButton.UseVisualStyleBackColor = false;
this.fourButton.Click += new System.EventHandler(this.fourButton_Click);
//
// fiveButton
//
this.fiveButton.BackColor = System.Drawing.SystemColors.Highlight;
this.fiveButton.Location = new System.Drawing.Point(238, 74);
this.fiveButton.Name = "fiveButton";
this.fiveButton.Size = new System.Drawing.Size(33, 23);
this.fiveButton.TabIndex = 10;
this.fiveButton.Text = "5";
this.fiveButton.UseVisualStyleBackColor = false;
this.fiveButton.Click += new System.EventHandler(this.fiveButton_Click);
//
// sixButton
//
this.sixButton.BackColor = System.Drawing.SystemColors.Highlight;
this.sixButton.Location = new System.Drawing.Point(40, 125);
this.sixButton.Name = "sixButton";
this.sixButton.Size = new System.Drawing.Size(33, 23);
this.sixButton.TabIndex = 11;
this.sixButton.Text = "6";
this.sixButton.UseVisualStyleBackColor = false;
this.sixButton.Click += new System.EventHandler(this.sixButton_Click);
//
// sevenButton
//
this.sevenButton.BackColor = System.Drawing.SystemColors.Highlight;
this.sevenButton.Location = new System.Drawing.Point(90, 125);
this.sevenButton.Name = "sevenButton";
this.sevenButton.Size = new System.Drawing.Size(33, 23);
this.sevenButton.TabIndex = 12;
this.sevenButton.Text = "7";
this.sevenButton.UseVisualStyleBackColor = false;
this.sevenButton.Click += new System.EventHandler(this.sevenButton_Click);
//
// eightButton
//
this.eightButton.BackColor = System.Drawing.SystemColors.Highlight;
this.eightButton.Location = new System.Drawing.Point(139, 125);
this.eightButton.Name = "eightButton";
this.eightButton.Size = new System.Drawing.Size(33, 23);
this.eightButton.TabIndex = 13;
this.eightButton.Text = "8";
this.eightButton.UseVisualStyleBackColor = false;
this.eightButton.Click += new System.EventHandler(this.eightButton_Click);
//
// nineButton
//
this.nineButton.BackColor = System.Drawing.SystemColors.Highlight;
this.nineButton.Location = new System.Drawing.Point(189, 125);
this.nineButton.Name = "nineButton";
this.nineButton.Size = new System.Drawing.Size(33, 23);
this.nineButton.TabIndex = 14;
this.nineButton.Text = "9";
this.nineButton.UseVisualStyleBackColor = false;
this.nineButton.Click += new System.EventHandler(this.nineButton_Click);
//
// zeroButton
//
this.zeroButton.BackColor = System.Drawing.SystemColors.Highlight;
this.zeroButton.Location = new System.Drawing.Point(238, 125);
this.zeroButton.Name = "zeroButton";
this.zeroButton.Size = new System.Drawing.Size(33, 23);
this.zeroButton.TabIndex = 15;
this.zeroButton.Text = "0";
this.zeroButton.UseVisualStyleBackColor = false;
this.zeroButton.Click += new System.EventHandler(this.zeroButton_Click);
//
// clearButton
//
this.clearButton.BackColor = System.Drawing.Color.Red;
this.clearButton.Location = new System.Drawing.Point(1, 189);
this.clearButton.Name = "clearButton";
this.clearButton.Size = new System.Drawing.Size(339, 23);
this.clearButton.TabIndex = 16;
this.clearButton.Text = "clear";
this.clearButton.UseVisualStyleBackColor = false;
this.clearButton.Click += new System.EventHandler(this.clearButton_Click);
//
// equalButton
//
this.equalButton.BackColor = System.Drawing.Color.LawnGreen;
this.equalButton.Location = new System.Drawing.Point(1, 218);
this.equalButton.Name = "equalButton";
this.equalButton.Size = new System.Drawing.Size(339, 23);
this.equalButton.TabIndex = 17;
this.equalButton.Text = "=";
this.equalButton.UseVisualStyleBackColor = false;
this.equalButton.Click += new System.EventHandler(this.equalButton_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(340, 246);
this.Controls.Add(this.equalButton);
this.Controls.Add(this.clearButton);
this.Controls.Add(this.zeroButton);
this.Controls.Add(this.nineButton);
this.Controls.Add(this.eightButton);
this.Controls.Add(this.sevenButton);
this.Controls.Add(this.sixButton);
this.Controls.Add(this.fiveButton);
this.Controls.Add(this.fourButton);
this.Controls.Add(this.ThreeButton);
this.Controls.Add(this.TwoButton);
this.Controls.Add(this.oneButton);
this.Controls.Add(this.ModButton);
this.Controls.Add(this.MulButton);
this.Controls.Add(this.divButton);
this.Controls.Add(this.minusButton);
this.Controls.Add(this.addButton);
this.Controls.Add(this.textBox1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.Text = "Calculator Sample";
this.Load += new System.EventHandler(this.Form1_Load);
this.DoubleClick += new System.EventHandler(this.Form1_DoubleClick);
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button addButton;
private System.Windows.Forms.Button minusButton;
private System.Windows.Forms.Button divButton;
private System.Windows.Forms.Button MulButton;
private System.Windows.Forms.Button ModButton;
private System.Windows.Forms.Button oneButton;
private System.Windows.Forms.Button TwoButton;
private System.Windows.Forms.Button ThreeButton;
private System.Windows.Forms.Button fourButton;
private System.Windows.Forms.Button fiveButton;
private System.Windows.Forms.Button sixButton;
private System.Windows.Forms.Button sevenButton;
private System.Windows.Forms.Button eightButton;
private System.Windows.Forms.Button nineButton;
private System.Windows.Forms.Button zeroButton;
private System.Windows.Forms.Button clearButton;
private System.Windows.Forms.Button equalButton;
}
}

=================
This is the youtube video



$40 off Craftsman 5 Drawer Homeowner Tool Center with Riser and Parts Bins $99.99 on sale 10/2-10/8
Sears Deal of the Day: Thule Car Top Carrier, Quest
Wholesale Fleece Blankets
400950_BuddhaGroove.com-Culture Infused Living: Home Accents, Jewelry, Accessories from around the world!
400948_Culture Infused Living: Home Accents, Jewelry, and accessories from around the world. CulturalElemen
504427_Save up to 75% on batteries and accessories at Brooklyn Battery Works!
504080_10% OFF Orders of $75 or More from Journelle.com! Use Promo Code: NOV11 (Valid 11/1 - 11/30/11)
502239_Brand names, bargain prices at shoezoo.com. If you don't love your new shoes, return them for free!

400949_GaneshMall.com-Culture Infused Living: Home Accents, Jewelry, and accessories from around the world!

Thursday, September 15, 2011

ScreenSaver Example

This is the ScreenSaver example partial code. To get the complete program working, you need to watch the youtube video.
There are many things you can change to practice. You can change the interval of the timer to make it faster. For instance: timer1.Interval=100; will make it move very fast. Also, instead of the images changes by clicking you can make it change after each position (top, center, bottom) and so on. The possibilities are endless.



================================
================================
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 ScreenSaver1
{
public partial class Form1 : Form
{
private Image[] imgs = { ScreenSaver1.Properties.Resources.Autumn_Leaves,
ScreenSaver1.Properties.Resources.Creek,
ScreenSaver1.Properties.Resources.Desert_Landscape,
ScreenSaver1.Properties.Resources.Dock,
ScreenSaver1.Properties.Resources.Forest};
private int next = 1;
private int position = 0;//0 is top left, 1 is center, 2 is bottom right

public Form1()
{
InitializeComponent();
}

private void timer1_Tick(object sender, EventArgs e)
{
switch (position)
{
case 0:
this.Location = new Point(1, 1);
break;
case 1:
this.CenterToScreen();
break;
case 2:
this.Location = new Point(Screen.PrimaryScreen.Bounds.Width - this.Width, Screen.PrimaryScreen.Bounds.Height - this.Height);
break;
default:
break;
}
position = (position + 1) % 3;
}

private void Form1_Load(object sender, EventArgs e)
{
this.MinimumSize= this.MaximumSize = this.Size;
this.timer1.Interval = 2000;
this.timer1.Start();
this.Location = new Point(1, 1);
}

private void Form1_Click(object sender, EventArgs e)
{
this.BackgroundImage = this.imgs[++next % imgs.Length];
}
}
}


$40 off Craftsman 5 Drawer Homeowner Tool Center with Riser and Parts Bins $99.99 on sale 10/2-10/8
Sears Deal of the Day: Thule Car Top Carrier, Quest
Wholesale Fleece Blankets
400950_BuddhaGroove.com-Culture Infused Living: Home Accents, Jewelry, Accessories from around the world!
400948_Culture Infused Living: Home Accents, Jewelry, and accessories from around the world. CulturalElemen
504427_Save up to 75% on batteries and accessories at Brooklyn Battery Works!
504080_10% OFF Orders of $75 or More from Journelle.com! Use Promo Code: NOV11 (Valid 11/1 - 11/30/11)
502239_Brand names, bargain prices at shoezoo.com. If you don't love your new shoes, return them for free!

400949_GaneshMall.com-Culture Infused Living: Home Accents, Jewelry, and accessories from around the world!

Thursday, August 18, 2011

Introduction

This blog is to introduce you to the programming language C# through mainly examples.
The learning will be explained moderately directed mainly to the novitiate.
C# is by far the best programming language. All programming languages have strength and weaknesses. Even though Java and C++ are the most predominantly used languages, C# embody the best practices of both. It seems that every language tries to solve problems of earlier languages and then encounter new ones. So far, I have not seen any anomalies with C#, that doesn't mean there are none or will be none in the future.
Nevertheless C# is a great language to start learning, and the development software are easy to use. Writing applications with forms is 1000 times much easier than doing with C++.
You can follow my youtube videos by searching csharpmastery

$40 off Craftsman 5 Drawer Homeowner Tool Center with Riser and Parts Bins $99.99 on sale 10/2-10/8
Sears Deal of the Day: Thule Car Top Carrier, Quest
Wholesale Fleece Blankets
400950_BuddhaGroove.com-Culture Infused Living: Home Accents, Jewelry, Accessories from around the world!
400948_Culture Infused Living: Home Accents, Jewelry, and accessories from around the world. CulturalElemen
504427_Save up to 75% on batteries and accessories at Brooklyn Battery Works!
504080_10% OFF Orders of $75 or More from Journelle.com! Use Promo Code: NOV11 (Valid 11/1 - 11/30/11)
502239_Brand names, bargain prices at shoezoo.com. If you don't love your new shoes, return them for free!

400949_GaneshMall.com-Culture Infused Living: Home Accents, Jewelry, and accessories from around the world!