Professional Documents
Culture Documents
Визуелнo прoграмирање
Визуелнo прoграмирање
Визуелнo прoграмирање
, 2013
. -
- :
. -
. -
:
:
:
-
CIP -
". ",
004.42'236:004.738.1
,
* + / . , .. - : " ", 2013
(URL): http://www.ugd.edu.mk. - :
. 159
ISBN 978-608-4708-29-2
) - NET ) C NET
COBISS.MK-ID 94101514
,
.
,
.
,
, .
, ,
. ,
,
, , .
. ,
.
,
-
.
( Java, C++ .)
.
,
.
,
.
,
.
, .
? ................................................................................. 9
.............................................................................................................. 9
.......................................................................................... 11
Microsoft Visual Studio 2010 ............................................................. 11
.NET? ................................................................................................................................................ 11
.NET ?........................................................................................ 12
................................................................................................... 13
.............................................................................................................................. 14
......................................................................................................................... 15
............................................................................................. 15
.NET ? ............................................................................. 18
C Sharp (C#)? ................................................................................................................................ 18
C# ? ........................................................................................... 19
C#? ............................................................................. 20
VISUAL STUDIO 2010 ................................................................. 23
VS2010 ......................................................................................................................... 24
Visual Studio 2010 ................................................................................................ 24
....................................................................................................................................... 25
................................................................................................................................. 26
............................................................................................................................. 26
VS2010 ................................................................................ 28
/ .............................................................. 29
.................................................................................. 29
.......................................................................................................................... 31
.......................................................................................................................... 32
VS2010 ..................................................................................................... 33
.............................................................................................................. 34
................................................................................................................. 35
VS2010 .................................................. 36
............................................................................................................... 37
Windows .................................................................................................................................... 39
....................................................................................................................... 39
......................................................................................................... 40
.................................................................................................................. 41
..................................................................................................................... 41
................................................................................................................ 42
...................................................................................................................... 43
Windows ...................................................................................... 44
Name.................................................................................................................................... 44
Text ...................................................................................................................................... 45
Visible................................................................................................................................... 45
Enabled ................................................................................................................................ 45
TabIndex TabStop ............................................................................................................. 46
Location ............................................................................................................................... 47
Size ....................................................................................................................................... 48
.............................................................................................................. 49
(event driven programming) ................................................. 53
..................................................................................................... 53
..................................................................................................... 54
......................................... 54
.............................. 58
....................................................................... 60
.............................................................................................................................. 63
........................................................................................................................................ 65
................................................................................. 65
.................................................................. 67
................................................................................... 67
................................................................................ 68
......................................................................................................... 70
........................................................................................................... 71
.......................................................................................... 72
............................................................................... 72
........................................... 72
.................................................................................. 73
.................................................................... 73
............................................................................................. 75
( ) .................... 76
............................................................................... 76
.......................................................................................... 77
............................................................................................................. 78
............................................................. 79
....................................... 80
........................................................................... 81
....................................................................................... 81
.............................................................................................. 83
.................................................................. 83
................................................................. 83
, .............................................................................. 83
- .................................................................................................. 84
MDI ............................................................................................................................................. 85
MDI ? ..................................................... 86
MDI ......................................................... 86
Windows Forms ......................................................................................................................... 90
Label ....................................................................................................................................... 90
TextBox. .................................................................................................................................. 93
Button ..................................................................................................................................... 98
CheckBox .............................................................................................................................. 100
RadioButton ......................................................................................................................... 104
ListBox .................................................................................................................................. 105
............................................................................................................................ 112
Timer a .................................................................................................................................... 116
PictureBox a ............................................................................................................................ 117
ImageList a .............................................................................................................................. 120
TabControl a ............................................................................................................................ 123
, ,
,
( Visual Studio .NET
).
.
C#, .NET ,
,
.
.NET ,
, ,
. ,
C# .
?
(Visual Programming VP)
.
:
- ;
;
"-" .
- -
( ),
.
, , , .
,
( Visual Programming Language - VPL).
() (, )
,
, ,
/ (Visual Programming Environment VPE).
:
Lab View;
Microsoft Robotics Studio;
Visual Paradigm;
Eclipse;
Microsoft Visual Studio.
(VPL) .
, ( )
, VPE
( VPE /
). VPE
, ,
.
VPE
,
. VPL
.
, :
(.
flowcharts),
(.
).
-
,
, -
(-) .
,
.
,
,
. , /
, :
GUI;
/
;
/
.
, VPE,
:
Microsofts Visual Basic ( Basic)
VisualWorks ParcPlace Systems ( Smalltalk).
VPE Computer-Aided Software Engineering (CASE)
( , )
,
. , ,
- .
.
10
,
, :
;
;
, ;
( )
;
- ;
;
.
.NET?
.NET (. .NET Framework, ".NET" "dot net")
,
.
, .NET ,
, (. Intermediate Language
- IL, MSIL ). .
, .NET
, .
.NET Windows XP (Service Pack 1)
Windows . , .NET
11
.NET ?
.NET , , ,
( C#),
().
. ,
Windows , Web .
-, Web ,
Web .
1.1. .NET
Visual Studio. NET .NET
.
12
.NET
,
, ,
.
(. Common Type System, CTS)
.
. CTS
,
.
,
. , Microsoft .. (.
Common Language Specification, CLS),
(CLR)
. , CLS Visual Basic
C#.
, . CLS
, , .
,
CLS, Visual Basic C#.
C# Visual Basic
CLS.
API , CLS -
.
.
,
C#.
public class MojaKlasa {
public void MojMetod() {
...
}
public void mojMetod() {
...
}
}
13
C# , C#
: MojMetod mojMetod
MojaKlasa. , Visual Basic ,
Visual Basic , Visual Basic
. , CLS
( ).
, public (
. protected),
Visual Basic .
(. Common Language Runtime, CLR)
, . CLR
:
- , ,
,
(. Garbage Collector, GC),
,
(. security model)
,
(. type system)
,
. NET ,
.NET ,
(, . compiler), (. debugging)
(. profiling),
,
(IL) (. optimizer)
.
(. managed code). , , (.
Garbage Collector, GC)
, .
C# ( .NET Visual Basic J#)
.
, C++ (unmanaged code).
, (
)
. , (. managed code
extensions), C++
.NET .
14
.NET (Framework Class Library, FCL)
, .NET .
.NET ,
. ,
(
), , (collections)
, ,
. , ,
.
,
(namespace). System,
Object . System
, , ,
, .
System.
1.1
.
1.1 .NET
System
System.Collections
System.Diagnostics
System.Drawing
System.EnterpriseServices
System.Globalization
System.IO
System.Management
System.Net
System.Reflection
System.Resources
System.Runtime.Remoting
System.Security
System.Text
System.Threading
System.Xml
,
, , ,
: , (stack),
(queue), (bit array), (hashtable)
(dictionary).
( ).
.
, (object pooling),
.
, : , ,
, .
.
, .
.
.
.
.
.
(ASCII, UTF8, Unicode).
.
XML .
(managed module) ( 1.2).
Windows (.exe, .dll), .NET .
15
1.2
.NET
, .
(engl. portable
executable, PE) 1.2.
0.2
PE
(bitmap)
. (. assembly) (
1.3). ,
- -. , ,
(assembly-).
(. assembly linker).
()
.
. ,
,
.
,
. , , Web
, ..
16
,
, .
1.3. (assembley)
, ,
, ,
.
(. Windows registry),
.
. (IL)
(CLR), , .
,
. , ,
, .
- ,
Visual Basic
C#.
(CLR). ,
- , ,
.
-
(CLR).
.NET
( , .NET ).
17
.NET ?
,
.NET , .NET
. .NET Windows
, .
.NET ,
.NET web Microsoft.
.
.NET Windows
.
MSCorEE.dll system32 Windows
( Windows WinNT
). .NET
. , Windows
Microsoft.NET .NET .
.NET .
, Microsoft.NET\Framework
, - :
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\policy
.NET ,
.NET . ,
.NET
.
.NET ,
( ).
C Sharp (C#)?
C , , ,
Microsoft- .NET (.NET Framework). (C
sharp C) ,
( 1.4).
C++, ++ 1.
1.4 C sharp ( C)
18
( , , .),
- (Unicode 266F)
, # (Unicode 0023).
C hash.
C .NET Anders Hejlsberg,
Microsoft. Microsoft,
Borland Turbo Pascal Delphi. Microsoft
Visual J++ ,
Sun. C# 1998 .,
2002 ( Visual Studio .NET 2002).
,
Visual Studio .
, :
C# 1.2 2003 ( Visual Studio 2003)
.
C# 2.0 2003 2005 (
Visual Studio 2005)
C# 3.0 - 2006 - 2007 .
(Visual Studio 2008)
C# 4.0 - 2010 . (Visual Studio 2010)
ECMA (
) ISO (
).
C# ?
C# :
( );
;
bool / int;
unsafe ;
,
(Garbage Collector GC);
,
;
C# ("Strongly Typed" language)
, ..
C#
;
(enumeration)
(namespace);
19
(properties)
;
.
C# ,
:
C# 2.0
;
() (template) C++;
;
;
get .. set (property);
(nullable value types).
C# 3.0
;
(from, where, select) (LINQ),
SQL, XML .;
;
;
;
(extension methods);
.
C# 4.0
- dynamic
;
in out ;
( C++);
C#?
. C#
20
, , ,
:
Windows
,
.
,
, ,
, .
.
,
, .
Windows
.
(" ")
, .
Web ,
web .
,
. web Microsoft
ASP.NET VS2010. ASP.NET web
C# Visual Basic.
Web (API) HTTP
(host computer).
21
2
VISUAL STUDIO 2010
Visual
Studio 2010 (VS2010) .
VS2010
,
.
,
. .
Microsoft
(), Express
SQL Server
, .NET Framework .
,
.
Microsoft Visual Studio
. Visual Studio 2010
(VS2010) , .
Web :
http://www.microsoft.com/express/.
22
, (IDE), VS2010,
C# . , C#,
( Notepad)
( .NET
Framework).
,
.
, Visual Studio
.NET :
VS
.
VS
VS ( C#),
.
IntelliSense ( ).
VS Windows , Web , ,
(UI) ,
.
C# .
.
VS ,
, .
VS
, C#
, .
, VS,
,
.
23
VS2010
Visual Studio 2010 Standard Visual Studio 2010 Professional,
Visual Studio 2010:
24
Windows .
(.
2.1). 2.1.
Edit
View
Project
Build
Debug
Data
Format
Tools
Test
, ,
, ,
Visual Studio, .
, : , , , ,
, , , (cut, copy, paste, undo, redo, delete, find, select),
.
( . Solution Explorer,
Toolbox, Properties window) .
.
.
(,
) .
.
. Format
GUI (Design) .
( , Toolbar), .
.
Analyze,
Architecture, , , Microsoft Team Foundation
Team
Server.
Window
Help
.
.
25
.
( ),
Microsoft 1.
.
,
. , ..
.
: View | Toolbars.
,
Customize.
.
,
:
.
.
.
Visual Studio 2010 (
)
.
: .
.
, (
)
VS2010, Microsoft
.
26
() (. Toolbox)
(),
. " "
,
(
windows ).
(.. ) .
,
, ,
.
(. Solution Explorer)
,
, ,
.
.
.
(.. ) View .
27
(. Properties)
. ,
View .
(. Status bar)
,
VS2010 .
(. Error list)
, ,
. ,
.
VS2010
,
(. 2.3):
(. Window Position) .
, :
(. Dock), (. Float), (. Dock As Tabbed Document),
(. Auto Hide), (. Hide);
/ (. Maximize/Restore Down) .
, . ,
(. Pin),
.
(. Close) .
,
,
VS2010, .
:
.
- .
- .
- , .
28
.
VS2010 ( 2.4).
,
Hide ,
.
29
30
Windows ,
,
.
( )
( ,
).
..
.
Float Window Position
( 2.5).
31
.
,
.
,
,
.
,
, ( 2.7).
( ) , VS2010
( ),
. ,
.
, ,
.
32
VS2010
, Windows
Microsoft Visual Studio 2010 C#. ,
Windows , Windows
.
,
.
?
,
Windows "",
, . ,
,
, .
VS2010 ,
.
,
.
,
VS2010 :
(. Distributable Component)
.
() ( ),
VS2010 (..
.NET ).
.
().
(. Solution)
.
,
, .. Application.
, Windows (. Windows Forms).
, Windows ,
(. Windows Forms Controls). Windows
, , , , , .
33
VS2010:
, (. New Project);
, File | New | Project;
Ctrl + Shift + N;
( 2.8),
,
.
,
.
2.8
, windows , .
34
(. Solution Explorer).
.
(, ) (Windows
), .
,
,
.
( .sln),
( .csproj).
(
). ,
Properties Alt + Enter
( 2.9) .
2.9
COM , DLL
.
35
VS2010
:
Project.
aa (Add New Item
Add Existing Item )
(Standard toolbar),
(Solution Explorer)
(Add) ,
.
(
2.10).
2.10
Windows
,
.
36
.
F5
( 2.11).
2.11 VS2010
37
3
, ,
.
.
,
.
( windows
).
windows
.
Visual C#,
.
38
Windows
,
.
.
(Graphical User Interfaces GUI).
, ,
.
/ Visual C# ,
. ,
, ,
.
Visual C#
. ,
. , .
Visual C#
Windows
. ( ),
Visual C# Windows
Windows .
.
(parent-child relationship).
()
. (
windows ),
.
.
.
, .
(
).
,
.
.
39
Controls ( ).
(
- drag and drop
), .
,
Controls , Controls.Add() .
, ,
. VS2010
:
(design time) /
.. .
,
, ,
. /
..
.
VS2010,
.
(run time)
.
VS2010 .
.
(Solution Explorer),
( 3.1).
3.1
.
40
()
. ( )
.
( 3.2) ,
, , , .
3.2 () .
.
.
,
.
..
. : Timer, Open File Dialog .
(toolbox). (
3.3). ..
.
3.3
41
, VS2010
,
. VS2010
() , :
,
,
; .
, .
-
.
.
.
- (Copy),
- (Paste),
.
,
. VS2010
.
,
.
8 ( 3.4).
3.4
,
,
( 3.5).
.
,
. Shift Ctrl
.
,
.
42
,
( )
( 3.6).
.
3.5
3.6
.
,
(Delete) Edit.
(Delete)
.
( )
, ( 3.7),
.
( 3.7).
,
. (
),
43
.
Ctrl.
3.7
,
() .
Locked , false
( ), true (
, 3.8).
3.8
Windows
Name
Name.
, .
, , /
. , ,
Form1. , : Form2,
Form3,.... ..
,
.
.
, VS2010 IDE ,
. ,
textBox1, textBox2, textBox3, .
44
. ,
, ,
.
, ,
Name, Enter.
Visual C#,
.
Microsoft, 2.
,
, :
128
,
Text
M / Text. ,
. , Label Text
, . ,
, .
, Text, .
Unicode
,
. , ( )
.
Visible
, Visible.
(Boolean type) (true/false)
/ .
. ,
. .
Enabled
.
,
. Enabled . ,
Enabled false,
.
45
( 3.9).
,
.
TabIndex TabStop
,
. tab
tab ordering.
Tab.
.
.
Tab
TabIndex. tab
TabIndex .
, :
( 3.10)
46
Location
,
. ,
()
, .
, ,
( 3.12).
( )
(Location), :
(
) .
X .
- (
) .
Y .
47
3.12
Size
, ,
,
Size. windows
, .
: (Width) (Height).
, ,
, ..
.
(
),
( 3.1).
3.1
,
, Width Height.
.
,
.
48
3.2
Format
windows ,
, Layout ,
Format | Make same size,
3.2.
, .
,
, .
,
(Toolbox) . , ,
,
. System,
System.Windows.Forms.
, (). ,
( ),
.
49
ClassName VariableName;
, btnSubmit () Button (
System.Windows.Forms ), :
System.Windows.Forms.Button btnSubmit;
() ,
, new,
.
, Button
Form1.
public class Form1 : System.Windows.Forms.Form
{
System.Windows.Forms.Button btnSubmit;
public Form1()
{
btnSubmit = new System.Windows.Forms.Button();
btnSubmit.Location = new System.Drawing.Point(88, 2);
btnSubmit.TabIndex = 0;
btnSubmit.Text = "Submit";
Controls.Add(btnSubmit);
...
}
:
btnSubmit = new System.Windows.Forms.Button();
, . ,
,
. Visible true,
Size (
),
, .
,
, :
btnSubmit.Location = new System.Drawing.Point(88, 2);
(
Point), 88 ( X) 2
( Y).
, Tab :
50
btnSubmit.TabIndex = 0;
btnSubmit.Text = "Submit";
,
.
:
Controls.Add(btnSubmit);
() btnSubmit /
Controls Add.
.
,
VS2010 .
.
VS2010, ,
( , .) .
VS2010 .
..
.
51
(/)
()
. (events).
.
(
Windows).
.
, ,
.
52
.
Timer. Timer ( Tick)
.
Interval ,
Tick .. .
53
,
.
Interval, .
. ,
. ,
,
,
.
Windows Visual C# , ..
Paint.
.
Graphics .
Paint /
.
.
. (Button ) ,
, Click
,
.
(Event Handler).
TextBox ,
. TextBox
Button, Click ,
. MultilineChanged ,
Multiline. Button ,
.
,
, .
,
. TextChanged, ,
. ,
(TextBox).
54
TextBox ,
TextChanged ( ) ,
(
Enter), 12 ,
. .
,
VS2010,
.
,
( 4.1).
4.1
.
(
4.1). ,
,
.
,
Click .
Click
( OpsluzuvacKopce - XX).
4.2
Enter
Click:
55
( VS2010 ):
this.button1.Click += new System.EventHandler(this.OpsluzuvacKopce);
Click
OpsluzuvacKopce, .
VS2010,
.
VS2010
_ . , Click
button1, :
private void button1_Click(object sender, MouseEventArgs e)
{
}
,
,
InitializeComponent(). (
) ,
Reset
( 4.3).
4.3
56
,
.
Visual C#.
, , .
, , - .
, .
, Visual C# ,
;
.. ,
.
.
MouseDown,
:
object sender,
MouseEventArgs e
private void button1_MouseDown(object sender, MouseEventArgs e)
{
}
,
.
, Sender (), e .
Visual C#. Sender (),
.
MouseDown, , ,
. , ,
MouseEventArgs.
MouseDown.
, ,
:
.
,
.
57
( )
.
: keydown, keypress, keyup, :
keydown ..
.
keypress .
keyup
4.4.
4.4.
TextBox
, :
(.. )
KeyDown KeyUp
. KeyEventArgs. KeyPress ,
KeyPressEventArgs.
,
. KeyEventArgs 4.1,
KeyPressEventArgs 4.2.
, TextBox 4.5 4.6.
58
Alt
Control
Handled
ALT
CTRL
, (KeyPress KeyUp)
.
ASCII KeyDown KeyUp .
KeyDown KeyUp .
KeyDown KeyUp .
KeyDown KeyUp .
(CTRL, SHIFT, ALT)
SHIFT
KeyCode
KeyData
KeyValue
Modifiers
Shift
Handled
, .
KeyChar
4.5.
, TextBox
59
4.6.
, TextBox , KeyPress
( ) .
: MouseEnter, MouseMove, MouseHover/
MouseDown/ MouseWheel, MouseUp, MouseLeave, :
MouseEnter
MouseMove
MouseHover/ MouseDown/ MouseWheel
/
/
MouseUp
MouseLeave
4.7.
TextBox
60
:
(.. ).
4.3 MouseEventArgs.
4.3 MouseEventArgs
Button
Clicks
Delta
120
, -120 .
MouseWheel
x- .
y- .
X
Y
.
MouseWheel (
). ,
Delta MouseEventArgs +120,
-120.
,
. 4.8.
Button.
4.8. j MouseWheel
delegate MouseEventHandler VS2010
61
MouseMove
.
. 4.9.
TextBox.
X Y
MouseEventArgs .
TextBox ,
MouseDown Button
( 4.10).
62
.
.
TextBox
TextChanged .
TextChanged .
, TextChanged ,
, TextChanged
.
Windows StackOverflow (
4.11), Windows
.
. ,
, ,
.
4.11. ,
63
5
(Graphical User Interface GUI)
.
Windows .
,
.
,
.
Visual C#, ,
,
() - SingleDocument Interface, SDI Multiple-Document Interface, MDI.
64
(Graphical User Interface GUI)
.
GUI . GUI
,
, .
GUI Windows . ,
.
, , ,
..
,
.
. , , ,
.
, .
, , ,
.
Visual C# : ..
,
.
Windows , ,
.
Visual C# . ,
,
, ., ,
. ,
.
Windows Application,
. ,
, :
( 5.1 )
( Project | Addd Windows Form )( 5.1 )
( 5.1 )
,
( 5.2),
, .Net.
65
5.1. VS2010
5.2. VS2010
,
.
, Name () Properties,
Name ( ).
( . frmTestForm.cs),
VS2010
.
66
( 5.3).
Text.
5.3. VS2010
,
Text ( 5.4), :
this.Text = Naslov na formata;
5.4. .
( 3D
Windows), .
, BackColor.
BackColor
RGB .
67
, BackColor Control.
. , Windows
, .
Windows, XP Vista,
. XP Vista, ( ).
Windows,
.
, Control
BackColor, 0; 0; 255 Enter
Tab ( 5.5).
, RGB
, Blue.
Visual C# RBG ,
.
, RGB . ,
,
BackColor .
5.5.
:
this.BackColor = Color.Blue;
this.BackColor = Color.FromArgb(0,0,255);
, .
, BackgroundImage
68
. ,
( 5.6).
5.6. , ,
, :
1. /.
2. BackgroundImage .
3. Build (
).
4. (.. Select Resource).
(. Local Resource) ( 5.7).
5. Import ,
.
6.
OK, .
5.7.
BackgroundImage
- .
- . BackgroundImage
, -
69
, : , , .
( Tag) ( 5.8).
, , ,
BackgroundImage
(Ang. Reset) .
5.8. BackgroundImage
:
,
BackgroundImageLayout.
:
None - .
Tile .
Center - .
Strech - .
Zoom - e a .
,
,
Alt + Tab , .
,
. , Visual C#
.
70
, .
, .
,
.
, Icon
, Build,
. ,
.
:
this.Icon = new System.Drawing.Icon(@"C:\Icon.ico");
,
ShowIcon. bool .
ShowIcon false
, (
5.9).
Cursor .
.
Default.
( 5.10).
5.10
71
ForeColor.
, :
FormBorderStyle.
.
,
. :
Fixed3D , 3
FixedDialog
FixedSingle
FixedToolWindow .
(task bar)
ALT+TAB.
, ShowInTaskbar.
None
Sizable
SizableToolWindow -
(task bar)
ALT+TAB.
, ShowInTaskbar.
FormBorderStyle :
,
( 5.11).
72
5.11.
RightToLeft.
:
(Yes) -
(No) -
(Inherit)
( )
.
UseWaitCursor bool
,
. :
. StartPosition,
:
73
CenterParent
CenterScreen
Manual
Location.
WindowsDefaultBounds
Windows
WindowsDefaultLocation -
Windows ..
(Size).
:
this.StartPosition = FormStartPosition.CenterScreen;
. ,
,
,
( 5.12).
,
StartPosition, Manual,
.
.
this.Location = new System.Drawing.Point (100, 100);
5.12
74
Left - Top;
10 .
Bottom Right .
.
Size,
- Height Width.
:
Form1.Size = new Size(600,500);
. MaximumSize MinimumSize
(0,0) ... = 0 =0 .
this.MaximumSize = new Size(500, 500);
this.MinimumSize = new Size(200, 200);
, DesktopBounds; DesktopBounds
, Rectangle (
, ).
, .
,
+ 12 (horizontal + 12 vertical + 12).
400400,
(50, 50)
75
// Rectangle
Rectangle tempRect = new Rectangle(50,50,400,400);
// .
this.DesktopBounds = tempRect;
(
)
(.. ) , ,
Maximized .
Minimized .
Normal ()
(.. )
WindowState. ,
:
Form1.WindowState = FormWindowState.Minimized;
Form1.WindowState = FormWindowState.Maximized;
Form1.WindowState = FormWindowState.Normal;
..
,
(
).
AutoSize AutoSizeMode. AutoSizeMode
,
:
GrowAndShrink
GrowOnly
,
Size.
:
76
this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
AutoSizeMode ..
,
AutoSize. AutoSize true,
. AutoSize
false. AutoSize :
this.AutoSize = true;
,
( ),
.
AutoScroll, false.
true, ,
,
/ .
5.13.
77
5.14
Enable .
true, false
( 5.15).
5.15 ,
false,
( , .).
78
:
(, /, )
ControlBox
. true, false,
(
)( 5.16).
5.16
HelpButton
. false, true,
/, ( 5.17).
this.HelpButton = true;
5.17
MaximizeBox MinimizeBox false.
HelpButton
.
,
( 5.18).
79
5.18
HelpButton HelpRequested .
HelpRequested,
HelpButton.
MaximizeBox MinimizeBox,
/.
Minimize
Maximize/Restore ,
Restore
Resize
.
FormBorderStyle ,
:
FormBorderStyle.FixedSingle,
FormBorderStyle.Sizable,
FormBorderStyle.Fixed3D,
FormBorderStyle.FixedDialog
80
MaximizeBox MinimizeBox,
( 5.19).
5.19
.
.
( 5.20).
5.20
SizeGripStyle
Auto, :
Auto
Hide -
Show -
:
this.SizeGripStyle = SizeGripStyle.Hide;
,
, :
81
TransparencyKey
Opacity
TransparencyKey
, BackColor
. :
this.TransparencyKey = Color.Red;
5.21,
Label, BackColor
.
5.21
Opacity .
100% .
0 % ..
, 100% - .
:
this.Opacity = .50;
5.22.
5.22 Opacity
RightToLeftLayout
true.
82
.
, TopMost,
true .
this.TopMost= true;
AcceptButton
ENTER
. ENTER
. , button1
ENTER :
this.AcceptButton = button1;
CancelButton
ESC
. ESC
. , button2
ESC :
this.CancelButton = button2;
,
.
,
,
,
() . :
{ formclassname } {objectvariable} = new {formclassname()};
83
( ) () LoginDialogForm.
LoginDialogForm frmLogin = new LoginDialogForm();
.
. ( ),
.
:
LoginDialogForm.Show();
LoginDialogForm.Visible = true;
.. .
..
, .
:
LoginDialogForm.ShowDialog();
Close().
this.Close();
. , Visible false:
frmLogin.Visible = false;
.
-
. ,
( .
, ).
:
FormBorderStyle -
FormBorderStyle.None
84
Load ,
(
)
private void Form1_Load(object sender, EventArgs e) {
GraphicsPath path = new GraphicsPath();
path.AddEllipse(0, 0, this.Width, this.Height);
Region reg = new Region(path);
this.Region = reg;
}
MDI
Windows :
- :
.
/ (Single-document interfaces SDI): , ,
.
/ (Multiple-document
interfaces - MDI): SDI ,
.
-
,
. Windows Calculator.
SDI
.
,
. SDI
WordPad Paint Windows .
, ,
, SDI ,
.
. , Paint
,
85
, ..
.
MDI SDI,
/
.
Adobe Photoshop, Microsoft Visual Studio .
MDI ?
,
, ,
.
, Window,
,
, .
MDI
,
.
MDI
MDI .
MDI .
MDI .
MDI .
:
1) Windows Forms ( ) Visual Studio
SDI .
2) ,
VS2010 ( ),
frmContainer. MDI .
IsMdiContainer true.
( 5.23)
86
( ,
).
5.23 MDI
3) MDI .
SDI .
( ) frmChild.
4) :
public frmChild(MdiBasic.frmContainer parent)
{
InitializeComponent();
// Set the parent of the form to the container.
this.MdiParent = parent;
}
/
, MDI .
VS2010
,
MDI ( ).
5) .
MDI ,
, .
:
87
public frmContainer()
{
InitializeComponent();
frmChild child = newfrmChild(this);
child.Show();
}
frmChild this
frmContainer, MDI .
Show() .
5.24.
5.24 MDI
MDI ,
.
88
6
Windows
Windows Windows
.
,
.
windows .
.. windows .
89
Windows Forms
Label
Label .
,
.
.
Text, Label
.
.
Label lblIme = new Label();
lblIme.Text = ;
Label (
AutoSize true), ,
.
Label
. Label
( Text),
Enter ( 6.1).
6.1. Label
Label ,
\n :
label1.Text = "Proben tekst \nvo koj ima nov red";
6.2
6.2 Label .
90
6.4. Label
91
( 6.5).
6.5. Label
Label .
BorderStyle, :
None
FixedSingle 2 ,
Fixed3D 3
6.6.
6.6. Label
Label
Image. ,
Label , ImageAlign,
( 6.7).
6.7. Label
Label
BackColor ForeColor
.
.
label1.BackColor = Color.LightPink;
label1.ForeColor = Color.MidnightBlue;
92
Label Font
- . ,
, ( (bold), (italic), (underline),
(strikeout)). ( 6.8)
.
6.8.
,
Label ,
( , .) .
label1.Font = new System.Drawing.Font(label1.Font, System.Drawing.FontStyle.Bold |
FontStyle.Italic | FontStyle.Underline);
TextBox.
TextBox
,
. TextBox
Text .
TextBox txtIme = new TextBox();
txtIme.Text = "Ime";
,
: , . TextAlign.
( 6.9).
6.9 TextBox
93
TextBox
, ( )
( ).
MultiLine (
true). ,
smart tag
( ) ( 6.10).
ScrollBars.None ( )
ScrollBars.Horizontal ( )
ScrollBars.Vertical ( )
ScrollBars.Both ( ).
TextBox , WordWrap.
true
. :
AcceptsReturn ENTER TextBox
.
AcceptsTab - TAB TextBox
( TAB )
.
,
ReadOnly true. (
Enabled false.)
TextBox
TextLength . TextLength ,
.
TextLength.
TextBox
, .
TextBox .
94
TextBox
( ).
. PasswordChar.
6.11 PasswordChar
UseSystemPasswordChar true,
.
. TextBox
, :
95
SelectedText TextBox
SelectionLength TextBox
.
SelectionStart (
) TextBox .
TextBox .
) ) .
6.12.
textBox1.SelectionStart = 1;
textBox1.SelectionLength = 3;
MessageBox.Show(textBox1.SelectedText);
6.11 TextBox ) ; )
.
TextBox
, MaxLength. TextBox
. CharacterCasing,
:
Lower .
Normal
Upper
TextBox ,
AutoCompleteMode :
96
Append
,
() .
None .
Suggest
SuggestAppend Suggest Append.
, ,
6.12.
Suggest
Append
Suggest + Append
6.12 AutoCompleteMode
AutoCompleteSource ,
. CustomSource
AutoCompleteCustomSource.
TextBox .
TextBox
.
TextBox
ShourtcutEnabled. ShourtcutEnabled :
CTRL+Z
CTRL+E
CTRL+C
CTRL+Y
CTRL+X
CTRL+BACKSPACE
CTRL+V
CTRL+DELETE
CTRL+A
SHIFT+DELETE
CTRL+L
SHIFT+INSERT
CTRL+R
97
. Textbox Cut, Copy, Paste, Undo
, , .
TextBox ,
TextBox .
.
private void button1_Click(object sender, EventArgs e)
{
textBox1.Cut();
textBox2.Paste();
}
TextChanged (
).
TextChanged TextBox ,
(Paste).
, .
( )
. TextBox
Label ,
.
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (textBox1.TextLength < 10)
label1.Text = textBox1.Text;
}
Button
. Button.
.
98
( )
: FlatStyle FlatAppearance.
FlatStyle ,
:
Flat ,
.
Popup ,
3 .
Standard 3 ( )
System
,
6.13.
FlatStyle
Flat
Popup
System
6.13 FlatStyle Button
FlatAppearance ,
FlatStyle Flat. :
BorderColor
BorderSize - ( )
MouseDownBackColor - ,
MouseOverBackColor - ,
.
DialogResult , ,
.
.
6.14
: (frmRoditel)
Label ( label1) (button1).
. , , (frmDete)
TextBox (txtIme) (btnOK btnCancel).
DialogResult btnOK , btnCancel Cancel.
99
, TextBox
(txtIme) , Label (label1) .
Modifiers TextBox (txtIme)
public. (..
).
CheckBox
.
: / (Yes/No) / (True/False),
. ,
, .
100
,
( 6.15).
6.15 CheckBox
CheckBox
.. .
,
.
:
;
Location ;
Location ,
Top Left :
testCheckBox.Location = new Point(20, 150);
testCheckBox.Left = 20;
testCheckBox.Top = 150;
CheckBox (Checked)
- (Unchecked),
Checked
, true false
.
CheckBox Unchecked.
.
, .
.
101
if (dynamicCheckBox.Checked)
{
// CheckBox
}
else
{
// CheckBox
}
CheckBox ,
:
dynamicCheckBox.CheckState = CheckState.Indeterminate;
.
CheckBox ,
:
AutoCheck Checked CheckState ,
CheckBox , CheckBox
.
Checked CheckBox .
CheckState CheckBox .
ThreeState CheckBox
.
102
CheckBox .
Appearance CheckBox .
:
Button Windows
Normal
Size CheckBox .
- Height Width
. , ,
,
:
testCheckBox.Height = 40;
testCheckBox.Width = 300;
testCheckBox.Size = new Size(300, 40);
Text CheckBox
.
, : , , , ( ).
testCheckBox.Text = "I am a test CheckBox";
testCheckBox.TextAlign = ContentAlignment.MiddleCenter;
,
Image.
, 6.16.
// CheckBox.
checkBox1.Text = " ";
// CheckBox.
checkBox1.Image = Image.FromFile(@"D:\Image1.jpg");
// CheckBox
checkBox1.ImageAlign = ContentAlignment.BottomRight;
// CheckBox
checkBox1.FlatStyle = FlatStyle.Standard;
// CheckBox
checkBox1.BackColor = Color.Red;
6.16 CheckBox
103
CheckBox CheckedChanged
. ,
:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
CheckBox ,
:
checkBox1.Checked = ! checkBox1.Checked;
RadioButton
CheckBox , RadioButton
.
(.. ).
,
CheckBox.
.
.
CheckBox .
RadioButton .
.
\r\n, Newline .NET Environment.
Click ,
.
private void button1_Click(object
{
string OmilenZanr = "";
if (checkBox1.Checked)
OmilenZanr += checkBox1.Text
if (checkBox2.Checked)
OmilenZanr += checkBox2.Text
if (checkBox3.Checked)
OmilenZanr += checkBox3.Text
sender, EventArgs e)
+ "\r\n";
+ "\r\n";
+ "\r\n";
if (radioButton1.Checked)
OmilenZanr += " : " + radioButton1.Text + Environment.NewLine;
104
if (radioButton2.Checked)
OmilenZanr += " : " + radioButton2.Text + Environment.NewLine;
if (radioButton3.Checked)
OmilenZanr += " : " + radioButton3.Text + Environment.NewLine;
OmilenZanr += " ";
MessageBox.Show(OmilenZanr);
}
(
) 6.17
6.17
ListBox
ListBox
().
.
.
, , 6.18.
105
6.18 ListBox
ListBox ,
(.. ).
.
(
).
, ListBox :
ListBox ,
. ListBox
, .
, (random)
Ctrl .
(
, Shift,
).
ListBox
SelectionMode . :
None
One
MultiSimple ,
MultiExtended - ,
, SHIFT CTRL
ListBox
. ,
. ,
, .
106
, ,
true HorizontalScrollbar.
ListBox ( )
. ListBox
( ),
Items ( 6.22)
107
6.23 ListBox
, , ,
ENTER .
ListBox .
:
listBox1.Items.Add("Pero");
listBox1.Items.Add("Goce");
listBox1.Items.Add("Dusko");
, :
string[] strNames = {"Pero", "Goce", "Dusko"};
listBox1.Items.AddRange(strNames);
ListBox Sorted
, true
. 6.24.
108
6.24 ListBox
ListBox ,
.
:
0
,
,
.
6.25.
listBox1.Items.Insert(1, "Bojan");
6.25 ListBox
, ListBox
. ListBox
.
ListBox Clear()
Items.
listBox1.Items.Clear();
ListBox
( 0). ,
ListBox .
listBox1.Items.RemoveAt(2);
109
ListBox .
.. case-sensitive.
ListBox ,
bool contains = listBox1.Items.Contains("Pero");
.
:
int contains = listBox1.Items.IndexOf("Pero");
-1.
( )
. ( )
ListBox :
listBox1.SelectedItem = "Pero";
listBox1.SelectedIndex = 1;
, ,
:
, .
, SelectionMode
None,
, SelectionMode
One,
ListBox
, :
GetSelected i
true i , false.
bool sel = listBox1.GetSelected(3);
- ,
SetSelected.
listBox1.SetSelected(1, true); // 1
listBox1.SetSelected(2, false); // - 2
.
Click ,
ListBox .
110
ListBox
:
SelectedIndices
.
SelectedItems -
.
, ListBox 6.26
6.26.
MessageBox.Show(listBox1.SelectedIndices[1].ToString());
6.27 ListBox
111
MultiColumn
true.
listBox1.MultiColumn = true;
ColumnWidth
:
listBox1.ColumnWidth = 60;
ListBox
.
SelectedIndexChanged,
:
. Visual C# :
Panel ( 6.28)
112
6.28 Panel
GroupBox ( 6.29)
6.29 GroupBox
(
), :
(
)
(
)
(
).
. , GroupBox , , Panel
. ,
BorderStyle . : None ( ),
FixedSingle, Fixed3D.
6.30.
None
FixedSingle
Fixed3D
6.30 Panel
113
. Panel ,
GroupBox Text ( 6.31).
6.31 GroupBox
.
.
GroupBox , Panel ScrollableControl,
( ).
AutoScroll true.
Panel AutoScroll true
6.28.
114
7
Windows
windows .
.. windows .
115
Timer a
Visual
C#. .
Timer.
Timer
VS2010 ( 7.1).
116
timer1.Start();
Timer Stop :
timer1.Stop();
PictureBox a
, Visual C# PictureBox.
, ,
.
, ,
( 7.2).
7.2 PictureBox
PictureBox
.
BorderStyle ,
:
None ,
FixedSingle ,
Fixed3D 3 .
PictureBox
Image . :
, Image
117
Image Image.
PictureBox
, ImageLocation.
Image, string, ,
.
,
. 7.4
.
7.4 ImageLocation
:
pictureBox1.ImageLocation = @"C:\Users\Pictures\ee.jpg";
pictureBox1.ImageLocation = "http://www.functionx.com/design/une1.gif";
118
PictureBox,
,
. ( )
ErrorImage PictureBox .
Image ,
:
pictureBox1.ErrorImage = Image.FromFile(@"C:\Users\Pictures\ee.jpg");
PictureBox
Load .
pictureBox1.Load(@"C:\Users\Pictures\ee.jpg");
PictureBox,
.
SizeMode PictureBox .
,
(enumerator) PictureBoxSizeMode.
pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
SizeMode PictureBox :
Normal
( 7.5)
7.5
CenterImage - (
) ( 7.6)
119
7.6
StretchImage
( 7.7)
7.7
Zoom ,
AutoSize
ImageList a
,
.
, ,
.
( )
, .
Visual C# - ImageList,
.
,
, .
120
ImageList,
, Timer
.
.
.
ImageSize .. - Height Width
( ) ,
.
:
imageList1.ImageSize = new Size(256, 356);
ImageSize , , ,
:
( 7.8)
Depth4Bit,
Depth8Bit,
Depth16Bit,
Depth24Bit,
Depth32Bit.
ImageSize,
( 7.9).
7.9 ColorDepth
121
ImageList ,
, ..
. TransparentColor,
Color.
( 7.10),
:
imageList1.TransparentColor = Color.Black;
imageList1.TransparentColor = Color.FromArgb(255, 0, 255);
7.10 TransparentColor
ImageList,
.
(Image Collection
Editor) ( 7.11).
122
:
Choose images ( 7.8)
Images
ImageList,
:
Image img1 = Image.FromFile(@"E:\Programs\image1.jpg");
imageList1.Images.Add(img1);
Image img2 = Image.FromFile(@"E:\Programs\Image2.jpg");
imageList1.Images.Add(img2);
Image[] images =
{
Image.FromFile(@"E:\Programs\image3.jpg"),
Image.FromFile(@"E:\Programs\Image4.jpg"),
Image.FromFile(@"E:\Programs\Image5.jpg")
};
imageList1.Images.AddRange(images);
ImageList (
). Images:
imageList1.Images[1];
(
0).
TabControl a
,
,
. , .
.
/
.
.
Windows 95
(). ,
.
TabControl
.
123
, ,
( 7.12).
() (
).
7.12 TabControl
7.13 TabControl
TabControl ,
TabPage .
124
7.14 TabPage
TabPage TabControl
. TabPage
TabControl AddTab (
TabControl TabPage ) ( 7.15).
7.15 TabPage
TabPage , TabControl
, TabControl
AddTab ( 7.16).
7.16 TabPage
TabPage , TabControl
, ( )
AddTab ( 7.17).
125
7.17 TabPage
TabPage , TabControl
, () TabPages
, .. ( 7.18).
Add.
7.18 TabPage
. TabPage
.
TabPage TabControl
, .. AddTab
RemoveTab .
TabPage (
) Delete ,
TabPage .
126
TabPage ,
.
:
,
.
TabPage
(TabPage Collection Editor),
() TabPages .
TabPage , TabControl ,
TabControl .
TabPage
( , ), TabPage
( 0).
, :
tabControl1.SelectedIndex = 1; // SelectedIndex, TabControl
. .
tabControl1.SelectTab(1); // SelectTab, TabControl
TabPage .
tabControl1.SelectedTab = tabPage3; // SelectedIndex, TabControl
, TabPage .
.
tabControl1.SelectTab("tabPage2"); // SelectTab, TabControl
TabPage
.
TabPage ,
: Location (Right Top), Size (Width Height),
- TabControl .
,
DisplayRectangle TabControl .
Rectangle, .
127
TabPage ,
, .
Text TabPage , ,
:
tabControl1.TabPages[1].Text = "Naziv na stranicata";
,
( ). HotTrack
TabControl true.
.
ToolTipText TabPage
.
TabControl , ShowToolTips true.
TabControl ,
, TabControl
.
Alignment TabControl
. ,
, .
tabControl1.Alignment = TabAlignment.Left;
Alignment
7.19.
7.19 TabControl
128
TabControl , ,
.
Appearance :
Normal ( ),
Buttons,
FlatButtons.
7.19 TabControl
Normal Buttons
() . FlatButtons
Alignment Top.
TabControl ,
, (
), (
7.20).
, .
7.20 TabControl
TabControl
,
.
129
MultiLine.
( 7.21), true,
:
tabControl1.Multiline = true;
7.21 TabControl
, (
), RowCount.
int brojNaRedovi = tabControl1.RowCount;
TrackBar a
TrackBar ()
( 7.22).
130
, .
.
.. .
TrackBar ,
:
( 7.23)
7.23 TrackBar
:
,
.
.
TrackBar :
Maximum .
Minimum - .
Value ..
Orientation .
,
:
Horizontal () - trackBar1.Orientation = Orientation.Horizontal;
Vertical () - trackBar1.Orientation = Orientation.Vertical;
131
TickStyle
, :
Both .
BottomRight ,
.
None .
TopLeft - ,
.
TickFrequency TrackBar
.
: SmallChange LargeChange.
SmallChange Value
.
(-) ( ) ,
, , .. .
LargeChange Value
.
(-) ( ) ,
, PAGE UP PAGE DOWN,
.
:
TextBox (txtBox1 txtBox2,
TrackBar : trackBar1 trackBar2.
trackBar1 : Maximum =
100, Minimum = 0, LargeChange = 1, SmallChange = 1, ThickFrequency = 1
trackBar2 : Maximum =
100, Minimum = 0, LargeChange = 5, SmallChange = 1, ThickFrequency = 1
trackBar1
txtBox1, trackBar2
txtBox1.
.
132
8
(
). .
( ,
, ).
.
Visual C# ,
, .
133
MenuStrip a
(windows).
, , ( )
.
( ).
. ( ,
,
).
.
MenuStrip.
: (
8.1), .
8.1
MenuStrip ( ContextMenuStrip) ,
, ()
( Timer
)( 8.2).
MenuStrip ,
.
, ,
- .
, . ..
MenuStrip ToolStripMenuItem.
134
8.2 MenuStrip
MenuStrip
, :
Type here ( 8.3).
8.3 MenuStrip
(.. Items),
smart tag ( 8.4),
(Items Collection Editor).
135
,
, Dock. ,
,
:
menuStrip1.Dock = DockStyle.Left;
( 8.6).
8.7.
8.6 Dock
136
8.7
.. (grip element)
( 8.8)
8.8
GripStyle MenuStrip (
) : Hidden Visible (
8.9)
8.9 GripStyle
:
menuStrip1.GripStyle = ToolStripGripStyle.Visible;
( )
:
Menu Item
TextBox
ComboBox ( 8.10).
8.10 MenuStrip
137
,
. ,
-,
( 8.11):
MenuItem
ComboBox
Separator
TextBox
8.11
. Separator
.
, ( 8.12)
8.12 Separator
:
ToolStripMenuItem project = new ToolStripMenuItem("Project");
project.Text = "Project";
project.ToolTipText = "Project";
newToolStripMenuItem.DropDownItems.Add(project);
.
,
. () DropDownItems.
.. (
, ).
138
. ShortcutKeyDisplayString
. ( 8.13)
.
8.13
project.ShortcutKeyDisplayString = "Ctrl + P";
ShortcutKeyDisplayString ..
ShowShortcutKeys true.
ShortcutKeys.
( 8.14) .
8.14 ( ) ShortcutKeys
projectToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.P;
,
(accelerator key).
. Alt
.
&
Text ( 8.15).
139
( 8.16).
. .
Delete .
8.16
( 8.17).
,
() .
8.17
( )
Checked ( 8.17).
( 8.18)
8.18
140
( )
.
Click. (Event handler)
( 8.19)
Click.
8.19 Click
:
FileMenu.Click += new System.EventHandler(this.FileMenuItemClick);
private void FileMenuItemClick(object sender, EventArgs e)
{
MessageBox.Show("File menu item clicked");
}
ContextMenuStrip a
.
8.20 ContextMenuStrip a
141
MenuStrip
MenuStrip
( 8.21).
. .
8.21 ContextMenuStrip
ContextMenuStrip .
ContextMenuStrip ContextMenuStrip
.
:
textBox1.ContextMenuStrip = contextMenuStrip1;
, ,
MenuStrip .
StatusStrip a
.
- .
.
( )
MenuStrip ( 8.22).
142
8.22
. , :
BorderSides BorderStyle.
BorderSides
( 8.23).
lblMessage.BorderSides = ToolStripStatusLabelBorderSides.All;
8.23 BorderSides
BorderStyle
( 8.24).
lblMessage.BorderStyle = Border3DStyle.Sunken;
8.24 BorderStyle
143
. ,
.
,
, .
, .
,
ADO.NET,
.
Microsoft Access , , , 99%
SQL Server.
144
. (front end) .
:
,
() ,
.
, ,
, .
: .. (front end)
( (. DataBase Management System DBMS)?
:
,
,
,
:
,
,
(. MS Access, Oracle)
.
,
.
:
ODBC (Open Database Connectivity) 1990.,
() ;
DAO (Data Access Objects) 1992., Access 1.0
,
RDO (Remote Data Objects) 1995., ,
ODBCDirect 1997., DAO , Visual
Basic 5.0,
OLE DB (Object Linking and Embeding for Database) 1996.,
C++,
ADO (ActiveX Data Objects) 1996.,
,
RDS (Remote Data Source) 1998., Web ,
ADO .NET 2000., ADO RDS .
145
ADO .NET ,
Microsoft .NET VS2010 .
, :
(Windows, Linux, Unix)
(Visual Basic, Visual C + +, Visual C #, Delphi, ...)
(Microsoft Access,
Microsoft FoxPro, Paradox, Oracle, ...),
,
- ,
ADO .NET XML (eXtensible Markup
Language),
,
ADO .NET Microsoft Visual Studio. NET (Microsoft
Visual Basic .NET, Microsoft Visual C++ .NET, Microsoft Visual C# .NET)
ADO .NET :
(Data source) - ,
(DataConnection) -
,
(DataAdapter) -
.
(.. DataSet),
,
(DataSet)
.
Access , .
ADO .NET (DataProvider)
(DataSet) ADO .NET
( 9.1).
146
.
.
, , :
- ,
Excel
XML
Word
, .
VS2010
Visual Studio .NET (
MS Access), ADO .NET , ,
(Toolbox) ( 9.2).
9.2 Data.
,
, .. :
147
Data
Choose Items
.
ADO .NET
ADO.NET (ActiveX Data Object) .NET ,
.
.NET Framework
.
.
ADO .NET .
MS Access ,
ADO .NET MS SQL Server.
Northwind.mdb
:
http://www.microsoft.com/downloads/en/details.aspx?FamilyID=C6661372-8DBE-422B-8676C632D66C529C&displaylang=EN
VS2010
1
VS 2010 ,
, . ,
.
, , .
, ,
Microsoft Access SQL Server.
, Data, Add
New Data Source.
148
9.3
2
.
NewConnection, Add Connection
( 9.4).
9.4 VS2010
149
,
( MS SQL Server).
(
MS Access) Change.
Change Data Source.
Change Data Source Microsoft Access Database File
( 9.5).
9.5
,
.
3
. ,
/ ,
.
( MS SQL Server MS Access)
.
(
Browse) ,
.
,
Test Connection. OK .
,
VS 2010 , (
), (No).
9.6.
150
9.6 VS2010
4
("Save connection string..." 9.7)
.
.
9.7
151
9.8
6
.
, , .
, DataGridView.
DataSource,
,
( 9.9).
9.9
152
DataGridView VS2010
. ADO .NET
.
DataGridView (header) .
??
DataGridView
.NET ,
:
System.Data.SqlClient Microsoft SQL Server
(SqlConnection, SqlCommand ...)
System.Data.OleDb
(MS Access, FoxPro, DBF .) (OleDbConnection, OleDbCommand ...)
Oracle MySql .
VS2010 ,
,
.
MS Access
(.. SELECT)
9.10.
9.10
153
(leDbConnection)
/
. MS Access :
OleDbConnection conn = new OleDbConnection();
(.. OleDbConnection)
, :
naziv param1=vrednost param1; naziv param2=vrednost param2;...
; .
MS Access :
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\VisualProgramming\Nwind.mdb;User id=Admin;Password=";
. Open()
. .
conn.Open();
(OleDbCommand)
SQL .
.
:
Connection ,
CommandText SQL
MS Access
OleDbCommand, :
OleDbCommand komanda = new OleDbCommand();
komanda.Connection = conn;
komanda.CommandText = "Select * FROM Customers";
154
(DataSet, DataTable)
SQL . ( )
() (Table). DataSet
( SQL OleDB),
( ).
DataSet dataset = new DataSet();
DataTable table = new DataTable();
(OleDbDataAdapter)
.
, .
Fill(). MS Access
:
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = komanda;
adapter.Fill(dataset);
DataGridView DataSource :
dataGridView1.DataSource = dataset.Tables[0];
dataGridView1.DataSource = table;
DataGridView ,
. DataBindings
Add .
textBox1.DataBindings.Add("Text", dataset.Tables[0], "ProductName");
textBox2.DataBindings.Add("Text", dataset.Tables[0], "UnitPrice");
checkBox1.DataBindings.Add("Checked", dataset.Tables[0], "Discontinued");
DataGridView , Label
Products NorthWind .
5 , Label :
.
155
156
157
2
Assembly
Boolean
Button
Char
CheckBox
ComboBox
Container
DataColumn
DataGrid
DataGridDateTimePickerColumn
DataGridTableStyle
DataGridTextBoxColumn
DataReader
DataRow
DataSet
DataTable
DateTime
Dialog
DialogResult
Double
Exception
GroupBox
HashTable
ImageList
Integer
Label
ListBox
ListView
MarshallByRefObject
Mainmenu
MenuItem
MDI-Frame
MDI-Sheet
NumericUpDown
Panel
PictureBox
RadioButton
SDI-Form
SqlCommand
SqlCommandBuilder
SqlConnection
SqlDataAdapter
StatusBar
String
StringBuilder
TabControl
TabPage
TextBox
ToolBar
ToolBarButton
Timer
UserControl
WindowsPrincipal
asm
bln
btn
ch
cbx
cmb
ctr
dcol
dgrid
dgdtpc
dgts
dgtbc
dreader
drow
dset
dtable
date
dialog
dr
dbl
ex
gbx
htbl
iml
int
lbl
lbx
lv
rmt
mm
mi
frame
sheet
nud
pnl
pbx
rbtn
form
sqlcom
sqlcomb
sqlcon
sqlda
stb
str
strb
tabctrl
tabpage
tbx
tbr
tbb
tmr
usr
wpl
158
[1] Ian Griffiths, Matthew Adams, and Jesse Liberty, Programming C# 4.0, 2010 OReilly, ISBN: 9780-596-15983-2
[2] John Sharp, Microsoft Visual C# 2010 Step by Step, 2010 Microsoft Press
[3] BEN WATSON, C# 4.0 How-To, 2010 SAMS Publisher, ISBN-13: 978-0-672-33063-6
[4] Joseph Albahari and Ben Albahari, C# 4.0 IN A NUTSHELL, Fourth Edition, The Definitive
Reference, ISBN: 978-0-596-80095-6
[5] John Paul Mueller, Visual C# .NET Developer's Handbook, 2002 SYBEX, ISBN: 0-7821-4047-5
[6] James Foxall, Sams Teach Yourself Visual C#2008 in 24 Hours: Complete Starter Kit, 2008
Pearson Education, Inc.ISBN-13: 978-0-672-32990-6
[7] Microsoft C# Language Specifications, 2001 Microsoft Press, ISBN 0-7356-1448-2
159