.


:




:

































 

 

 

 


.




1.

: Windows Microsoft Visual Studio.NET.

: Microsoft Visual Studio.NET C#.

 

1.1. Visual Studio.NET.

.NET - Visual Studio.NET. 2002 . Visual Studio.NET 񳺿 Microsoft.NET ': , .NET-㳺.

³ - Visual Studio.NET 2000 . Microsoft  . , , . , , , Visual Studio 6.0, , .

- Microsoft, Visual Studio.NET. , . , .

Visual Studio.NET. //Microsoft Visual Studio 2005/Microsoft Visual Studio 2005. ' Visual Studio Start Page, . 1.1. , , . Find Samples , .

. 1.1. .

. What's New in Visual Studio 2005? VS.NET. -.

, View/Other Window/Start Page.

1.2. .

Visual Studio 2005 #. Visual Studio 2005 VB, #, C++, Setup ( ) . Visual Studio 2005, File/New/Project... ϳ ' , . 1.2. ( ) . #, Visual #. . Windows- (Windows Application), (Console Application) .

. 1.2. ³ .

Windows Application. , , . . . 1.3.

. 1.3. Visual Studio 2GGS.

 

. Solution Explorer , Class View Properties.

³ Solution Explorer , . , , , , Add/Windows Form (. 1.4). , . , , Form1 View Code. ³, View Designer. . - .

³ ClassView , (. 1.5).

 

 

 

 

Class View , , . Class View. , . Class View. Visual Studio 2005. Class View , View/Class View.

 

1.3. ³ Properties.

³ Properties . Properties . , ,

: ( ) ( ). - , , , , . . , . . , Properties , . , Properties, . , .

³ 䳿 , , . , - , 䳿. . , ' , ' , .

1.4. ³ Toolbox.

Windows Forms , . Visual Studio , View/Toolbox (. 1.8). ³ .NET Windows. Toolbox : Data, Components, Windows Forms, General . , . Windows Forms , , , . Data . Components , Timer. General - .

. 1.8. (Toolbox).

 

1.5. ³ .

. - , - Visual Studio. -, . , , Solution Explorer,

Auto Hide .

 

1.6. Visual Studio 2005.

䳿, Visual Studio 2005, . , , . , . Visual Studio 2005 . View/Toolbars (. 1.11).

ҳ , , . , Customize.

Visual Studio 2005 . , Visual Studio 2005. ( ). , . , File , . . , New File . . , Ctrl+

2. Windows- .

2.1. .

', , . , (MDI) . - .

- ', , , , , , .

, ' .NET, , System.Windows.Forms.Form. , Visual Studio Designer, . , . , Windows Forms . - , , . , . , Visual Studio Designer.

ϳ : , , . , , .

Visual Studio 2005 . Visual Studio 2005 File/New/Project... , ', Visual C# Project Windows Application. ' HelloWorld .

' . Windows Forms. Solution Explorer HelloWorld : Properties, References, Form1.cs Program.cs. , # .cs.

- Form1.cs Program. cs. Form1.cs , . Program.cs Main(), ' . . Properties Name Form1 MainForm. Properties , Visual Studio 2005 , View/Properties Window Alt+Enter.

2.2. .

. Visual Studio 2005 . Solution Explorer HelloWorld. Properties

Application .

Assembly Name ' .

Output . Windows Application, Console Application Class Library. Windows Forms Windows Application.

Default Namespace

.

Startup Object ' , Main,

Icon .

Resource File ' .

, Microsoft.NET Framework SDK Documentation, Visual Studio 2005.

, Properties/Build (. 1.13).

Configuration - .

Conditional compilation symbols . .

. 1.13. ³ Configuration Properties/Build.

 

Optimize code true .

Check for Arithmetic Overflow/Underflow .

Allow unsafe code - unsafe. Warning Level , .

Treat Warnings As Errors .

Output Path , .

XML Documentation File ' , . Tools/Build Comment Web Pages.

Generate Debugging Information . .

.

2.3. .

(. 1.3). , , .

. :

Properties Window ( View /Properties Window);

Layout Toolbar ( View/Toolbars/Layout);

Toolbox ( View/Toolbox).

. #. , Form1.cs Solution Explorer View Code. ³ Form1.cs. , # . , , , Notepad. , Visual Studio 2005, :

1) Program. cs - . using System;

using System.Collections.Generic; using System.Windows.Forms; namespace HelloWorld { static class Program { /// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread] static void Main()

{ Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm());

}

}}

.

using System;

using System.Collections.Generic; using System.Windows.Forms;

, . - using . . namespace HelloWorld

HelloWorld. Program Main.

static void Main()

{

Application.Run(new MainForm());

Main , , . Main() , MainForm.

2) Form1.cs MainForm. HelloWorld, Program, Main. , , ' ': HelloWorld.MainForm.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace HelloWorld

{ public partial class MainForm: Form {

public MainForm()

{

InitializeComponent();

}

}}

3) MainForm Form 1.Designer.cs. InitializeComponent() .

namespace HelloWorld { partial class MainForm { private System.ComponentModel.IContainer components = null; protected override void Dispose(bool disposing)

{ if (disposing && (components!= null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows Form Designer generated code private void InitializeComponent()

{

this.SuspendLayout();

//

// MainForm

this.AutoScaleDimensions = new System.Drawing.Size(6F, 13F);

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(292, 266); this.Name = "MainForm"; this.Text = "Forml"; this.ResumeLayout(false);

}

#endregion

}

}

2.4. .

, , Build/Build HelloWorld. ' - ErrorList ( ) Output. , , . . Visual Studio .

Output . ³ View/Output. . :

--- Build started: Project: HelloWorld, Configuration: Debug Any CPU ---

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4/define:DEBUG;TRACE /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50 72 7\System.Data. dll

/reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50 72 7\System.Deplo yment.dll

/reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50 72 7\System.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50 72 7\System.Drawi ng.dll

/reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50 72 7\System.Windo ws.Forms.dll

/reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50 72 7\System.Xml.d ll /debug+ /debug:full /optimize- /out:obj\Debug\HelloWorld.exe /resource:obj\Debug\HelloWorld.MainForm.resources /resource:obj\Debug\HelloWorld.Properties.Resources.resources /target:winexe Forml.cs Forml.Designer.cs Program.cs Properties\AssemblyInfo.cs Properties\Resources.Designer.cs Properties\Settings.Designer.cs

Compile complete - 0 errors, 0 warnings

HelloWorld -> C:\Documents and Settings\User\Moi \Visual Studio 2005\Proj ects\HelloWorld\HelloWorld\bin\Debug\HelloWorld.exe ========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped

, .

.

2.5. .

Visual Studio 2005 : . Debug/Start. . , , Debug/Start Without Debugging. (Debug/Start Without Debugging). ' (. 1.14).

Windows .

2.6. .

. , . Toolbox Button . . . Properties:

Name: HelloWorld Text:

. Properties Events. Click . Click. Visual Studio 2005 . :

private void HelloWorld_Click(object sender, System.EventArgs e)

{

}

:

private void HelloWorld_Click(object sender, System.EventArgs e)

{

MessageBox.Show(",");

}

³ . . .

2.7. .

C# . , WindowsForms. , GUI .

. NET Console. : , . ³ , . / ( , , , ), .

: Read, ReadLine, Write WriteLine, - , - .

Read . ³ int, , -1( ), . :

 

do

{ int i = Console.Read(); if (i!= -1)

Console.WriteLine("{0} {1} ", (char)i, i);

else

break;

} while (true);

.

ReadLine ( ). ' string null, .

do

{string s = Console.ReadLine(); if (s!= null)

Console.WriteLine(" : " + s); else

break; } while (true);

Write . ³ . , Write :

Console.Write (1);

Console.Write (0.754);

Console.Write("Hello!");

. . , {n} n- ( 0): string Name="";

Console.Write(", {0}", Name);

WriteLine Write , .

. , , .

³ , File/New project. Visual #, - Console Application. ' TestConsole. ³ #. . using System;

using System.Collections.Generic; using System.Text; namespace TestConsole { class Program

{ static void Main(string[] args)}

}

, . :

static void Main(string[] args)

{

// string strText;

// Console.WriteLine(" .");

// strText = Console.ReadLine();

// Console.WriteLine(" {0}", strText);

}

.

1. Windows- , .

2. Windows- , .

3. Windows- 1 2. ' 1, ' 2.

4. Windows- 1 2. ( 1) ( 2, 1 ). 2 ( ) ( ).

5. , .

.

1. Visual Studio 2005?

2. Visual Studio 2005?

3. ClassView?

4. Toolbox?

5. Properties?


2

: Windows Forms .

: Windows Forms.

1. .

(. 1.1.) : , . . Windows Application TestButtons. . :

Name - TestButtonsForm

Text -

GroupBox, RadioButton, CheckBox Button. . 1 . . , GroupBox. ' .

.1. 1. TestButtons.

:


Button1:

Text -

groupBox1:

Text -

radioButton1:

Text -

radioButton2:

Text-

radioButton3:

Text -

checkBox1:

Text -

Checked - True


, Visual Studio.NET. - TestButtons.Designer.cs) (Program.cs).

button1_Click :

private void button1_Click(object sender, EventArgs e)

{

//

string strMessage = "";

//

//

if (radioButton1.Checked == true)

{

//

strMessage = radioButton1.Text;

}

//

else if (radioButton2.Checked == true)

{

//

strMessage = radioButton2.Text;

}

//

else if (radioButton3.Checked == true)

{

//

strMessage = radioButton3.Text;

}

//, '

// ,

if (checkBox1.Checked == true)

MessageBox.Show(" " + strMessage);

}

³ . . . ' : . . '. , , .

2. .

, . - ComboBox, , CheckedListBox, . ComboBox , . .

Windows Applications TestLists. . Form1.cs TestListsForm.cs. :

GroupBox, CheckedListBox

ComboBox

Button.

2.1.

. 2.1. TestLists.

. GroupBox, . GroupBox . .

:


Text -

:

groupBox1:

Text -

checkedListBox1:

Name - memberList

comboBox1:

Name - peopleList

Text -

button1:

Name - buttonAdd

Text -

button2:

Name - buttonDelete

Text -


ComboBox CheckedListBox VisualStudio.Net. Items.

Items . ComboBox, ' peopleList, . peopleList Items. ³ StringCollectionEditor, Items. : , , .

, . ϳ . . , ( TestListsForm.cs TestListsForm.Designer.cs).

.

, , ComboBox, . buttonAdd_Click , :

private void buttonAdd_Click(object sender, System.EventArgs e)

{

//

if(peopleList.Text.Length!= 0)

{

// ,

memberList.Items.Add(peopleList.Text);

}

else

{

// ,

MessageBox.Show("

.");

} }

. memberList.Items.Add memberList. peopleList.Text, . . buttonDelete_Click.

private void buttonDelete_Click(object sender, System.EventArgs e)

{

//

while(memberList.CheckedIndices.Count > 0)

//

//

//

// CheckedIndices

//

// '

memberList.Items.RemoveAt(memberList.CheckedIndices[0]);

//

//CheckedIndices.Count

//

}

3. , .

, . , NumericUpDown . : NumericUpDown . , , .

Windows Application TestIndicator. . Forml.cs TestIndicatorForm.cs. :

TrackBar

ProgressBar

NumericUpDown.

3.

. 3. TestIndicator.

. TrackBar1:

Maximum 100

TickStyle Both

Text .

.

numericUpDown1 trackBar1 , progressBarl - . . , TrackBar Scroll, . 䳿 Scroll, 䳿 . ' trackBar1_Scroll. , :

private void trackBar1_Scroll(object sender, System.EventArgs e)

{ int Value = trackBar1.Value;

numericUpDown1.Value = Value;

progressBar1.Value = Value;

}

numericUpDown1. , : (NumericUpDown), . 䳿 ValueChanged numericUpDown1. 䳿 ValueChanged . numericUpDown1_ValueChanged. trackBar1_Scroll.

private void numericUpDown1_ValueChanged(object sender,System.EventArgs e)

{ int Value = (int)numericUpDown1.Value;

trackBar1.Value = Value;

progressBar1.Value = Value;

}

, . ³ . . . .

1. Windows-, :

) , (4 . ).

if (radioButton1.Checked == true)

{ pictureBox1.Image = Image.FromFile("C:\\11.jpg",true);}

) (4 ).

) NumericUpDown ; NumericUpDown.

1. .

2. ListBox ComboBox?

3. ?

4. Items?

5. RemoveAt?


3

: .

: Windows Forms.

1.  Toolbox

Toolbox . , - Toolbox Add Tab. , Delete Tab. Copy Paste.

Solution Explorer - , Toolbox. - Toolbox Add Tab

' " "

2. COM -

, Main() Start.cs [STAThread], , . 䳿 COM.

 

namespace MediaPlayer.cs

{

static class Program

{

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new Form1());

}}}

Choose Items

, ', COM Components, Windows Media Player, OK

3.

Project/Add Windows Form, , , ', ' MediaPlayer.cs

4. ³ COM -

" " .

Properties, .

Rate . , , 2,
PlayCount . 0
FileName
Volume ((=0)
ShowControls
ShowTracker (()
ShowAudioControls
ShowDisplay ,
ShowPosicionControls ³
CurrentPosition ̳ ,
Volume . 0 - . - 10000
Duration , . ̳ , ,

5.

. ֳ 䳿 , .

, . Containers Toolbox GroupBox, . : Name=groupBox, Dock=Bottom, Text=" "

groupBox Button. : Button Common Controls Toolbox , groupBox. , , ,

, Layout .

Locked/true,

 

btnOpen , . , FCL.

Dialogs Toolbox OpenFileDialog. ( , ),

' Properties,

OpenFileDialog
 
OpenFileDialog Name   openFilePlayer
Filter 1234567891011 Wave(*.wav) |*.wav| Dialogic VOX ADPCM (*.vox) |*.vox| InterVoice (*.ivc) |*.ivc| Macintosh AIFF (*.aif,*.aiff,*.snd) |*.aif,*.aiff,*.snd| MP3 Audio (*.mp3) |*.mp3| Sound Designer 1 (*.dig,*.sd) |*.dig,*.sd|Video for Windows (*.avi) |*.avi|Windows Media (*asf) |*asf|Windows Media Audio (*.wma) |*.wma|Windows Media Video (*.wmv) |*.wmv|All Files (*.*) |*.*

Filter , , FilterIndex , ' . Գ Filter " |_" " ".

³ :

openFileDialog1.InitialDirectory = System.IO.Directory.GetCurrentDirectory();

openFileDialog1.ShowDialog();

Player1.URL = openFileDialog1.FileName;

³ :

Player1.Ctlcontrols.play();

1. . .

2. .

3. .

4. :

if (checkBox1.CheckState == CheckState.Checked)

{ Player1.settings.volume = 0; }

else {

Player1.settings.volume = 50; }

.

1. ?

2. COM -

3. OpenFileDialog.

 


4

: .

: Windows Forms.

1. .

MDI-, -, , ' . . -, ³, ( , ) . MDI- , , . - MDI- . MDI- ( ), , , MDI- ( ). . ҳ . , , .

1. Windows Application MDIBasic.

2. :

Name frmContainer

IsMdiContainer true

Text

WindowState Maximized

3. , Windows Form Project | Add New Item ( , , Windows Form). frmChild. , , , . : public frmChild (MDIBasic.frmContainer parent)

{ InitializeComponent();

this.MdiParent = parent; }

MDI-:

public frmContainer()

{ InitializeComponent();

MDIBasic.frmChild child = new MDIBasic.frmChild(this); child.Show(); }

this, MDI-. Show() . , .

2. .

. & &³. Name MenuItemFile MenuItemWindow . & :

Text () Name (')

& MenuItemNewWindow & MenuItemExit , . ̳ . &³ . . MdiWindowListItem menuStrip1 ' ³, menuItemWindow.

. . 䳿 Click . 䳿 Click ' MenuItemNew_Click. 䳿 :

private void MenuItemNewWindow_Click(object sender, EventArgs e)

{ //

frmChild newChild = new frmChild(this);

//

newChild.Show(); }

frmChild ' newChild. ' newChild - , MdiParent . , . , , . Show(). :

private void MenuItemExit_Click(object sender, EventArgs e)

{ Application.Exit(); }

. / . ' ' frmChild (.2).

2. MDI .

3. .

MDIBasic . frmChild RichTextBox. rtfText Dock Fill, . - , , - ', . . ' - , ContextMenuStrip . contextMenuStrip1 :

Text () Name (')

& MenuItemBold

& MenuItemItalic

ϳ& MenuItemUnderline

. lick , , :

private void MenuItemBold_Click(object sender, EventArgs e)

{ Font newFont = new Font(rtfText.SelectionFont, //1

(rtfText.SelectionFont.Bold? //2

rtfText.SelectionFont.Style & ~FontStyle.Bold: //3

rtfText.SelectionFont.Style | FontStyle.Bold)); //4

rtfText.SelectionFont =newFont; //5 }

, RichTextBox. , , . ϳ . . 2 , Bold true. , , , , ? : 3. , 4 , Bold false, . , . ϳ, (FontStyle).

4. ' .

ij, , , . :

Text () - Name (')

& - MenuItemFile & - MenuItemNew &³ - MenuItemOpen

& - MenuItemSave

, , ³ . , MergeAction MergeIndex Append -1 . , . MergeAction MatchOnly, Visible true. '. , :

Text MergeAction MergeIndex

& - Insert 1 &³ -Insert 2 & - Insert 3

. , , ³, , . , Click - , . :

private void MenuItemNew_Click(object sender, EventArgs e)

{ this.rtfText.Clear(); }

sender , . ³, .

private void MenuItemOpen_Click(object sender, EventArgs e)

{this.rtfText.LoadFile("test.rtf"); }

private void MenuItemSave_Click(object sender, EventArgs e)

{ rtfText.SaveFile("test.rtf"); }

.

5. .

. . , . . - frmChild, MdiList. ,

frmChild , , :

public frmChild (MDIBasic.frmContainer parent,string caption)

{ InitializeComponent(); this.MdiParent = parent; this.Text = caption; }

, , :

public frmContainer()

{ InitializeComponent();

MDIBasic.frmChild child = new MDIBasic.frmChild(this," 1");

child.Show(); }

. :

private void MenuItemNewWindow_Click(object sender, EventArgs e)

{ frmChild newChild = new

frmChild(this,""+nextFormNumber++); newChild.Show(); }

() . :

private void MenuItemTile_Click(object sender, EventArgs e)

{ this.LayoutMdi(MdiLayout.TileHorizontal); }

private void MenuItemCascade_Click(object sender,EventArgs e)

{ this.LayoutMdi(MdiLayout.Cascade); }

. . frmContainer ActiveMdiChild, , . : private void MenuItemClose_Click(object sender, EventArgs e)

{frmChild frm =(frmChild)this.ActiveMdiChild;

if (frm!= null) { frm.Close(); }}

.

1. , ϳ. 䳿 Click .

2. : , , , , . , 䳿. RichTextBox , , Undo(), Redo(), Cut(), Copy() Paste() RichTextBox. , , , , .

this.menuItemCut.Enabled=rtfText.SelectedText.Length>0? true: false;

.

1. .

2. MDI-?

3. ' MDI-?

4. Show()?

5. frmChild?


5

: Web- ASP.NET Visual Studio.NET.

: Visual Studio 2005 Web- ASP.NET.

1.

ASP.NET File New Web Site ( , New Project , Web- ). New Web Site, , :

(Templates) - , Web -. ϳ ASP.NET - Web - Web -. . Web - Web -, Web - Web-. ³ , Visual Studio . Web- Web-, Web- - Web -. , .

(Location) -





:


: 2017-03-12; !; : 1107 |


:

:

,
==> ...

1963 - | 1878 -


© 2015-2024 lektsii.org - -

: 0.477 .