Windows Forms - PowerPoint PPT Presentation

1 / 123
About This Presentation
Title:

Windows Forms

Description:

?????? ???????? ?? .NET Framework. ?????? ???????? ?? ????? C# ... AutoScroll ?????? ???? ??? ????? ?????????? ?? ?????? ??????????? ?????????? ????? ... – PowerPoint PPT presentation

Number of Views:134
Avg rating:3.0/5.0
Slides: 124
Provided by: sve84
Category:

less

Transcript and Presenter's Notes

Title: Windows Forms


1
(No Transcript)
2
Windows Forms
???????????? ?? .NET Framework
http//www.nakov.com/dotnet/
?????????? ?? ???????? ????????????? ????????? ?
??????? ?????
????????? ????????? ???????????????? ?? ???????
www.devbg.org
3
?????????? ??????
  • ?????? ???????? ?? .NET Framework
  • ?????? ???????? ?? ????? C
  • ?????? ???????? ?? ?????????? ? ????????? ? .NET
    Framework
  • ??????? ?????? ?? ?????? ? Visual Studio .NET ?
    Windows Forms ????????? ??

4
??????????
  • ????? ? Windows Forms?
  • ????????? ??????????. ??????????? ????? ?? .NET
  • ????????? ????? ?? Windown Forms
  • ??????? ???????. ???????? ?? ?????????
  • ?????? Control. ????? ?????? ????????
  • ????? ?? ???????????? ?? ??????????
  • ?????, ???????? ? ??????? ?????? Form
  • ??????? ???????? TextBox, Label, Button
  • ????????? ?? ???????? ??? ???????
  • ?????????? ?? ?????????
  • Windows Forms ?????????? ?? VS.NET

5
??????????
  • ?????????? ????????? ?????
  • ????????? ?? ????????? ?????
  • ????? Windows Forms ????????. ??????. ????? ?
    ???????????. ?????? ?????
  • ?????? ?? ????? ?? ????
  • MDI ??????????
  • ????????? ?? ?????
  • ????????? ?? ????? (Data Binding). ????????? ?
    CurrencyManager
  • ?????????? DataGrid
  • Master-Details ?????????
  • ??????????? ?? ?????

6
??????????
  • ??????? System.Drawing ? GDI
  • ???????? ?? ???????
  • ????????????? ????????
  • ??????? ?? ???????? ? IE
  • ????? ? Windows Forms
  • ??????? (Drag and Drop)
  • ??????????????? ???? ?? ????????????

7
????? ? Windows Forms?
  • Windows Forms
  • ?????????? ?? ?????????? ?? ??????????-??????????
    ???????? ????????????? ????????? (GUI)
  • ???????? ??????????? ?? Rapid Application
    Development (RAD)
  • ???????????-??????????? ???????????
  • ??????????, ???????? ?? ???????
  • ??????? ?? GUI ?????????? ?? Delphi ? Visual
    Basic 6, ? ????? ?? MFC
  • ??????? ????? ????? ?? ????????
  • Data-aware ??????????

8
????? ? Windows Forms?
  • Windows Forms
  • ???????? ????????? ?? Unicode
  • ????????? ??????????? ? ??????????? ?? ????? ?
    ????????
  • ???????? ??????? ActiveX ????????
  • ???????? ???????? ?? ???????
  • ?????????? ????? ?? ?? ?????????? ? Internet
    Explorer
  • ??????? ?? Java ????????
  • ??? ????????????? ??????????? (?? ??????? ??
    ActiveX ??????????)
  • ????? ????????? ?? ??????? (GDI)

9
Windows Forms ??????
public class SampleForm System.Windows.Forms.For
m static void Main()
SampleForm sampleForm new SampleForm()
sampleForm.Text "Sample Form" Button
button new Button() button.Text
"Close" button.Click new
EventHandler(sampleForm.button_Click)
sampleForm.Controls.Add(button)
sampleForm.ShowDialog() private void
button_Click(object sender, EventArgs e)
Close()
10
???????????? 1
  • ?????? ????? Windows Forms ??????????

11
???????? ?? Windows Forms
System.Windows.Forms
Design
ComponentModel
????????? ???????? ?? ?????? ? ????????, ???????,
???????? ?? ????????? ?? ?????, ?? ?????, ??????,
????? ? ???????????, ???????, ??????? ? ??.
System.Drawing
????????? ?????? ?? GDI ????????? ?? Windows
?????? ? ?????, ?????, ??????????? ??????,
???????????? ?? ????????, ?????, ????????,
???????? ?? ??????? ? ??.
Drawing2D
Printing
Imaging
Text
12
????????? ??????????
  • ??????????
  • ????????? ??????? (???????), ????? ???????
    ?????????? ??????
  • ?????????????? (reusable)
  • ???? ???? ????????? ?????????, ????? ??????
    ???????
  • ????????
  • ??????
  • ???????
  • ????????? ?? ???? ???? ?? ????? ?????????? ???
    ????????

13
??????????? ????? ?? .NET
  • ????????????? ????? ????????
  • ????????? ?? ???????????? ? ?????????? ??
    ????????? ??????????
  • ?????? ????? ?? ????????????
  • ????????????? ????? ?? .NET Framework
  • ?????? ??????? ?? ????????? ? ?????????? ?? .NET
    ?????????? (????????? ?????)
  • ???????? ??????? ? ??????????, ????? ?????????
    ?????????? ?? ??????????

14
??????????? ????? ?? .NET
  • ????????????? ????? ?? .NET
  • ????????? ?????????? ?? ??????????? ??
    ????????????
  • ?? ????? ?? ?????? (design-time behavior)
  • ?? ????? ?? ?????? (runtime behavior)
  • ????????? ????? ???????????????? (reusability)
  • ???????? ?????????? ? ??????????
  • CLR ????????? ???????????? ???????????? ??
    ????????????
  • ????????? ?????????????? ?? ???????????? ????? ??
    ?????? ? System.ComponentModel

15
Windows Forms ? ????. ?????
  • Windows Forms ? ??????? ?? ???????????? ????? ??
    .NET
  • ????????????? ????? ???????? ?????????? ?
    ??????????
  • Windows Forms ???????? ???????? ?
    ?????????-????????
  • ?????????? ?? ?????? ?? ??????????? ??????????
  • ?????????-???????? (?????, ???????, ??????, ...)
    ???????? ????? ????????
  • ???????? (??????, ???????? ??????, ...)
    ???????? ?? ? ????????? ??????????

16
????????? ????? ?? WinForms
  • ??????????? ????? ?? Windows Forms ????????
  • ????? (???????? ? ???????)
  • ???????? (???????? ??????, ??????, ??????, ?????
    ? ???????????, ...)
  • ???????, ????? ?? ??????????
  • ?????? ????? ?? ????????????
  • ????? ?? ???????????? ?? ??????????
  • ?????????? ?? ?????? ? ?????????
  • ????????? ????? ?? ???????????? ? ??????? ??
    ?????????
  • ?????????? ????????? ????????? ?? ???????????????
    ???????? ? ???????? ?? ?????????? ?????

17
????????? ????? ?? WinForms
  • ???????? ????? ?? ????? Windows Forms ??????????
    ?????? ????
  • ????????? ????? ?? ?????????
  • ??? ?????????? ?? ????????? (????. ??????????? ??
    ???????, ????????? ?? ?????? ??? ??.) ??
    ????????? ????
  • ?????? ??????????, ?? ????? ?? ?????? ???????????
  • ??????? ? ???????????
  • ??? ?????????? ? ?????????-????????, ?? ????? ?
    ???? ?? ?? ??? ?? ??????? ???????? ? ???????????
    ? ? ?? ???????
  • ??? ????????? ?? ???????? ????? ?? ????????????,
    ?? ????? ???????????? ??

18
??????? ???????
  • ???????????? Windows Forms ????????
  • ?????????? ?? ?????? ??????? ?? ?????????? ?
    ?????????-??????????
  • ????????? ???????? ????????
  • ??????? ?????? ???????
  • Component .NET ?????????
  • Control ???????? ???????? (?????????? ?
    ???????? ?????)
  • ScrollableControl ????????, ????? ????????
    ?????????? ?? ???????????? ??
  • ContainerControl ????????, ????? ??????? ?????
    ???????? ? ????????? ??????????? ?? ??????

19
???????? ?? ?????????
20
?????? Control
  • ?????? System.Windows.Forms.Control ? ?????? ??
    ?????? ???????? Windows Forms ????????
  • ???????? ???????? ?? ??????? ?? ?????? Windows
    Forms ????????
  • ??-??????? ???????? ?? ????? Control
  • Anchor, Dock ??????? ?? ????? ????? ??????????
    ?? "???????" ?? ?????????? ??
  • Bounds ?????? ??????? ? ????????? ?? ??????????
    ? ?????? ?????????
  • BackColor ?????? ????? ?? ????
  • ContextMenu ?????? ?????????? ???? (popup menu)
    ?? ??????????

21
?????? Control
  • ??-??????? ???????? ?? ????? Control
  • Controls ??????? ???????? ?? ????????? ????????
    (??? ???)
  • CanFocus ????? ???? ?????????? ???? ?? ????????
    ??????
  • Enabled ????????? ??????????? ?? ?????????? (??
    ????? ??????, ?? ?????????)
  • Font ?????? ?????? (???, ????, ??????)
  • ForeColor ?????? ????? ?? ??????????
  • Location ??????? ????????? ?? ???????? ? ??????
    ?????????
  • Parent ?????? ?????????-??????????, ?????????
    ???????? ????????

22
?????? Control
  • ??-??????? ???????? ?? ????? Control
  • Size ??????? ????????? ?? ??????????
  • TabIndex ???????? ???? ??? ????????? ? ???????
    TAB
  • TabStop ?????? ???? ?????????? ???? ?? ??
    ???????? ??? ????????? ? TAB
  • Text ?????? ?????, ??????? ? ??????????
  • Visible ?????? ???????? ?? ??????????
  • ??-????? ?????? ?? ????? Control
  • Focus() ???????? ??????????
  • Hide(), Show() ??????/??????? ??????????

23
?????? Control
  • ??-??????? ??????? ?? ????? Control
  • Click ???????? ??? ???????? ? ??????? ?????
    ??????????
  • Enter, Leave ????????? ??? ?????????? ?
    ???????????? ?? ??????????
  • KeyDown, KeyUp ????????? ??? ????????? ?
    ????????? ?? ?????? (??? ??????????)
  • KeyPress ??? ????????? ?? ?????????????? ??????
  • MouseDown, MouseUp, MouseHover, MouseEnter,
    MouseLeave, MouseMove, MouseWheel ????????? ???
    ??????? ?? ???????, ????????? ????? ??????????

24
?????? Control
  • ??-??????? ??????? ?? ????? Control
  • Move ???????? ??? ??????????? ?? ??????????
  • Paint ???????? ??? ???????????? ?? ??????????
  • Resize ???????? ??? ??????? ?? ??????? ??
    ??????????
  • TextChanged ???????? ??? ??????? ?? ??????????
    Text ?? ??????????
  • Validating ???????? ?? ?? ????????? ?? ???????,
    ???????? ? ??????????

25
???????????? ?? ??????????
  • ? Windows Forms ?????????? ????? ?? ???????????
  • ??? ??????????? ?? ????????
  • ??? ????? ?? ???????? ????????
  • ??? ??????? ?? ??????? ??? ????????? ?? ?????
    ????????
  • ?????????????? ????? ?? ??? ?????
  • Invalidate() ???????? ?? ???????????? ????????
    ???????? ??? ???? ??????? ? ??????? ?????????
    "?????????"
  • Update() ????????? ??????????? "?????????",
    ????????? ?? Invalidate() ? ???????? ????????
    ???????? ???????

26
????? ?????? ????????
  • ?????? ScrollableControl
  • ?????? ?????????????? ?? ??????????
  • AutoScroll ?????? ???? ??? ????? ?????????? ??
    ?????? ??????????? ?????????? ?????
  • HScroll, VScroll ??????? ???? ?????????? ?? ???
    ???????????? ? ?????????? ?????????? ?????
  • ?????? ContainerControl
  • ????????? ?????????????? ?? ?????????? ?? ??????
  • ActiveControl ??????? ??????????, ????? ? ??
    ?????

27
?????, ???????? ? ???????
  • ?????? System.Windows.Forms.Form
  • ???????????? ????? (???????? ??? ????????? ?????)
    ? GUI ????????????
  • ? ???? ????? ?? ?? ??????? ????????
  • ??????? ???????? ?? ????? Form
  • FormBorderStyle ?????? ???? ?? ??????? ??
    ???????
  • Sizable ?????????? ?????????? ?????
  • FixedDialog ?????? ? ????????? ???????
  • None ??? ?????
  • FixedToolWindow ????? ? ??????????? ? ????????
    ??????

28
?????, ???????? ? ???????
  • ??????? ???????? ?? ????? Form
  • Controls ?????? ? ?????????? ??????????? ???
    ???????
  • Text ???????? ?? ?????????
  • Size ??????? ?? ?????????
  • ClientSize ?????? ?? ???????????? ?? ???????
    (??? ??????? ?)
  • AcceptButton ????? ?? ????????????
  • ActiveControl ??????????, ????? ????? ??????
  • ControlBox ?????? ???? ??????? ?? ??? ????????
    ?? ?????????, ??????????? ? ?. ?.

29
?????, ???????? ? ???????
  • ??????? ???????? ?? ????? Form
  • Icon ?????? ????? ?? ?????????
  • KeyPreview ??? ?? ?????? true, ?????????
    ??????? ?? ????????? ????????? ?? ????????????
    ????? ?? ?? ??????? ?? ???????????? ????????
  • MinimumSize, MaximumSize ?????? ??????????? ??
    ??????? ?? ???????
  • Modal ?????? ???? ??????? ? ???????
  • Opacity ?????? ??????????? (0.00 1.00)
  • MdiChildren, MdiParent ???????/??????
    ??????????? ?????/??????????? ?? ???????? ????? ?
    MDI ?????

30
?????, ???????? ? ???????
  • ??????? ???????? ?? ????? Form
  • TopMost ?????? ???? ??????? ???? ??? ??????
    ????? ???????? (always on top)
  • WindowState ??????? ??????????? ?? ???????
    (????????, ???????????? ??? ?????????????)
  • ??????? ?????? ?? ????? Form
  • Close() ??????? ??????? (?????? ? ? ???????????
    ???????????? ???????)
  • Show() ??????? ??????? ? ? ????????
  • ShowDialog() ??????? ??????? ? ??????? ????? ?
    ????? ???? ???????? DialogResult ??????????

31
?????, ???????? ? ???????
  • ??????? ?????? ?? ????? Form
  • LayoutMdi() ?????????? ????????? (MDI) ?????
    (????????, ????????????, ??????????)
  • ??????? ??????? ?? ????? Form
  • Activated / Deactivate ??????? ??? ?????????? /
    ???????????? ?? ??????? (?????????? / ?????? ??
    ??????)
  • Closing ??????? ?? ??? ????????? ?? ???????.
    ???????????? ???? ?? ??????????? ????????? ??
    ???????????
  • Load ??????? ?? ?????????? ??? ???????
    ????????? ?? ???????. ????? ?? ?????? ?? ??
    ?????????????? ?? ???????????

32
??????? ????????
  • TextBox ???? ?? ????????? ?? ?????.
    ??-????? ????????
  • Multiline ?????? ???? ?? ?? ??????? ?????????
    ?? ??????? ????
  • Text (Lines) ??????? ????????? ?????
  • Label ?????????? ????? ???
    ???????. ????? ????????
  • Text ???????, ????? ?? ??????????
  • Button ????? ?? ?????????.
    ??-????? ???????? ? ???????
  • Click ???????? ?? ??? ?????????
  • Text ?????? ?????? ????? ??????

33
????????? ?? ????????
  • ??????????? ?? ???????? ??? ??????? ????? ????
    Controls.Add
  • ????? ?? ?????????? (?. ???. z-order) ?? ????????
    ?? ???? ?? ??????????? ?? (?????????? ???????? ?
    ???-??????)
  • Windows Forms ?????????? ?? Visual Studio .NET ??
    ????? ?? ?????????? ????????? ?? ??????????

Form form new Form() Button button new
Button() button.Text "Close" form.Controls.Add
(button)
34
?????????? ?? ?????????
  • ???????????? ?? ??????? ????? ????
  • Windows Forms ?????????? ?? Visual Studio .NET
    ???????? ??????????? ????????????? ?? ???????

Form form new Form() Button button new
Button() button.Click new EventHandler(
this.button_Click) ... private void
button_Click( object sender, EventArgs e)
// Handle the "click" event
35
?????????? ?? ?????????
  • ?????? ??????? ? Windows Forms
  • EventHandler ?????? ???????????
  • ??? ???????????? ?????
  • KeyEventHandler ??????? ?? ????????????
  • ?????? ?? ??? ? ??????????? ?????? ? ???????????
    ?? Ctrl, Shift ? Alt
  • MouseEventHandler ??????? ?? ???????
  • ?????? ?? ????????? ?? ??????? ? ??????????? ??
    ???????? ?
  • CancelEventHandler ???????, ????? ????? ??
    ??????? ????????? ????????

36
????? ?????????? ??????
using System using System.Drawing using
System.Windows.Forms public class
CalculatorForm Form private TextBox
mTextBoxNumber1 private TextBox
mTextBoxNumber2 private TextBox
mTextBoxSum private Button mButtonCalc
private Label mLabelPlus private Label
mLabelEquals public CalculatorForm()
mTextBoxNumber1 new TextBox()
mTextBoxNumber1.Bounds new Rectangle(
new Point(16, 16), new Size(72, 20))
mTextBoxNumber1.MaxLength 10 (????????
??????????)
37
????? ?????????? ??????
mLabelPlus new Label()
mLabelPlus.AutoSize true
mLabelPlus.Location new Point(94, 19)
mLabelPlus.Text "" mTextBoxNumber2
new TextBox() mTextBoxNumber2.Bounds
new Rectangle( new Point(112, 16),
new Size(72, 20)) mTextBoxNumber2.MaxLeng
th 10 mLabelEquals new Label()
mLabelEquals.AutoSize true
mLabelEquals.Location new Point(191, 18)
mLabelEquals.Text "" mTextBoxSum
new TextBox() mTextBoxSum.Bounds new
Rectangle( new Point(208, 16), new
Size(72, 20)) mTextBoxSum.ReadOnly
true (???????? ??????????)
38
????? ?????????? ??????
mButtonCalc new Button()
mButtonCalc.Bounds new Rectangle(
new Point(16, 48), new Size(264, 23))
mButtonCalc.Text "Calculate sum"
mButtonCalc.Click new EventHandler(
this.ButtonCalc_Click)
this.AcceptButton mButtonCalc
this.ClientSize new Size(298, 87)
this.Controls.Add(mTextBoxNumber1)
this.Controls.Add(mLabelPlus)
this.Controls.Add(mTextBoxNumber2)
this.Controls.Add(mLabelEquals)
this.Controls.Add(mTextBoxSum)
this.Controls.Add(mButtonCalc)
this.FormBorderStyle
FormBorderStyle.FixedDialog
this.MaximizeBox false
this.MinimizeBox false this.Text
"Calculator" (???????? ??????????)
39
????? ?????????? ??????
private void ButtonCalc_Click( object
aSender, EventArgs aArgs) try
int value1
Int32.Parse(mTextBoxNumber1.Text)
int value2 Int32.Parse(mTextBoxN
umber2.Text) int sum value1
value2 mTextBoxSum.Text
sum.ToString() catch
(FormatException)
mTextBoxSum.Text "Invalid!"
mTextBoxNumber1.SelectAll()
mTextBoxNumber2.SelectAll() (???????? ??????????)
40
????? ?????????? ??????
mTextBoxNumber1.Focus()
static void Main() CalculatorForm
calcForm new CalculatorForm()
Application.Run(calcForm)
41
???????????? 2
  • ????? ??????????

42
Windows Forms ? VS.NET
  • Windows Forms ?????????? ?? VS.NET ?????????
  • ????????? ?? ?????
  • ???????? ?? ????????
  • ???????? ?? ?????????? ??????????
  • ????????? ?? ??????????
  • ???????? ?? ???????
  • ????????? ?? ?????

43
Windows Forms ? VS.NET
  • ???????? ?? ????????
  • ???????? ?? ?????????? ??????????

44
Windows Forms ? VS.NET
  • ???????? ?? ??????????? ?? ???????
  • ????????? ?? ??????????

45
???????????? 3
  • ????????? ?? ????? ?????????? ? Windows Forms
    ????????? ?? VS.NET

46
?????????? ????????? ?????
  • ?????? MessageBox ????????? ????????? ??
    ?????????? ????????? ?????
  • ????????? ??? ???????????
  • ???????????? ???????
  • ???????

MessageBox.Show("???? ?????? ? ????????.",
"??????????????")
bool confirmed MessageBox.Show("???????? ?? "
"?? ???????? ?????", "??????",
MessageBoxButtons.YesNo, MessageBoxIcon.Question
) DialogResult.Yes
47
????????? ?? ????????? ?????
  • ??????????????? ????????? ????? ?? ???????? ????
  • DialogResult result dialog.ShowDialog()
  • ShowDialog() ??????? ??????? ???????
  • DialogResult ??????? ????????? (OK, Yes, No,
    Cancel ? ??.)
  • ???????? ?? DialogResult
  • ??????????? ???? ?????????? DialogResult ??
    ????????
  • ????? ????? ????????? ?? ??????? ????
    ?????????? ?? DialogResult

48
????????? ????? ??????
49
???????????? 4
  • DialogResult ? ????????? ?? ????? ????? ???????

50
????? Windows Forms ????????
  • CheckBox ????? ?? ????? ? ????
    "??/??". ??-????? ????????
  • Checked ?????? ???? ? ???????
  • RadioButton ???????? ??
    ???????????? ?????
  • Checked ?????? ???? ? ???????
  • CheckedChanged ???????? ?? ??? ??????? ??
    Checked ??????????
  • ???????? ?? ? ?????
  • ???? ???? RadioButton ? ?????? ? ????? ??????
  • ???????? ?? ? GroupBox, Panel ??? TabPage

51
????? Windows Forms ????????
  • PictureBox ?????????? ????????. ??-?????
    ????????
  • Image ?????? ??????????
  • SizeMode ?????? ???? ?????????? ?? ?? ??????? /
    ?????? ??? ????????
  • Panel ???????????? ?????????, ????? ???????
    ????? ????? ????????
  • TabControl, TabPage ?????????? ???????? ??
    ?????? ??? ????????

52
????? Windows Forms ????????
  • ListBox ?????????? ?????? ? ??????. ??-?????
    ????????
  • Items ?????? ???????
  • SelectionMode ????????? / ????????? ???????????
    ?? ??????? ???????? ????????????
  • SelectedIndex, SelectedIndices, SelectedItems
    ????? ???????? ??????? (??? ????????? ????????)
  • CheckedListBox ?????? ?? ??????????? ?? ?????
    "??/??"
  • Items ?????? ?????????????
  • CheckedItems ????? ?????????

53
???????????? 5
  • ?????? ? ????? ????????

54
????? Windows Forms ????????
  • ComboBox ????? ?? ???????? ?? ????? ?
    ?????????? ?? drop-down ???????????? ?????.
    ??-????? ????????
  • Text ????????? ?????
  • Items ???????? ?????????
  • DropDownStyle ?????? ???? ???? ???? ?? ??????
    ???????? ?? ??????? ??? ???? ?? ?? ??????? ?????
    ????????
  • TreeView ?????????? ?????????? ?????. ???????
    ????????
  • Nodes ??????? ??????? (?????? ?? TreeNode
    ??????)
  • SelectedNode ???????? ?????

55
????? Windows Forms ????????
  • LinkLabel ?????????
    (hyperlink)
  • Text ?????????? ?? ????????
  • LinkClicked ???????? ?? ??? ???????? ?????
    ???????????
  • RichTextBox ????? ?? ???????? ?? ????? ?
    ??????????? (Rich Text Format)
  • LoadFile, SaveFile ???????/??????? RTF
  • SelectionFont, SelectionColor, SelectionAlignment
    ??????? ?????, ???? ? ???????????? ?? ????????
    ?????

56
??????
  • MainMenu ??????
    ????
  • ??????? ?????? ?? MenuItem ????????
  • MenuItem ??????? ?? ????
  • Text ???????? ?? ????????, ???????? New ???
    Open ???
  • ShortCut ?????? ??????
  • Click ??????? ????????
  • ContextMenu ?????????? ???? (popup ????)
  • ??????? ?????? ?? MenuItem ????????

57
????? ? ???????????
  • ToolBar ????? ? ??????????? (? ??????)
  • Buttons ??????? ?????? ?? ToolBarButton
    ????????
  • ImageList ?????? ?????????? ?? ????????
  • ButtonClick ???????? ?? ??? ????????? ?? ?????
  • ?????? ?? ToolBarButtonClickEventArgs ?
    ?????????? ??? ????? ? ??? ????????
  • ToolBarButton ????? ? ???????
  • ImageList ?????? ? ????????

58
?????? ?????
  • StatusBar ?????
    ?? ???????????
  • Panels ??????? ???????? ?? ???????
  • ShowPanels ??????? / ???????? ????????? ??
    ????????
  • StatusBarPanel ?????? ? ???????
  • Text ?????????? ?? ??????
  • Icon ????? ?? ??????

59
?????? ?? ????? ?? ????
  • OpenFileDialog ?????? ?? ????? ?? ???? (???
    ????????)
  • Title ???????? ?? ???????
  • InitialDirectory ??????? ??????????
  • Filter ?????? ?????????? ??????? ??????????
  • FilterIndex ?????? ???????? ??????
  • Multiselect ????? ?? ????? ???????
  • FileName, FileNames ???????? ????
  • SaveFileDialog ?????? ?? ????? ?? ???? (???
    ?????????)

60
?????? ?????? ??????
private void buttonLoadFile_Click( object
sender, System.EventArgs e) OpenFileDialog
openFileDialog new OpenFileDialog()
openFileDialog.Filter "Text files
(.txt).txt" openFileDialog.Title
"Choose text file" if (openFileDialog.ShowDi
alog() DialogResult.OK) string
fileName openFileDialog.FileName using
(StreamReader reader
File.OpenText(fileName))
string fileContents reader.ReadToEnd()
textBox.Text fileContents
61
???????????? 6
  • ?????? ? ?????? ??????

62
MDI ??????????
  • MDI (Multiple Document Interface) ????????????
    ????????? ?????? ? ??????? ????????? ????????????
  • MDI ?????????? (MDI parents)
  • ???????? ????? ?????
  • ?????????? ???? ???? Window ?? ????? ?? ?????????
    ????? (MdiList true)
  • ?????? ?? ?? IsMdiContainer true
  • MDI ??????? (MDI children)
  • ???????? ?? ? ?????????-???????
  • ?????? ?? ?? MdiParent lt?????????gt

63
???????????? 7
  • ??????????????? ??????? ????????

64
????????? ?? ?????
  • ??????????? ? ??????????, ?????? ? ??????
    ???????? ?????? ?? ?? ??????? ????????? ???? ??
    ???????? ?????
  • ? Windows Forms ??? ?????????? ???????? ??
    ?????????
  • Validating ??????? ?? ????????? ?? ??????? ?
    ????? Control
  • ?????? ?? ????????? ?? ??? CancelEventArgs
  • ??? ?? ?????? Canceltrue ?? ????? ???????????
    ?? ??????? ??????????
  • ErrorProvider ????????? ???????? ???????? ?
    ????????? ?????

65
????????? ?? ????? ??????
private TextBox textBox1 private ErrorProvider
errorProvider ... private void
textBox1_Validating(object sender,
System.ComponentModel.CancelEventArgs e)
try Int32.Parse(textBox1.Text)
errorProvider.SetError(textBox1, "")
catch (FormatException)
errorProvider.SetError( textBox1,
"Integer number expected!") e.Cancel
true
66
???????????? 8
  • ????????? ?? ?????

67
????????? ?? ?????
  • ??????????? ?? ??????? (Data Binding)
  • ????????? ??????????? ??????????? ?? ????? ?????
    ???????? ? ????????? ?? ?????
  • ???????? ????????? ?? ????? ???????? ????? ??
    ??????? ? ComboBox ????????
  • ????????? ?? ?????
  • IList ?????? ? ????????
  • IBindingList ???????? ?? ?? DataView
  • ???????? ??????????? ?? ???????
  • ????????, ?????????? data binding
  • ?????? Windows Forms ????????
  • TextBox, ComboBox, ListBox, DataGrid

68
????????? ?? ?????
  • ?????? ?????????
  • ?????? ????????? (simple binding)
  • ????????? ?? ???????? ? ???????? ?????
  • ????????? ?? ???????? ? ???????? ??????? ??
    ??????
  • ???????? TextBox ? CheckBox
  • ?????? ????????? (complex binding)
  • ????????? ?? ???????? ? ??? ??????
  • ???????? ListBox, ComboBox, DataGrid

69
?????? ?????????
  • ????????? ?? ???????? ??? ?????
  • ??? ??????? ?? textBox1.Text ?? ???????
    ?????????? ?????

class Customer private string mName
public string Name get return
mName set mName value
Customer cust new Customer() cust.Name
"??? ????" textBox1.DataBindings.Add( new
Binding("Text", cust, "Name"))
70
???????????? 9
  • ????????? ?? ???????? ??? ?????

71
?????? ?????????
  • ????????? ?? ???????? ??? ??????
  • ????????? ?? ???????? ??? ???????

string towns "?????", "???????",
"?????" textBoxTowns.DataBindings.Add( new
Binding("Text", towns, ""))
// ????? DataSet ds ? ??????? Towns ? ?????? id ?
name DataTable towns new DataTable("Towns") to
wns.Columns.Add(new DataColumn("id",
typeof(int))) towns.Columns.Add(new
DataColumn("name", typeof(string))) DataSet ds
new DataSet() ds.Tables.Add(towns) textBoxTowns
.DataBindings.Add( new Binding("Text", ds,
"Towns.name"))
72
?????? ????????? ? VS.NET
  • ??????????? ???? ?? ????? ? ?? ????? ?? ?????? ?
    VS.NET (??? ?????????? ?? ???????? DataSet)

73
BindingContext
  • ??????? ???? ?????????? ?? ?????????? ???????? ?
    ???? BindingContext ?????
  • CurrencyManager ?? ???????? ???????? ???
    ??????. ??????? ????????? ? ???????
  • PropertyManager ?? ???????? ???????? ??? ?????

CurrencyManager
Array
CurrencyManager
Collection
BindingContext
Form
CurrencyManager
DataTable
PropertyManager
Object
74
????????? ? CurrencyManager
  • CurrencyManager ?????? ???? ???????? ??????? ?
    ??????? ???????? ?? ?????
  • Position ??????? ?????????
  • Count ??????? ??????? ?? ???????
  • ????????? ?? ????????? ?? ?????
  • ????????? ?? CurrencyManager ??????
  • ????????? ?? ???????

CurrencyManager cm (CurrencyManager)
textBox1.DataBindings"Text".BindingManagerBase
// ???? ? ???? CurrencyManager cm
(CurrencyManager) form1.BindingContextdataTab
leCustomers
cm.Position
75
???????????? 10
  • ????????? ?? ???????? ??? ?????? ? ????????? ??
    ???????

76
?????? ?????????
  • ????????? ?? ???????? ??? ??????
  • ???????? ?? ??? ???????? ????????
  • ListBox, ComboBox ? ??.
  • ??????? ?? ??????????
  • DataSource ?????? ? ???????
  • DisplayMember ??? ?? ??????, ????? ?? ??
    ???????????
  • ValueMember ??? ?? ??????, ?? ????? ?? ????????
    ?????????
  • ??????

comboBox1.DataSource dataSetCountries
comboBox1.DisplayMember "Countries.CountryCode"
comboBox1.ValueMember "Countries.Name"
77
???????????? 11
  • ?????? ????????? ?? ???????? ??? ??????

78
?????? ????????? ? VS.NET
  • ??????????? ???? ?? ????? ? ?? ????? ?? ?????? ?
    VS.NET (??? ???????? ?? ???????? DataSet)

79
?????????? DataGrid
  • DataGrid ?????????? ??????????? ???????? ?????
  • ????????? ????????? ?? ?????? ? ??????
  • ????????? ??????????? ?? ???????
  • ????? ??????????????
  • ?? ???? ???????? ? ?????? ?????? ?? .NET
    Framework
  • ???????? ?? ???-????? ? ADO.NET DataSet ?
    DataTable
  • DataSource ?????? ????????? ?? ?????
  • DataMember ?????? ???? ?? ??????? ? ??????? ??
    ?????????

80
DataGrid ??????
private void MainForm_Load( object sender,
System.EventArgs e) // Create table
"Towns" DataTable towns new
DataTable("Towns") towns.Columns.Add(
new DataColumn("id", typeof(int)))
towns.Columns.Add( new DataColumn("name",
typeof(string))) // Add some rows in the
table DataRow row towns.NewRow()
row"id" 1 row"name" "?????"
towns.Rows.Add(row) row towns.NewRow()
row"id" 2 row"name" "???????"
towns.Rows.Add(row)
81
DataGrid ??????
row towns.NewRow() row"id" 3
row"name" "?????" towns.Rows.Add(row)
row towns.NewRow() row"id" 4
row"name" "????" towns.Rows.Add(row)
// Add table "Towns" to the DataSet
DataSet ds new DataSet()
ds.Tables.Add(towns) // Bind the DataGrid
to the DataSet dataGridTowns.DataSource
ds dataGridTowns.DataMember "Towns"
82
???????????? 12
  • ?????? ? DataGrid

83
?????????? DataGrid
  • ??-????? ???????? ?? DataGrid
  • ReadOnly ????????? / ????????? ????????
  • CaptionVisible ??????? / ?????? ??????????
  • ColumnHeadersVisible ??????? / ??????
    ?????????? ?? ????????
  • RowHeadersVisible ??????? / ?????? ????????
    ????? ?? ????????
  • TableStyles ?????? ??????? ?? ?????????
  • ??????? ? ???? ??????? ????
  • MappingName ?????? ?????????, ?? ????? ??
    ?????? ???????????? ????
  • GridColumsStyles ?????? ????????????? ??
    ????????? ?????? ????????, ?????? ? ??.

84
???????????? 13
  • TableStyles ?????????? ?? ??????? ?? DataGrid

85
Master-Details ?????????
  • Master-Details ??????????? ????????
    ??????????????? ??? "1 ??? ?????"
  • ???????? 1 ?????? ??? ????? ???????
  • ? ADO.NET DataSet ???????? ?? ????????? ???????
    ??? "??????/????????"
  • ????????? ?? DataRelation ???????? ? DataSet
  • Windows Forms ???????? Master-Details ?????????
  • ?? ???????? ???????? ?? ?????? ?? ???????? ??
    ??????? ???????? ???????
  • ?? ??????????? ???????? ?? ?????? ?? ???????? ??
    ??????? ????????? ?? ?????????
  • ?????????? ?? ???????? ? ???? ? ??? DataSet

86
Master-Details ??????
// Bind the master grid to the master
table dataGridCountries.DataSource
datasetCountriesAndTowns dataGridCountries.DataMe
mber "Countries" // Bind the detail grid
to the relationship dataGridTowns.DataSource
datasetCountriesAndTowns dataGridTowns.DataMembe
r "Countries.CountriesTowns"
87
???????????? 14
  • Master-Details ?????????

88
??????? "????? ??? ?????"
  • ??????? ??? "????? ??? ?????" ?? ?? ????????? ??
    DataSet ? DataGrid
  • ????? ?? ????? ??????? ?? Master-Details ????
    ???????? ?? ?????? ? ?????? ?? ?????

CREATE VIEW VIEW_StudentsCourses AS SELECT
StudentId, StudentName, CourseId, CourseName FROM
Students, Courses, StudentsCourses WHERE
Students.StudentsId StudentsCourses.StudentId AN
D Courses.CourseId StudentsCourses.CourseId
89
??????? "????? ??? ?????"
90
??????????? ?? ?????
  • ????????????? ?? ?????
  • ????????? ???????? ?????????? ?? ????? ??
    ?????????????? ?????????
  • ???????? ? ?? ?? ???????? ???????? ?????? ?????
    ?? ????? ?????
  • ???? ??????? ?? ???????? DLL ???? ???? ?? ??
    ???????? ?????? ?????
  • ???????-?????????? ????? ?? ???????
    ??????????????
  • ????????? ?????? ????? ?? ?????????? ????????????
    ?? ???????????? ??????????????, ???????? ??
    ???????? ?????

91
??????????? ?? ?????
  • ???????? ????? ? ???-?????????? ?????
  • ??????????, ????? ????? ?? ?? ????????, ?? ??????
    ???? protected
  • ?????????? ???????? ?? ????? ?? ?? ???????? ??
    ???????-??????????
  • ?? ??????????? ?? ????? ?? ????????? ?????? ??
    ???????? ?????
  • ???????-?????????? ?? ???????? ?? ?? Visual
    Studio .NET (???? File Add New Item
    Inherited Form)
  • ??? ??????? ?? ???????? ????? ???????????? ??????
    ?? ?? ????????????

92
???????????? 15
  • ??????????? ?? ?????

93
????????? ? System.Drawing
  • System.Drawing ????????? ?????? ?? GDI ?????????
    ?? Windows
  • ??????????? ?? ???????
  • ?????? ? ??????? ? ???????? ?????????????
  • ??????????? ?? ??????????? ??????
  • ?????? ? ???????????
  • ?????? ? ????? ? ????????
  • ???????? ?? ???????

94
??????? System.Drawing
  • System.Drawing ?? ?????? ??
  • System.Drawing
  • ??????? ???????
  • ???????????, ??????, ?????
  • ??????? ??????????? ??????
  • ???????????? ?? ?????
  • System.Drawing.Imaging
  • ?????? ? ???????????
  • ???????? ? ?????
  • ?????? ? ????????? ? ???????? ??????? ???????
  • ???????????? ?? ???????????

95
??????? System.Drawing
  • System.Drawing ?? ?????? ??
  • System.Drawing.Drawing2D
  • ???????? ?????????????
  • ??????, ??????? ? ??.
  • System.Drawing.Text
  • ????????? ?????? ?? ??????????
  • System.Drawing.Printing
  • ???????? ?? ???????
  • ???????? ????????? ????? ?? ????????

96
?????? Graphics
  • ?????? System.Drawing.Graphics
  • ?????????? ?????????? ?????????? ?? ???????
  • ???-????? ????????? ?? ???????? ? ??????????? ??
    ????????? Paint
  • Paint ???????????? ?????????? ??? ????????????
  • ??????????? PaintEventArgs ??????? Graphics
    ??????
  • ???? ?? ?? ??????? ???? Control.CreateGraphics()
  • ?????? ?? ?? ??????????? ???? finally ???? ??? ?
    ????????????? using

97
System.Drawing ??????
private void MainForm_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
Graphics g e.Graphics g.SmoothingMode
SmoothingMode.AntiAlias Brush brush new
SolidBrush(Color.Blue) g.FillEllipse(brush,
50, 40, 350, 250) Pen pen new
Pen(Color.Red, 2) g.DrawRectangle(pen, 40,
50, 200, 40) brush new SolidBrush(Color.Ye
llow) Font font new Font("Arial", 14,
FontStyle.Bold) g.DrawString(".NET
Rulez", font, brush, 60, 60)
98
???????????? 16
  • ?????? ??? System.Drawing

99
???????????? 17
  • ???????? ??? System.Drawing

100
???????? ?? ???????
  • ????????? ?? 3 ??????? ?????
  • PrintDialog
  • ?????????? ?????? ?? ???????? ?? ???????
  • PrintController
  • ????????? ??????? ?? ???????? ? ???????? ???????,
    ???????? ? ????
  • ?????????? Graphics ????????????
  • PrintDocument
  • ?????? ???????????????? ?? ???????????? ????????
  • ??????? PrinterSettings ??????? ?? PrintDialog

101
????????????? ????????
  • ??????????????? ???????? (custom controls)
  • ?????????? ??????????? ?? ??????????? ????? ??
    ???????? ????
  • ??????????? ?? ????? ???????? ? ????
  • ??????????? ? ????????? ?? ????????
  • ????????? ?? ?????? ???? ????????
  • ????? ?? ?????????? ??????????? ??
  • ?? ????? ?? ?????? ?????????????? ? ?????????
    ?? VS.NET
  • ?? ????? ?? ??????????
  • ?????????? ???????????? ????????, ????? Control
    ??? UserControl

102
????????? ?? ????????
  • ????????? ?? ???? ????????, ????? ?? ?????????
    ????? ????????????
  • ?? VS.NET ? New Item ? Custom Control
  • ??????????? ????? Control
  • ???????????? ?????????? ????? OnPaint() ?? ??
    ??????? ??????????
  • ?????????? ???????????? ???????? ? ??????
  • ????????? ??????????, ???????? ?? ????????? ????
    ????????
  • Category ????????? ? ?????????
  • Description ???????? ?? ??????????

103
????????? ?? ???????? ??????
public class ClockControl System.Windows.Forms.C
ontrol private int mHour private int
mMinute Category("Behavior"),
Description("Specifies the hour.") public
int Hour get
return mHour set
mHour value
this.Invalidate() (????????
??????????)
104
????????? ?? ???????? ??????
protected override void OnResize(System.EventA
rgs e) this.Height this.Width
this.Invalidate() protected
override void OnPaint(PaintEventArgs pe)
Graphics g pe.Graphics // Draw
the clock circle Pen pen new
Pen(Color.Blue, 1) g.DrawEllipse(pen, 0,
0, this.Width-1, this.Height-1)
// Draw the minute finger and the clock
finger // ...
105
???????????? 18
  • ????????????? ???????? "????????"

106
????????? ?? ????????
  • ????????? ?? ???? ????????, ???? ?????????? ??
    ????? ????????
  • ?? VS.NET ? New Item ? User Control
  • ?????????? ????????? ?? VS.NET
  • ????????? design-time ?????????? ???? ??????????
    Category ? Description
  • ????????? ?? ???? ????????, ????? ?????????
    ???????????? ????????
  • ?? VS.NET ? New Item ? Inherited User Control
  • ?????????? ?????????????? ???????? ? ?????? ? ??
    ????????? ?? VS.NET ?????????
  • ???????????? OnXXX() ???????? ??? ????????????

107
??????? ?? ???????? ? IE
  • Internet Explorer ???? ?? ????????? Windows Forms
    ???????? ???????? ? ?????? ?? HTML ????????
  • ???????????? ? ??????? ?? Java ???????? ???????
    ?? ???????? ???
  • ?????????? ??
  • Internet Explorer 5.5 ??? ??-???
  • .NET Framework
  • ??????????? ?? ????????? ?? ?????????? ?????? ??
    ????????? ??????? ? ????? ?????? ????????
  • ??????????? ???? ?? ?? ?????? ?????

108
??????? ?? ???????? ??????
lthtmlgt ltscriptgt function ChangeText()
clockControl.Hour hour.value
clockControl.Minute minute.value
lt/scriptgt ltbodygt ltpgtClock Control in
IElt/pgt ltobject id"clockControl"
classid"httpDemo-18-CustomControl-Clock.exeDemo
_18_CustomControl_Clock.ClockControl"
width"200" height"200"gt ltparam
name"Hour" value"14"gt ltparam
name"Minute" value"35"gt lt/objectgt (????????
??????????)
109
??????? ?? ???????? ??????
ltbrgt ltbrgt Hourltinput type"text"
id"hour"gtltbrgt Minuteltinput type"text"
id"minute"gtltbrgt ltinput type"button"
value"Update the clock"
onclick"ChangeText()"gt lt/bodygt lt/htmlgt
110
???????????? 19
  • ??????? ?? ???????? ? IE

111
????? ? Windows Forms
  • ? Windows Forms ???????????? ???????????????
    ???????? ?????? ?? ?? ?????????? ? ??????? ?????
  • ? ???????? ?????? ?? ???????? "?????????" ??
    ?????????????? ?????????
  • ???????????? ?? ?????????????? ????????? ??????
    ?? ????? ???? ?? ???????, ? ????? ?????? ????????
  • ?????? ?? ??????????? Windows Forms ???????? ??
    ?????, ????? ?? ?? ?????????
  • ?? ????? ????? ???? ?? ?? ???????? ???? ????????
    Invoke(), BeginInvoke(), EndInvoke() ?
    CreateGraphics()

112
????? ? Windows Forms
  • ??????????? Invoke() ?????? ?? ????? Control ??
    ?????????? ?? ?????? ?? ???????, ????? ?????????
    ??????????

delegate void StringParamDelegate(string
aValue) class Form1 System.Windows.Forms.Form
private void UpdateUI(string aValue)
// Update UI here void
AsynchronousCalculation() // This
runs in separate thread. Invoke UI update
this.Invoke(new StringParamDelegate(UpdateUI),
new object"??????? ?????????")

113
???????????? 20
  • ?????????? ?? ????? ? Windows Forms ??????????

114
??????? (Drag and Drop)
  • ? ??????????-????????
  • ? ????????? MouseDown ?????? DoDragDrop() ?? ??
    ???????? ???????
  • ? ??????????-?????????
  • ???????? AllowDrop true
  • ?????????? ????????? DragEnter
  • ??????????? ??????? ?? ???????? ????? ?
    ??????????? / ??????????? ????????????
  • DragEventArgs.Data.GetDataPresent()
  • ?????????? ????????? DragDrop
  • ??????????? ?????????? ?????
  • DragEventArgs.Data.GetData ()

115
??????? ??????
private System.Windows.Forms.ListBox
listBoxSource private System.Windows.Forms.ListBo
x listBoxTarget private void listBoxSource_Mouse
Down(object sender, System.Windows.Forms.Mouse
EventArgs e) Point mousePos new
Point(e.X, e.Y) int selectedIndex
listBoxSource.IndexFromPoint(mousePos) if
(selectedIndex ! -1) string data
(string) listBoxSource.ItemsselectedI
ndex listBoxSource.DoDragDrop(data,
DragDropEffects.Copy) (????????
??????????)
116
??????? ??????
private void listBoxTarget_DragEnter(object
sender, System.Windows.Forms.DragEventArgs
e) if (e.Data.GetDataPresent(
DataFormats.UnicodeText)) e.Effect
DragDropEffects.Copy private void
listBoxTarget_DragDrop(object sender,
System.Windows.Forms.DragEventArgs e)
string data (string) e.Data.GetData(
DataFormats.UnicodeText) listBoxTarget.Items.
Add(data)
117
???????????? 21
  • ??????? ? ??????? ? Windows Forms

118
??????????????? ????
  • .NET Framework ???????????? ????? ?? ?????????
    ??????????????? ???? ?? ?? ????? ??????????? ??
  • ?? VS.NET ????? ?? ??????? ??????????????? ????
  • File Add New Item Application configuration
    file App.config
  • ??? ??????????? App.config ?? ?????? ??? ???
    lt???_??_???????.exe.configgt
  • ?? ????? ?? ?????????? ??????????? ??
    ???????????????? ???? ????? ?? ????? ?????????

119
??????????????? ???? ??????
  • ???????? ??????????????? ????
  • ????????? ?? ????????

string username System.Configuration.
ConfigurationSettings.AppSettings"username" //
username "??? ????"
120
???????????? 22
  • ????????? ?? ????????? ?? ??????????????? ????

121
Windows Forms
????????
122
??????????

123
?????????? ??????????
  • MSDN Library http//msdn.microsoft.com
  • Marj Rempel, Kenneth S. Lind, Marjorie Rempel,
    MCAD/MCSD Visual C .NET Certification All-in-One
    Exam Guide, McGraw-Hill, 2002, ISBN 0072224436
  • Threading in Windows Forms http//www.yoda.arach
    sys.com/csharp/threads/winforms.shtml
Write a Comment
User Comments (0)
About PowerShow.com