C# windowform Basic (1)

Embed Size (px)

DESCRIPTION

http://technohalo.com

Citation preview

IT pascal, c, c++, SQL, c# Programming C# windowform application IT Programming Languages Programming loop input output GUI (graphical user interface) C# Graphic ColorDialog OpenFileDialog SaveFileDialog windowform Public Private class object Code VisualStudio code Programming hello world Online C# IT ( ) 4th Jan 2011

() Windowform () Windowform

() Windowform () Windowform () Windowform code

() Windowform box My Computer File Edit View Tab MenuStrip Address TextBox Go Button scoll bar Window Windowform

() Windowform .NET Framework 2002 Miscrosoft OS OS http://www.microsoft.com/download/en/confirmation.aspx?id=22 .NET Frameword 3.5 sp 1 http://sevenlamp.wordpress.com/2009/07/23/dotnetframework/ .NET Framework .NET Framework dll Dynamic-link library csc.exe () Windowform notepad Start>All Programs>Accessories>Notepad Start>Run notepad Enter Notepad ( windowform ) class xxx : System.Windows.Forms.Form { private System.Windows.Forms.TextBox input1; private System.Windows.Forms.TextBox input2;

private System.Windows.Forms.Button sum; private System.Windows.Forms.Label ans; private xxx() { input1 = new System.Windows.Forms.TextBox(); input1.Location = new System.Drawing.Point(10, 10); input1.Text = "10"; Controls.Add(input1); input2 = new System.Windows.Forms.TextBox(); input2.Location = new System.Drawing.Point(130, 10); input2.Text = "20"; Controls.Add(this.input2); sum = new System.Windows.Forms.Button(); sum.Location = new System.Drawing.Point(80, 80); sum.Text = "Sum Again!"; Controls.Add(this.sum); ans = new System.Windows.Forms.Label(); ans.Location = new System.Drawing.Point(100, 160); ans.Text = "ans= 30"; Controls.Add(this.ans); sum.Click += new System.EventHandler(this.sum_Click); } private void sum_Click(object sender, System.EventArgs OurEvent) { ans.Text = "ans= " + (System.Convert.ToDouble(input1.Text) + System.Convert.ToDouble(input2.Text)).ToString(); } static void Main() { System.Windows.Forms.Application.Run(new xxx()); } }

C eg1.cs

() Windowform csc.exe .NET Framework exe Start>Run cmd OK C:\WINDOWS\system32\cmd.exe ZZ C:\Documents and Settings\ZZ> C C cd\ Enter C:\> C .NET Framework csc.exe C:\> dir csc.exe /s Enter csc.exe C dir Volume in drive C has no label.

Volume Serial Number is 98A0-05CB Directory of C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 07/25/2008 11:16 AM 1 File(s) 80,376 csc.exe 80,376 bytes

Directory of C:\WINDOWS\Microsoft.NET\Framework\v3.5 07/29/2008 11:40 PM 1 File(s) 1,548,280 csc.exe

1,548,280 bytes

Directory of C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319 03/18/2010 01:16 PM 1 File(s) Total Files Listed: 3 File(s) 3,601,208 bytes 1,972,552 csc.exe

1,972,552 bytes

0 Dir(s) 35,260,284,928 bytes free csc.exe C:\WINDOWS\Microsoft.NET\Framework\v3.5 C:\> path C:\WINDOWS\Microsoft.NET\Framework\v3.5 Enter ( C:\WINDOWS\Microsoft.NET\Framework\v3.5 Right Click Mark C:\WINDOWS\Microsoft.NET\Framework\v3.5 select Control+C C:\> Control+V paste RightClick paste ) C:\> csc.exe eg1.cs path csc.exe eg1.cs exe Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.1 for Microsoft (R) .NET Framework version 3.5 Copyright (C) Microsoft Corporation. All rights reserved. eg1.cs csc.exe eg1.exe Run C C:\> eg1.exe Enter

+ = select Sum Again ( ) ans= calculator ( ) Run C eg1.exe ( Enter ) enter

video notepad .cs .exe VisualStudio VisualStudio2008 VS2008 .exe

() Windowform code class xxx : System.Windows.Forms.Form { private System.Windows.Forms.TextBox input1; private System.Windows.Forms.TextBox input2; private System.Windows.Forms.Button sum; private System.Windows.Forms.Label ans; private xxx() { input1 = new System.Windows.Forms.TextBox(); input1.Location = new System.Drawing.Point(10, 10); input1.Text = "10"; Controls.Add(input1); input2 = new System.Windows.Forms.TextBox();

input2.Location = new System.Drawing.Point(130, 10); input2.Text = "20"; Controls.Add(this.input2); sum = new System.Windows.Forms.Button(); sum.Location = new System.Drawing.Point(80, 80); sum.Text = "Sum Again!"; Controls.Add(this.sum); ans = new System.Windows.Forms.Label(); ans.Location = new System.Drawing.Point(100, 160); ans.Text = "ans= 30"; Controls.Add(this.ans); sum.Click += new System.EventHandler(this.sum_Click); } private void sum_Click(object sender, System.EventArgs OurEvent) { ans.Text = "ans= " + (System.Convert.ToDouble(input1.Text) + System.Convert.ToDouble(input2.Text)).ToString(); } static void Main() { System.Windows.Forms.Application.Run(new xxx()); } }

notepad {} class xxx : System.Windows.Forms.Form { }

c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll http://msdn.microsoft.com/en-us/library/system.windows.forms.control_members %28v=VS.90%29.aspx

VisualStudio VisualStudio2008

class xxx : System.Windows.Forms.Form System.Window.Forms. Form code xxx xxx class class member Constructer, method, properties, event dll(Dynamic-link library) System.Windows.Forms.dll

class xxx : System.Windows.Forms.Form (xxx dll Form class ) {

private System.Windows.Forms.TextBox input1; (input1 TextBox ) private System.Windows.Forms.TextBox input2; (input1 TextBox ) private System.Windows.Forms.Button sum; (sum Button ) private System.Windows.Forms.Label ans; (ans label ) private xxx() ( Method ) { input1 = new System.Windows.Forms.TextBox(); (input1 TextBox class xxx : System.Windows.Forms.Form {} xxx(){} method TextBox xxx(){} ) input1.Location = new System.Drawing.Point(10, 10);

System.Drawing.dll textBox (0,0) WindowForm

input1.Text = "10"; ( ) input.Location input.Text VS2008 . input )

Controls.Add(input1); ( Control Collection input1 ) input2 = new System.Windows.Forms.TextBox(); input2.Location = new System.Drawing.Point(130, 10); input2.Text = "20"; Controls.Add(this.input2); sum = new System.Windows.Forms.Button(); sum.Location = new System.Drawing.Point(80, 80); sum.Text = "Sum Again!"; Controls.Add(this.sum); ans = new System.Windows.Forms.Label(); ans.Location = new System.Drawing.Point(100, 160); ans.Text = "ans= 30"; Controls.Add(this.ans);

sum.Click += new System.EventHandler(this.sum_Click); ( sum.Click sum button sum_Click event ) } private void sum_Click(object sender, System.EventArgs OurEvent) { sum button ans.Text = "ans= " + (System.Convert.ToDouble(input1.Text) + System.Convert.ToDouble(input2.Text)).ToString(); ans.Text ans ans= ans= + . System.Convert.ToDouble(input1.Text) System.dll Convert ToDouble() () double type double int input2 Double double double ans lable double .ToString() double } static void Main() ( static void ) { System.Windows.Forms.Application.Run(new xxx()); (dll Application Run xxx() ) } }

Main() Main() xxx() Run xxx()

Click Event Windowform VisualStudio Controls.Add(this.input2); input2.ForeColor = System.Drawing.Color.Lime; input2.BackColor = System.Drawing.Color.Black; )

comment [email protected] http://technohalo.com 5 Jan 2012