Programming Microsoft Windows Forms

Similar documents
초보자를 위한 C# 21일 완성

초보자를 위한 ASP.NET 21일 완성

초보자를 위한 한글 Visual Basic .NET 21일 완성

초보자를 위한 C++

초보자를 위한 C++

( )박용주97.PDF

歯PLSQL10.PDF

초보자를 위한 자바 2 21일 완성 - 최신개정판

Java 프로그래머를 위한 C# 비교 활용

Beginning Linux Programming 제3판

hwp

초보자를 위한 ASP.NET 2.0

SRC PLUS 제어기 MANUAL

Dialog Box 실행파일을 Web에 포함시키는 방법

13 2 ( 25 ) Korean J Med Hist Dec 2004 ISSN X * ( ) ( ) ( ). 1) ( ) ( ) ( ) ( ) ( ) 2) ( ) 3) 1990 ( ) 4) * 1) ( ) C

Windows 시스템 프로그래밍 제3판

중 국 6 대 패 션 시 장 조 사 보 고 서 < 2004 년 상 해 10 대 매 장 10대 패 션 제 품 의 브 랜 드 시 장 점 유 뮬 > 제 품 브 랜 드 시 장 점 유 율 제 품 브 랜 드 시 장 점유 율 C O N C H P LA Y B O Y

Interstage5 SOAP서비스 설정 가이드

DV690-N_KOR_ indd

3ÆÄÆ®-14

334 退 溪 學 과 儒 敎 文 化 第 55 號 角 說 에서는 뿔이 난 말과 고양이라는 기형의 동물을 소재로 하여 당대 정치 상 황을 비판하였고, 白 黑 難 에서는 선과 악을 상징하는 색깔인 白 과 黑 이 서로 벌이 는 문답을 통하여 옳고 그름의 가치관이 전도된 현실세

C#과 .NET 플랫폼 - 정식버전판

PCServerMgmt7

초보자를 위한 ADO 21일 완성

歯FFF01379.PDF

(Microsoft PowerPoint - C#\260\355\261\3363\(WinForm\).ppt)


歯Img_man_kr.PDF


Bchvvhv[vhvvhvvhchvvhvvhvvhvvhvvgvvgvv}vvvgvvhvvhvvvhvvhvvhvvvbbhvvhvvvgvvgvvhvvhvvhv}hv,.. Bchvvhv[vhvvhvvhvvhvvbbhvvhvvhvvvhvvhvvgvvgvv}vvgvvhvvvhvv

thesis

Ext JS À¥¾ÖÇø®ÄÉÀ̼ǰ³¹ß-³¹Àå.PDF

歯IC-706.PDF

3ÆÄÆ®-11

A 0 D5-a (XQD Card Type) D5-b (CF Card Type)

Microsoft SQL Server 2005 포켓 컨설턴트 관리자용

A 001~A 036

윈도우 자동실행 설정 방법.PDF

MPLAB C18 C

02 C h a p t e r Java

C# Programming Guide - Types

歯320.PDF

PowerPoint 프레젠테이션

05Àå

µµ≈•∏‡∆Æ1

1. 화섬산업의 개요 1.1 화섬산업의 륵성 화 섬산 업 의 산 업 적 특 성 화섬산업은 원사,원면 둥 기초소재를 생산하는 섬유산 업의 핵심산업으로 고용창출효과와 고부가가치를 실현할 수 있음 O 세계적으로 독일,이태리,일본 등 선진국을 중심으로 M E(마이크로 일렉트

E PA T e c h n o l o g y In n ov a t io n S t r a t e g y E PA E n v ir o n m e n t a l T e c h n o lo g y In it ia t iv e ( ET I)

歯5)논단2.PDF

1

Analytics > Log & Crash Search > Unity ios SDK [Deprecated] Log & Crash Unity ios SDK. TOAST SDK. Log & Crash Unity SDK Log & Crash Search. Log & Cras

untitled

...? 2 Carryover Data. 2 GB / $35 Safety Mode Safety Mode,. 3 4 GB / $50 : $20/ 4 : $10/ : $5/ : 8 GB / $70 16 GB / $ ; 6 XL,, Verizon X

PowerPoint

,,,,,, (41) ( e f f e c t ), ( c u r r e n t ) ( p o t e n t i a l difference),, ( r e s i s t a n c e ) 2,,,,,,,, (41), (42) (42) ( 41) (Ohm s law),

untitled

9

1. 2., $20/ 1 $10/ $5/ GB Verizon Cloud 4? ; 2 1 GB $15 ( GB ). 1 $ Wi-Fi (, ) 4, GB verizonwireless.com/korean 1

비긴쿡-자바 00앞부속

Windows Embedded Compact 2013 [그림 1]은 Windows CE 로 알려진 Microsoft의 Windows Embedded Compact OS의 history를 보여주고 있다. [표 1] 은 각 Windows CE 버전들의 주요 특징들을 담고

untitled

소프트웨어 개발의 성공 열쇠 - 오브젝트 디자인


untitled

百 눼신 시 " 가.인도의 대표적 섬유,패션 제품 l) 카펫 면과 비단으로 만든 카펫은 수세기 동안 인기있는 수출 품옥이었다.무굴시대의 디 자인 감각으로 완성된 플러시 비단카펫은 오늘날까지 관광객에게 많은 사랑을 받는 제품이다.인도산 수직 매듭 양탄자 두리(Dur ie

PBR200114_01.PDF

DocsPin_Korean.pages

Contents Contents 2 1 Abstract 3 2 Infer Checkers Eradicate Infer....

I 154

???짚?

NSK-Ç¥Áö_º»»ç

표지목차.hwp

istay

untitled

untitled

MasoJava4_Dongbin.PDF

5장.key

歯목차88.PDF

02_3 지리산권 스마트폰 기반 3D 지도서비스_과업지시서.hwp

°ø±â¾Ð±â±â

CD-RW_Advanced.PDF

untitled

Mobile Service > IAP > Android SDK [ ] IAP SDK TOAST SDK. IAP SDK. Android Studio IDE Android SDK Version (API Level 10). Name Reference V

ilist.add(new Integer(1))과 같이 사용하지 않고 ilist.add(1)과 같이 사용한 것은 자바 5.0에 추가된 기본 자료형과 해당 객체 자료 형과의 오토박싱/언박싱 기능을 사용한 것으로 오토박싱이란 자바 컴파일러가 객체를 요구하는 곳에 기본 자료형

DE1-SoC Board

ELECTRICAL PARTS LIST (CA-6215) Ref No. Part No. Description Value Qty AMP B'D ( B ) C1406 C CAP NPP POLY 152J 2J 152P 2 C140

수탁연구01-09(수요자 중심1).hwp

<%DOC NAME%> (User Manual)

chap10.PDF

<C0CCBCBCBFB52DC1A4B4EBBFF82DBCAEBBE7B3EDB9AE2D D382E687770>

iii. Design Tab 을 Click 하여 WindowBuilder 가자동으로생성한 GUI 프로그래밍환경을확인한다.

01-OOPConcepts(2).PDF

T100MD+

3장

歯MDI.PDF

09-interface.key

!K_InDesginCS_NFH

IDA 5.x Manual hwp

PRO1_01E [읽기 전용]

(Microsoft PowerPoint - hci2-lecture1.ppt [\310\243\310\257 \270\360\265\345])

Copyright 2012, Oracle and/or its affiliates. All rights reserved.,.,,,,,,,,,,,,.,...,. U.S. GOVERNMENT END USERS. Oracle programs, including any oper

Transcription:

Chapter 1

Chapter 1 2 3 Microsoft.NET Microsoft Windows..NET Windows Forms. Windows Forms Windows, Windows. (.EXE). (.DLL) (, ). Windows Forms C n a t iv e Windows 32 (Win32 API) MFC(Microsoft Foundation Classes) C+ + Windows. Windows Forms.NET Framework DLL..NET Framework Windows Forms Windows Forms,..NET Framework Microsoft (http :/ / msdn. microsoft.com/ netframework/ downloads/ updates). 2005.NET Framework 2.0. Windows Forms Windows, Win32 MFC. Windows Forms. MSIL(Microsoft Intermediate Languages ; Microsoft ). ( MSIL ). CLR(Common Language Runtime ; ).NET Framework.NET.

2 4 PROGRAMMING MICROSOFT WINDOWS FORMS.NET..,.NET Windows Forms. Windows Forms. m a n a ge d cod e. s t r on g..net CLR g a r b a g e colle ct ion., CLR.. Windows Forms Win32 API..NET Windows Forms. fie ld m e t h od p r op e r t y ev e n t ( ).. (,, ).. 0,,., Windows Forms.NET CLS(Common Language Specification ; )., C+ + Microsoft Managed Extensions. C+ +.NET..NET C# Microsoft Visual Basic.NET. C#( ) C C+ +, CLS..NET

Chapter 1 2 5. C#. C C+ + C#. Programming in the Key of C#(Microsoft Press, 2003),. L a n gu a ge C# C# C# S p e cifica t ion. Microsoft C# (http :/ / msdn.micro soft.com/ library/ en-us/ cscon/ html/ vcoricstartpage.asp) Anders Hejlsberg, Scott Wiltamuth, Peter Golde The C# Programming Language 1) (Addison-Wesley, 2003). C# Programmer's Reference( C# ). C#,.NET..NET., C# Visual Basic.NET. Microsoft CLS J # J Script. (Microsoft ) J 2). Windows Forms Microsoft Visual Studio.. Visual Studio 2005.NET 2.0 Visual Studio 1) : C# : The C# Programming Language 2) : Java.

2 6 PROGRAMMING MICROSOFT WINDOWS FORMS. Microsoft Visual C# Visual Basic.NET Express. Visual Studio. Visual Studio,.NET. Visual Studio, Visual Studio Windows Forms.,. (Windows ) Windows Forms, MS-DOS.,.NET Framework SDK(Software Development Kit). SDK csc(c# ) vbc(visual Basic.NET ). ( ). Microsoft C#.NET, Visual Studio C#. (http :/ / www.charlespetzold. com/ keycs) Key of C# IDE. Key of C#.NET Framework,.NET Framework SDK..NET Framework.NET Framework SDK Visual Studio.NET (Key of C#, ). Visual Studio., Microsoft IntelliSense,..

Chapter 1 2 7 Visual Studio.NET Framework SDK,.NET Framework. MSDN(Microsoft Development Network) (http :/ / msdn.microsoft.com/ library)..net.. Contents.NET Framework Class Library., namespace. Microsoft, n a m e s p a ce System..NET Framework..,.,.NET Framework Timer,. t h ir d- p a r t y DLL Timer..NET,.NET System. s t a ck, q u e u e, h a s h t a b le System.Collections System.Collections.Generic. System.IO. System.Data System.Xml XML. Windows Forms System.Windows.Forms, System.Drawing.

2 8 PROGRAMMING MICROSOFT WINDOWS FORMS.NET,,. e n t it y. C#. class.,. r e fe r e n ce struct..net t y p e v a lu e t y p e... interface...,.. delegate. d e le g a t e p r ot ot yp e.. enum. e n u m e r a t ion. ( ),.,,...NET Windows Forms.?

Chapter 1 2 9 con s ole.net..net. Console Write WriteLine, System Console (WriteLine ca r r ia ge r e t u r n Write ). Console Read ReadLine, ReadKey (.NET 2.0 ). s t a t ic. Console ( Console). Hello, world. FirstConsole Program.cs / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Fi r st Consol e Progr am. c s ( c) 200 5 by Cha r l e s Pet zol d / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cl a s s Fi r st Consol e Pr og r am publ i c st at i c voi d Mai n ( ) Sy st em. Consol e.wr i t e Li ne ( " He l l o. NET Consol e " ) ;, FirstConsoleProgram.cs. (.cs) C Sharp. FirstConsoleProgram. C#, ( ). C# ( ), C# 2.0 partial.

30 PROGRAMMING MICROSOFT WINDOWS FORMS C# Main. C C+ +. C#, Main M. Main. Main. publ i c st at i c i nt Mai n ( st r i ng [] a r gs ) Main static., Main FirstConsoleProgram. Main. Fi r st Consol e Pr og r am. Ma i n () Main System.Console.WriteLine., fu ll q u a lifie d. System.Console.WriteLine System, using. SecondConsole Program.cs / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Se condconsol e Progr am. c s (c ) 200 5 by Cha r l e s Pet zol d / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - us i ng Syst em; cl a s s SecondConsol e Pr og r am publ i c st at i c voi d Ma i n () Consol e. Wr i t e Li ne ( "Hel l o agai n,. NET Consol e " ) ;

Chapter 1 3 1 using. (, System.Threading System.Thread using, Timer ),. C# csc.exe. Key of C#. Visual Studio, Visual Studio. Vis ua l St ud io Visual Studio. Windows Forms,... C# Visual Basic.NET. Visual Studio.csproj (C# ).vbproj (Visual Basic.NET ) XML. Visual Studio ( ).., Visual Studio., C# DLL Visual Basic.NET C+ +.NET ( Visual Studio Visual C#, C# ).

32 PROGRAMMING MICROSOFT WINDOWS FORMS DLL. Visual Studio.sln. Visual Studio.. Visual Studio, Visual C# Windows (Visual C# ). Visual Studio ( ),.. Visual Studio. Visual Studio (.sln)., ch e ck b ox., Visual Studio. (Visual C# ).... C#.. Visual Studio, C#., Console Console. ( ) WriteLine. Visual Studio IntelliSense. Microsoft (, C#, IntelliSense IntelliSense ).

Chapter 1 3 3, F6. ( ). (F5) (Ctrl + F5)., Visual Studio. ( ), Visual Studio... Visual Studio, Visual Studio ConsoleApplication 1. Program.cs us i ng Sy st em; us i ng Sy st em. Col l e ct i ons. Gene r i c ; us i ng Sy st em.text ; name spac e Consol eappl i cat i on1 c l a s s Pr og r am st at i c voi d Mai n ( st r i ng [] a r gs) Visual Studio using.., (DLL ).

34 PROGRAMMING MICROSOFT WINDOWS FORMS Visual Studio, ( ).. Program.cs.,.NET C#. DLL. System Console, Console ReadLine? C# Console..NET DLL DLL m e t a d a t a (.NET System.Reflection ). Console MSDN a s s e m b ly. Console mscorlib (mscorlib.dll). Mscorlib Microsoft Common Object Runtime Library, Multilanguage Standard Common Object Runtime Library. Windows Forms DLL., System.Windows.Forms System.

Chapter 1 35 Windows.Forms. System. Windows.Forms.dll. C# DLL. DLL r e fe r e n ce s. Visual Studio. Visual Studio C#. Visual Studio DLL. Visual Studio IntelliSense. IntelliSense DLL. W ind ow s Windows Forms. FirstWinFormsProgram...NET. Windows Forms System System.Drawing, System.Windows.Forms. ( ), System.Data System.Xml. Ctrl., IntelliSense., IntelliSense using. FirstWinFormsProgram FirstWinFormsProgram.cs.

36 PROGRAMMING MICROSOFT WINDOWS FORMS FirstWinForms Program.cs / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Fi r st Wi nfo rms Progr am. c s (c ) 200 5 by Cha r l e s Pet zol d / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - us i ng Syst em. Wi ndows. Fo rms ; cl a s s Fi r st Wi nfo r ms Pr og r am publ i c st at i c voi d Ma i n () Appl i c at i on. Run ( new Fo r m( ) ) ; using. Application Form, System.Windows.Forms. using,.. using. using,. System.Windows.Forms.Application System.Windows.Forms.Form.. 3), System.Drawing.dll Windows Forms System.Drawing System.Drawing.Drawing2D, System.Drawing.Imaging, System.Drawing.Printing., Ctrl + F5.. 3) :.

Chapter 1 3 7,,,, (. ). new Fo rm() Form. Form Windows Forms. Form Application Run. Windows. Windows, Windows. Application.Run Form., Application.Run, Main. Application.Run Application.Run Console.WriteLine (Console System using ). Windows..

38 PROGRAMMING MICROSOFT WINDOWS FORMS Windows Forms, Windows Forms, Console.WriteLine. Windows Forms... Ctrl+ C,. Windows Forms.., Visual Studio ( t arget ).. Windows. Windows Forms Windows,.. 4) Windows ( )-Windows Application.Run. FirstWinFormsProgram. Application.Run Form.,. 4) :.

Chapter 1 39 Form,. Application.Run. FormProperties.cs / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Fo r mprope rt i e s. c s (c ) 200 5 by Cha r l e s Pet zol d / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - us i ng Sy st em; us i ng Sy st em. Dr awi ng ; us i ng Sy st em.wi ndows. Fo r ms ; cl a s s Fo rmpr ope r t i e s publ i c st at i c voi d Mai n ( ) Fo rm f rm = new Fo rm() ; f r m. Text = "My Wi nfo r ms Progr am" ; f r m. Wi dt h *= 2 ; Appl i c at i on. Run ( f r m) ; Text Width Form...,. Text Width. 5)? Text Width,.NET Framework.., s m a r t. Text. Width. Form Width.. 5) : public.

4 0 PROGRAMMING MICROSOFT WINDOWS FORMS, Form get set (, get_width set_width).. f r m. set _wi dt h ( 2 * f rm. get _wi dt h () ) ;. J #.. Visual Studio. ( ). Form.NET Framework Text Width. Form Control. Form Form..,.NET..,

Chapter 1 4 1 callback. ev e n t h a n d le r...,,,.. Control Form., Control ( ) Click (Form ). Control Click. publ i c eve nt Event Handl e r Cl i c k ; event C#. Click EventHandler. EventHandler (C# delegate), System. publ i c del egat e voi d Event Handl e r (obj ect se nde r, Eve nt Ar gs e ) ;, Click.,.. voi d MyCl i c ke r (obj ect obj Sr c, Eve nt Ar gs a r gs)... 1), 2), 3) 4)..

4 2 PROGRAMMING MICROSOFT WINDOWS FORMS f r m. Cl i c k += new Event Handl e r (MyCl i c ke r ) ; (compound assignment operator). - = ( ). C# 2.0,. f r m. Cl i c k += MyCl i c ke r ; MyClicker EventHandler., Form Click, MyClicker. MyClicker obj Src. Form. Form. Fo rm f r m = ( Fo r m) obj Sr c ; Fo rm f r m = obj s r c a s Fo r m; Form. EventArgs. Click (MouseDown MouseHover ). Paint. ( ). Paint. Paint,. Paint Paint.

Chapter 1 4 3 Paint Control. publ i c eve nt Pa i nt Eve nt Ha ndl e r Pa i nt ; PaintEventHandler System.Windows.Forms. publ i c del egat e voi d Pai nt Event Handl e r (obj ect sende r, Pai nt Event Args e) ; Paint EventArgs PaintEventArgs. voi d MyPai nt e r (obj ect obj Sr c, Pai nt Event Ar gs a r gs )... PaintEventHandler. f r m. Pa i nt += new Pa i nt Eve nt Ha ndl e r (My Pa i nt e r ) ; f r m. Pa i nt += My Pa i nt e r ; PaintEventArgs System.Windows.Forms. EventArgs, Graphics ClipRetangle. Graphics Graphics. ClipRectangle Graphics. Click Paint. Click, Paint.

4 4 PROGRAMMING MICROSOFT WINDOWS FORMS FormEvents.cs / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Fo rmevent s. c s (c ) 200 5 by Cha r l e s Pet zol d / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - us i ng Syst em; us i ng Syst em. Dr awi ng ; us i ng Syst em. Wi ndows. Fo rms ; cl a s s Fo r meve nt s publ i c st at i c voi d Ma i n () Fo r m f r m = new Fo r m( ) ; f rm.text = "My Eve nt s Pr og r am" ; f rm.wi dt h *= 2 ; f rm. Cl i c k += MyCl i c ke r ; f rm. Pai nt += MyPai nt e r ; Appl i cat i on. Run (f rm) ; st at i c voi d MyCl i c ke r (obj e ct obj Sr c, Event Ar gs a r gs ) Me s sa ge Box. Show( "The f o rm ha s be en c l i c ked!", "Cl i c k" ) ; st at i c voi d My Pa i nt e r (obj e ct obj Sr c, Pa i nt Eve nt Ar gs a r gs) Fo r m f r m = ( Fo rm) obj Sr c ; Gr a phi c s gr f x = a r gs. Gr a phi c s ; g r f x. Dr awst r i ng ( " He l l o, Wi ndows Fo rms ", f r m. Font, Syst embr ushe s. Cont r ol Text, 0, 0) ; st atic. FormEvent s,. FormEvent, public.. MyPainter Graphics DrawString., ( ), x y. x y.

Chapter 1 4 5 MyPainter, Form Font., MyPainter obj Src Form, Font. Form Main. Form Form Form. Form,. Form. cl as s MyFo rm: Form... Main Application.Run. Main. cl a s s My Pr og r am publ i c st at i c voi d Mai n ( ) Appl i c at i on. Run ( new My Fo rm() ) ;

4 6 PROGRAMMING MICROSOFT WINDOWS FORMS MyForm Form, Form public protected,,.,. cl as s MyForm: Form publ i c MyFo r m( ) Text = "My I nhe r i t e d Fo r m" ; Wi dt h *= 2 ; C#.. MyForm.. Main MyForm., this C#. t hi s.text = My I nhe r i t e d Fo r m; Visual Studio this (.) IntelliSense.. MyForm. cl as s MyForm: Form publ i c MyFo r m( ) Text = "My I nhe r i t e d Fo r m" ; Wi dt h *= 2 ; Cl i c k += MyCl i c ke r ; Pa i nt += My Pa i nt e r ; voi d MyCl i c ke r (obj ect obj Sr c, Eve nt Ar gs a r gs)

Chapter 1 4 7 Me s s agebox. Show( "The but t on ha s bee n cl i c ked!", "Cl i c k") ; voi d MyPai nt e r (obj ect obj Sr c, Pa i nt Eve nt Ar gs a r gs ) Gr aphi c s g r f x = a r gs. Gr aphi c s ; gr f x. Dr awst r i ng ( "Hel l o, Wi ndows Fo r ms ", Font, Syst embr ushe s. Cont r ol Text, 0, 0) ; Form. Control ( Form ),. On., OnPaint (Paint ) OnClick (Click )., ( this ). virtual. Control Form override. Control v ir t u a l protected ov e r r id e protected. cl as s MyFo rm: Form publ i c MyFo r m( ) Text = " " ; Wi dt h *= 2 ; p rot e ct ed ove r r i de voi d OnCl i c k( Event Ar gs a r gs) Me s s agebox. Show( "The but t on ha s bee n cl i c ke d!", "Cl i c k") ; p rot e ct ed ove r r i de voi d OnPa i nt ( Pa i nt Eve nt Ar gs a r gs ) Gr aphi c s g r f x = a r gs. Gr aphi c s ; gr f x. Dr awst r i ng ( "Hel l o, Wi ndows Fo r ms ", Font, Syst embr ushe s. Cont r ol Text, 0, 0) ; MyProgram, MyForm Main. Form Main

4 8 PROGRAMMING MICROSOFT WINDOWS FORMS Main. cl as s MyForm: Form publ i c st at i c voi d Ma i n () Appl i c at i on. Run ( new MyFo r m( ) ) ; Main MyForm MyForm. Main static MyForm.. InheritFromForm.cs / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / I nhe r i t FromFo r m. c s ( c) 200 5 by Cha r l e s Pet zol d / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - us i ng Syst em; us i ng Syst em. Dr awi ng ; us i ng Syst em. Wi ndows. Fo rms ; cl a s s I nhe r i t Fr omfo rm: Fo rm publ i c st at i c voi d Ma i n () Appl i c at i on. Run ( new I nhe r i t Fr omfo rm() ) ; publ i c I nhe r i t Fr omfo rm() Text = "I nhe r i t f rom Fo r m" ; Wi dt h *= 2 ; pr ot ect e d ove r r i de voi d OnCl i c k ( Eve nt Ar gs a r gs) Me s s agebox. Show( "The f o rm ha s bee n c l i c ked!", "Cl i c k") ; pr ot ect e d ove r r i de voi d OnPai nt ( Pai nt Event Ar gs a r gs ) Gr aphi c s gr f x = a r gs. Gr aphi c s ; gr f x. Dr awst r i ng ( "Hel l o, Wi ndows Fo r ms ", Font, Syst embr ushe s. Cont r ol Text, 0, 0) ;

Chapter 1 4 9 : Control OnClick OnPaint Click Paint. Click Paint, InheritFromForm, InheritFromForm Click Paint. InheritFrom Form( InheritFromForm ) Click Paint., OnClick OnPaint. ba se. OnPai nt (a r gs) ; Vis ua l St ud io Windows Visual Studio. Visual Studio.. Visual Studio Program.cs ( WindowsApplication) Program Main. Program.cs us i ng Sy st em; us i ng Sy st em. Col l e ct i ons. Gene r i c ; us i ng Sy st em.wi ndows. Fo r ms ; name spac e Wi ndowsappl i cat i on1 st at i c c l a s s Progr am / / / <summa r y> / / /.

5 0 PROGRAMMING MICROSOFT WINDOWS FORMS / / / </ s umma ry> [STAThr ea d] st at i c voi d Ma i n () Appl i c at i on. Enabl evi sual St yl e s () ; Appl i c at i on. Set Compat i bl etext Rende r i ngde f a ul t ( f a l s e) ; Appl i c at i on. Run ( new Fo rm1( ) ) ; Main XML... XML. Main STAThread a t t r ib u t e..net STA(Single-Threaded Apartment : - ). STA COM (Common Object Module) ( System STAThreadAttribute )., Windows Forms,. STAThread. Application EnableVisualStyles ( ). FlatStyle.,. Form1 Form1.cs. Form1.cs us i ng Syst em; us i ng Syst em. Col l ect i ons. Ge ne r i c ; us i ng Syst em. Component Model ;

Chapter 1 5 1 us i ng Sy st em. Dat a ; us i ng Sy st em. Dr awi ng ; us i ng Sy st em.wi ndows. Fo r ms ; name spac e Wi ndowsappl i cat i on1 pa r t i al cl a s s Fo rm1 : Fo r m publ i c Fo r m1 () I ni t i al i z ecomponent () ; Form1 Form. partial.. InitializeComponent Form1, Form1.Designer.cs. Form1.Des igner.cs name spac e Wi ndowsappl i cat i on1 pa r t i al cl a s s Fo rm1 / / / <s umma ry> / / / Requi r ed de si gne r va r i a bl e. / / / </ summa r y> pr i vat e Sy st em. Component Mode l. I Cont a i ne r component s = nul l ; / / / <s umma ry> / / / Cl ea n up any r e sour ce s bei ng use d. / / / </ summa r y> / / / <pa r am name=" di spos i ng">t r ue i f managed r e sour ce s shoul d be di s po se d ; / / / ot he rwi s e, f a l s e. </ pa r am> pr ot ect e d ove r r i de voi d Di s po se (bool di spos i ng) i f (di s po si ng && ( component s!= nul l ) ) compone nt s. Di spos e ( ) ; ba s e. Di spos e ( di spos i ng) ; # r egi on Wi ndows Fo r m De si gne r gene r at ed code / / / <s umma ry> / / / Requi r ed met hod f o r De s i gne r s uppo rt - do not modi f y

5 2 PROGRAMMING MICROSOFT WINDOWS FORMS / / / t he cont e nt s of t hi s met hod wi t h t he code e di t o r. / / / </ s umma ry> pr i vat e voi d I ni t i a l i zecomponent ( ) t hi s. component s = new Sy st em. Compone nt Mode l. Cont ai ne r ( ) ; t hi s. Aut osc al emode = Syst em. Wi ndows. Fo rms. Aut osc al emode. Font ; t hi s. Text = " Fo r m1" ; #e nd r e gi on component s Visual Studio boilerplate. Container Component. Windows Windows Forms Control Component. Component. Container. Visual Studio,., ( )., Width Height Size.. Visual Studio Form1.Designer.cs. t hi s. Cl i ent Si z e = new Syst em. Dr awi ng. Si ze ( 565, 266) ;. Windows Forms. ( ).

Chapter 1 5 3. Windows Forms b u t t on, e d it fie ld, lis t b ox, s cr oll b a r, (.NET 2.0 Windows Forms ). p a n e l s p lit t e r. 3. Control,,. Parent Control.. ( Form ).,. Visible false. Enabled. false d u ll- color. Button p u s h. Button, Click., Visual Studio, C#. FormWithButton.cs / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Fo r mwi t hbut t on. c s (c ) 200 5 by Cha r l e s Pet zol d / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - us i ng Sy st em; us i ng Sy st em. Dr awi ng ; us i ng Sy st em.wi ndows. Fo r ms ; cl a s s Fo rmwi t hbut t on : Fo r m

5 4 PROGRAMMING MICROSOFT WINDOWS FORMS [STATh r e ad] publ i c st at i c voi d Ma i n () Appl i c at i on. Enabl evi sual St yl e s () ; Appl i c at i on. Run ( new Fo r mwi t hbut t on ( ) ) ; publ i c Fo r mwi t hbut t on ( ) Text = " Fo r m wi t h But t on" ; But t on bt n = new But t on ( ) ; bt n. Pa r e nt = t hi s ; bt n. Text = "Cl i c k me!" ; bt n. Locat i on = new Poi nt ( 50, 2 5) ; bt n. Aut osi ze = t r ue ; bt n. Cl i c k += But t ononcl i c k ; voi d But t ononcl i c k (obj ect obj Sr c, Eve nt Ar gs a r gs) Me s s agebox. Show( "The but t on wa s c l i c ked!", " But t on") ; Button, Parent this (Form ). Text. Location 50, 25. AutoSize true,., ButtonOnClick Click. Control Button. AutoSize.

Chapter 1 5 5 Button, Button. But t on bt n = (But t on) obj Sr c ; But t on bt n = obj Sr c a s But t on ; Click.. Text,.. Name. Name. Tag. Tag. Tag, Tag.., CheckBox Click. t ogg le., Boolean Checked.

5 6 PROGRAMMING MICROSOFT WINDOWS FORMS,.,. Control.,. But t on bt ncance l ;. bt ncance l = new But t on ( ) ;.... But t on bt ncance l = new But t on ( ) ; C#.,.., Visual Studio. Visual Studio. Visual Studio Windows,. Visual Studio Button private Form1. pr i vat e Syst em. Wi ndows. Fo rms. But t on but t on1 ; Button ( ). t hi s. but t on1 = new Sy st em.wi ndows. Fo r ms. But t on ( ) ; t hi s. but t on1. Loc at i on = new Syst em. Dr awi ng. Poi nt ( 92, 55) ;

Chapter 1 5 7 t hi s. but t on1. Name = " but t on1" ; t hi s. but t on1. Si z e = new Syst em. Dr awi ng. Si ze ( 104, 47) ; t hi s. but t on1.tabi ndex = 0 ; t hi s. but t on1.text = " but t on1" ; t hi s. Cont r ol s. Add (t hi s. but t on1) ;. Visual Studio ( ). Visual Studio Parent Form.. t hi s. Cont r ol s. Add (t hi s. but t on1) ; Controls Form ( Form Control ). Controls Control.ControlCollection., ControlCollection Control. public Control. ControlCollection ICollection IEnumerable, IList.. Control Controls. Form Controls Parent Form. Parent null. ( ) Controls. Name Control Control.ControlCollection Find..? Z z-order ( 3. Z x y ). Z Controls., Parent.

5 8 PROGRAMMING MICROSOFT WINDOWS FORMS, Z. BringToTop SendToBack Z. Visual Studio, Visual Studio TabIndex 0. TabIndex. Visual Studio Visual Studio. TabIndex 0 ( ), Z,. Visual Studio,.,. Visual Studio SuspendLayout ResumeLayout., (, Layout ). Windows Forms Form.. Tag.. MessageButton.. Text

Chapter 1 5 9.. public. cl a s s Me s s agebut t on : But t on publ i c st r i ng Me s s ageboxtext = " " ; OnClick, public MessageButton. Me s s agebut t on mbbt n = new Me s sa ge But t on () ; mbbt n. Me s s ageboxtext = "Text i n t he me s s age box. " ; MessageBoxText public,.net Framework. const.. private public.., Control Text Color,.. MessageBoxText. MessageBoxText,. MessageBoxText Enabled. MessageButton private enabled false, MessageBoxText.

6 0 PROGRAMMING MICROSOFT WINDOWS FORMS MessageButton.cs / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Me s s agebut t on. c s ( c) 200 5 by Cha r l e s Pet zol d / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - us i ng Syst em; us i ng Syst em. Dr awi ng ; us i ng Syst em. Wi ndows. Fo rms ; cl a s s Me s sa ge But t on : But t on st r i ng st r Me s s ageboxtext ; publ i c Me s sa ge But t on () Ena bl ed = f a l s e ; publ i c st r i ng Me s s ageboxtext s et st rme s sa ge BoxText = val ue ; Enabl e d = val ue!= nul l && val ue. Lengt h > 0 ; get r et u r n st rme s sa ge BoxText ; pr ot ect e d ove r r i de voi d OnCl i c k ( Eve nt Ar gs a r gs) Me s sa ge Box. Show(Me s sa ge BoxText, Text ) ; MessageBox. MessageBoxText set get. set value. MessageBoxText string, value string Length. Visual Studio MessageButtonDemo, MessageButton.cs C#. MessageButton, MessageButtonDemo.cs C#..

Chapter 1 6 1 MessageButtonDemo.cs / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Me s sa ge But t ondemo. c s ( c) 200 5 by Cha r l e s Pet zol d / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - us i ng Sy st em; us i ng Sy st em. Dr awi ng ; us i ng Sy st em.wi ndows. Fo r ms ; cl a s s Me s s agebut t ondemo : Fo rm [STAThr ea d] publ i c st at i c voi d Mai n ( ) Appl i cat i on. Ena bl evi s ua l St yl e s ( ) ; Appl i cat i on. Run (new Me s sa ge But t ondemo () ) ; publ i c Me s sa ge But t ondemo () Text = "Me s sa ge But t on Demo " ; Me s sa ge But t on msgbt n = new Me s sa ge But t on () ; msgbt n. Pa r e nt = t hi s ; msgbt n. Text = "Ca l c ul at e 10, 000, 000 di gi t s of PI " ; msgbt n. Me s s ageboxtext = "Thi s but t on i s not yet i mpl eme nt ed!" ; msgbt n. Locat i on = new Poi nt ( 50, 50) ; msgbt n. Aut osi ze = t r ue ; MessageBoxText null. MessageButtonDemo.cs Visual Studio, IntelliSense msgbtn.net. MessageButton., IntelliSense MessageButton ( IntelliSense). t op - d ow n ( b ot t om - u p ) ( Main ). Visual Studio. IntelliSense?.

6 2 PROGRAMMING MICROSOFT WINDOWS FORMS MessageButton,. MessageButton.cs. Visual Studio ( ).. Control Location Size (3 ). Location Point X Y... Size Width Height Size (Point Size System. Drawing ). Windows. 6). 300, 600, 1200 dpi(dot per inch ; ),. 96 dpi, Windows. 19 dpi 480 dpi ( ). 96 dpi 120 dpi. 120 dpi 6) : Windows Windows.

Chapter 1 6 3 25,. 96 dpi 120 dpi. Windows Forms Graphics DpiX DpiY. Windows Forms 8 p oin t. Font SizeInPoints ( 1/ 72. d e s ce n d e r s ( ) d ia cr it ics ). Font Height. Height 13 Height 16. 1/ 2.,. 1 3/ 4. 2 (4 ), 1/ 2.. Device IndependentButton.cs / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Devi c ei ndepende nt But t on. c s ( c) 200 5 by Cha r l e s Pet zol d / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - us i ng Sy st em; us i ng Sy st em. Dr awi ng ; us i ng Sy st em.wi ndows. Fo r ms ; cl a s s Devi ce I nde pe ndent But t on : Fo rm [STAThr ea d] publ i c st at i c voi d Mai n ( ) Appl i cat i on. Ena bl evi s ua l St yl e s ( ) ; Appl i cat i on. Run (new Devi c ei ndepende nt But t on () ) ; publ i c Devi c ei ndepende nt But t on ()

6 4 PROGRAMMING MICROSOFT WINDOWS FORMS Text = " Devi ce - I ndepende nt But t on" ; i nt f nt ht = Font. Hei ght ; Cl i ent Si z e = new Si z e ( f nt ht * 30, f nt ht * 10) ; But t on bt n = new But t on ( ) ; bt n. Pa r ent = t hi s ; bt n.text = " Looki n ' good!" ; bt n. Si z e = new Si z e ( 17 * f nt ht / 2, 7 * f nt ht / 4) ; bt n. Loc at i on = new Poi nt ( (Cl i e nt Si ze.wi dt h - bt n. Wi dt h) / 2, (Cl i ent Si z e. He i ght - bt n. He i ght ) / 2) ; Size 13 4, 1/ 2. 1 3/ 4. 96 dpi. 7) 120 dpi. 7) :, ( ),. (Some confusion things in your source http :/ / smile. egloos. com/ 1181563).

Chapter 1 6 5,. 8) Visual Studio AutoScaleDimensions AutoScaleMode (.NET 1.x AutoScaleBaseSize ). Cont ainercontrol. Control Form. AutoScaleMode AutoScaleMode. AutoScaleMode.Dpi AutoScaleMode.Font, AutoScaleMode.Inherit. AutoScaleMode AutoScaleMode.Font, Form Font AutoScaleDimrensions. Visual Studio, Visual Studio. AutoScaleDimrensions AutoScaleMode. Windows,. t hi s.aut osca l e Di me ns i ons = new Sy st em. Dr awi ng. Si z e F(6F, 13F) ; t hi s.aut osca l emode = Sy st em.wi ndows. Fo r ms.aut osca l emode. Font ; SizeF Size. 6 13 Windows Forms. Windows, Form Form. 8 16. 8/ 6 16/ 13. 8) :,.

6 6 PROGRAMMING MICROSOFT WINDOWS FORMS Windows, Visual Studio. t hi s.aut osca l e Di me ns i ons = new Sy st em. Dr awi ng. Si z e F(8F, 16F) ; t hi s.aut osca l emode = Sy st em.wi ndows. Fo r ms.aut osca l emode. Font ;, Visual Studio. AutoScaleMode AutoScaleMode.Dpi. (96 dpi ), Visual Studio. t hi s.aut osca l e Di me ns i ons = new Sy st em. Dr awi ng. Si z e F(96, 96) ; t hi s.aut osca l emode = Sy st em.wi ndows. Fo r ms.aut osca l emode. Dpi ;. t hi s.aut osca l e Di me ns i ons = new Sy st em. Dr awi ng. Si z e F( 120, 120) ; t hi s.aut osca l emode = Sy st em.wi ndows. Fo r ms.aut osca l emode. Dpi ;,., Windows r e s ou r ce s cr ip t. 1/ 8 1/ 4. 1/ 2,.. Aut osc al edi mensi ons = new Si z e ( 4, 8) ; Aut osc al emode = Aut osca l emode. Font ; 1/ 10,.

Chapter 1 6 7 Aut osc al edi mensi ons = new Si z e ( 10, 10) ; Aut osc al emode = Aut osca l emode. Dpi ; AutoScaleDimensions AutoScaleMode.,,.. DeviceDependentButton. AutoScaleButton.cs / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Aut osca l e But t on. c s ( c) 200 5 by Cha r l e s Pet zol d / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - us i ng Sy st em; us i ng Sy st em. Dr awi ng ; us i ng Sy st em.wi ndows. Fo r ms ; cl a s s Aut osc al ebut t on : Fo rm [STAThr ea d] publ i c st at i c voi d Mai n ( ) Appl i cat i on. Ena bl evi s ua l St yl e s ( ) ; Appl i cat i on. Run (new Aut osca l e But t on () ) ; publ i c Aut osca l e But t on () Text = "Aut o- Sc al e But t on" ; Cl i ent Si z e = new Si z e ( 240, 80) ; But t on bt n = new But t on ( ) ; bt n. Pa r ent = t hi s ; bt n.text = " Loo ki n ' good!" ; bt n. Si z e = new Si z e ( 17 * 4, 14) ; bt n. Loc at i on = new Poi nt ( (Cl i e nt Si ze.wi dt h - bt n.wi dt h) / 2, (Cl i ent Si z e. He i ght - bt n. He i ght ) / 2) ; Aut osca l e Di me ns i ons = new Si ze (4, 8) ; Aut osca l emode = Aut osca l emode. Font ;

6 8 PROGRAMMING MICROSOFT WINDOWS FORMS Visual Studio Windows AssemblyInfo.cs. EXE DLL. Windows., Windows Forms.. Key of C#. [a s s embl y : As sembl yti t l e ( "Key of C# ") ] [a s s embl y : As sembl yde sc r i pt i on ( "Sma l l C# I DE f o r. NET" ) ] [a s s embl y : As sembl ycompany ( "www. c ha r l e s pet zol d. com" ) ] [a s s embl y : As sembl y Pr oduct ( "Key of C# ") ] [a s s embl y : As sembl ycopy r i ght ( " ( c) Cha r l e s Pet zol d, " + Ve r si on. Copy r i ght ) ] [a s s embl y : As sembl yve r s i on (Ve r s i on. Ma j o r + ". " + Ve r si on. Mi no r + ". *" ) ] Key of C#, About Version., Version. (:) assembly., (.EXE.DLL ). System.Reflection using. Reflection., AssemblyTitle AssemblyTitleAttribute. AssemblyVersion... < >.< >.< >.< > (*), C# 2000 1 1, 1/ 2.

Chapter 1 6 9. AssemblyVersion, AssemblyFileVersion AssemblyVersion.,.. (...). 9) m od a l m od e le s s 10)..,.,.. (, )..,. Windows Forms Form. 9) :. 10) : Modeless. KLDP, MSDN. MSDN,.

70 PROGRAMMING MICROSOFT WINDOWS FORMS cl a s s MyDi a l ogbox : Fo rm ShowDialog. MyDi al ogbox dl g = new MyDi al ogbox ( ) ; dl g. ShowDi al og () ; ShowDialog.. ( ). ( ).,. ( ).,. DialogResult DialogResult (DialogResult.OK DialogResult.Cancel). ShowDialog, DialogResult. Click. Click DialogResult. Click. voi d OkBut t ononcl i c k(obj e ct obj Sr c, Eve nt Ar gs a r gs ) Di al ogre sul t = Di a l ogre s ul t. OK;

Chapter 1 7 1. i f ( dl g. ShowDi al og () == Di a l ogre s ul t. OK) Windows Forms Button DialogResult ( Form DialogResult,. Form Button DialogResult., Control ). DialogResult DialogResult, DialogResult ( ).... ModalDialogBox.cs / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Modal Di al ogbox. c s (c ) 200 5 by Cha r l e s Pet zol d / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - us i ng Sy st em; us i ng Sy st em. Dr awi ng ; us i ng Sy st em.wi ndows. Fo r ms ; cl a s s Moda l Di a l ogbox : Fo r m Che c kbox c bgr aysha de s ; publ i c Modal Di al ogbox ( ) Text = "Cha nge Col o r " ; Fo r mbo r de r St yl e = Fo r mbo r de r St yl e. Fi xeddi al og ; Cont r ol Box = f a l s e ; Mi ni mi z ebox = f al se ; Maxi mi z ebox = f al se ; ShowI nta s kba r = f al se ; St a rt Po si t i on = Fo r mst a rt Po si t i on. Manua l ; Loc at i on = Act i ve Fo rm. Loc at i on + Syst emi nf o r mat i on. Capt i onbut t onsi ze + Syst emi nf o r mat i on. Fr ame Bo r de r Si ze ;

72 PROGRAMMING MICROSOFT WINDOWS FORMS Cl i ent Si z e = new Si z e ( 144, 56) ; c bgr aysha de s = new Che c kbox ( ) ; c bgr aysha de s. Pa r e nt = t hi s ; c bgr aysha de s. Text = "Gr ay Shade s Onl y" ; c bgr aysha de s. Locat i on = new Poi nt ( 16, 8) ; c bgr aysha de s. Si ze = new Si ze (80, 12) ; But t on bt n = new But t on ( ) ; bt n. Pa r ent = t hi s ; bt n.text = "OK" ; bt n. Loc at i on = new Poi nt ( 16, 32) ; bt n. Si z e = new Si z e ( 48, 14) ; bt n. Di a l ogre s ul t = Di a l ogre s ul t. OK; Acc ept But t on = bt n ; bt n = new But t on () ; bt n. Pa r ent = t hi s ; bt n.text = "Ca nc el " ; bt n. Loc at i on = new Poi nt (80, 32) ; bt n. Si z e = new Si z e ( 48, 14) ; bt n. Di a l ogre s ul t = Di a l ogre s ul t. Ca nc el ; Cance l But t on = bt n ; Aut oscal e Di me ns i ons = new Si ze (4, 8) ; Aut oscal emode = Aut osc al emode. Font ; publ i c bool Gr ayshade s s et cbgr ayshade s. Che c ked = va l ue ; get ret urn cbgr ayshades. Checked ;.. ( ),. ShowInTaskBar false.

Chapter 1 7 3, Windows.., ActiveForm ( St artposition Location ). Gray Shades Only. DialogResult DialogResult.OK DialogResult.Cancel. AcceptButton CancelButton OK Cancel.. AcceptButton.. ( ). CancelButton Escape. CheckBox public. GrayShades b oole a n.... ModalDialogDemo. ModalDialogDemo ModalDialogBox.cs ModalDialogDemo.cs.

74 PROGRAMMING MICROSOFT WINDOWS FORMS ModalDialogDemo.cs / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Moda l Di a l ogdemo. c s ( c) 200 5 by Cha r l e s Pet zol d / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - us i ng Syst em; us i ng Syst em. Dr awi ng ; us i ng Syst em. Wi ndows. Fo rms ; cl a s s Modal Di al ogdemo : Fo rm [STATh r e ad] publ i c st at i c voi d Ma i n () Appl i cat i on. Ena bl evi s ua l St yl e s ( ) ; Appl i cat i on. Run (new Modal Di al ogdemo () ) ; publ i c Modal Di al ogdemo () Text = "Moda l Di al og Demo" ; But t on bt n = new But t on ( ) ; bt n. Pa r ent = t hi s ; bt n.text = "Change Col o r " ; bt n. Loc at i on = new Poi nt ( 16, 16) ; bt n.aut osi z e = t r ue ; bt n. Cl i c k += But t ononcl i c k ; voi d But t ononcl i c k (obj ect obj Sr c, Eve nt Ar gs a r gs) Modal Di al ogbox dl g = new Modal Di al ogbox ( ) ; i f (dl g. ShowDi a l og ( ) == Di al ogre sul t. OK) Ra ndom r nd = new Random( ) ; i nt i Shade = r nd. Next (2 55) ; i f (dl g. Gr aysha de s) Ba c kcol o r = Col o r. Fr omar gb (i Shade, i Sha de, i Sha de ) ; el se Ba c kcol o r = Col o r. Fr omar gb (i Shade, r nd. Next (2 55), r nd. Next ( 255) ) ; Click.,. Click ModalDialogBox,

Chapter 1 75 ShowDialog., ShowDialog. ShowDialog DialogResult.OK,. Gray Shades Only, ( ). dlg.grayshades,.,. dlg,. ShowDialog... ( )...,. FormBorderStyle FixedDialog MinimizeBox MaximizeBox false, ControlBox true. ControlBox,,.

76 PROGRAMMING MICROSOFT WINDOWS FORMS Owner.. dl g. Owne r = t hi s ; ShowDialog Show., ShowDialog. Show. Show,...,. Change, Change EventHandler.. publ i c event Event Handl e r Cha nge ;., Change.. i f (Cha nge!= nul l ) Change (t hi s, new Eve nt Ar gs () ) ; Change null, Change..

Chapter 1 7 7 ModelessDialogBox ModalDialogBox, Change. Modeless DialogBox.cs / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Model e s sdi a l ogbox. c s ( c) 200 5 by Cha r l e s Pet zol d / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - us i ng Sy st em; us i ng Sy st em. Dr awi ng ; us i ng Sy st em.wi ndows. Fo r ms ; cl a s s Mode l e s s Di al ogbox : Fo rm Che c kbox c bgr aysha de s ; publ i c eve nt Eve nt Ha ndl e r Change ; publ i c Model e s sdi a l ogbox () Text = "Cha nge Col o r " ; Fo r mbo r de r St yl e = Fo r mbo r de r St yl e. Fi xeddi al og ; Mi ni mi z ebox = f al se ; Maxi mi z ebox = f al se ; ShowI nta s kba r = f al se ; St a rt Po si t i on = Fo r mst a rt Po si t i on. Manua l ; Loc at i on = Act i ve Fo rm. Loc at i on + Syst emi nf o r mat i on. Capt i onbut t onsi ze + Syst emi nf o r mat i on. Fr ame Bo r de r Si ze ; Cl i ent Si z e = new Si z e ( 144, 56) ; c bgr aysha de s = new Che c kbox ( ) ; c bgr aysha de s. Pa r e nt = t hi s ; c bgr aysha de s. Text = "Gr ay Shade s Onl y" ; c bgr aysha de s. Locat i on = new Poi nt ( 32, 8) ; c bgr aysha de s. Si ze = new Si ze (80, 12) ; But t on bt n = new But t on ( ) ; bt n. Pa r ent = t hi s ; bt n.text = "Cha nge " ; bt n. Loc at i on = new Poi nt (48, 32) ; bt n. Si z e = new Si z e ( 48, 14) ; bt n. Cl i c k += But t ononcl i c k ; Acc ept But t on = bt n ; Aut oscal e Di me ns i ons = new Si ze (4, 8) ; Aut oscal emode = Aut oscal emode. Font ; publ i c bool Gr ayshade s s et

78 PROGRAMMING MICROSOFT WINDOWS FORMS cbgr ayshade s. Che c ked = va l ue ; get ret urn cbgr ayshades. Checked ; voi d But t ononcl i c k (obj ect obj Sr c, Eve nt Ar gs a r gs) i f (Cha nge!= nul l ) Change (t hi s, new Event Ar gs ( ) ) ; Change Change. ModelessDialogDemo. ModelessDialogDemo. Modeless DialogDemo.cs / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Mode l e s s Di al ogdemo. c s (c ) 200 5 by Cha r l e s Pet zol d / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - us i ng Syst em; us i ng Syst em. Dr awi ng ; us i ng Syst em. Wi ndows. Fo rms ; cl a s s Model e s sdi a l ogdemo : Fo r m [STATh r e ad] publ i c st at i c voi d Ma i n () Appl i cat i on. Ena bl evi s ua l St yl e s ( ) ; Appl i cat i on. Run (new Model e s sdi a l ogdemo ( ) ) ; publ i c Model e s sdi a l ogdemo ( ) Text = "Mode l e s s Di a l og Demo " ; But t on bt n = new But t on ( ) ; bt n. Pa r ent = t hi s ; bt n.text = "Change Col o r " ; bt n. Loc at i on = new Poi nt ( 16, 16) ; bt n.aut osi z e = t r ue ; bt n. Cl i c k += But t ononcl i c k ; voi d But t ononcl i c k (obj ect obj Sr c, Eve nt Ar gs a r gs)

Chapter 1 79 Model e s sdi a l ogbox dl g = new Mode l e s s Di al ogbox ( ) ; dl g. Owne r = t hi s ; dl g. Cha nge += Di a l ogoncha nge ; dl g. Show( ) ; voi d Di a l ogoncha nge (obj e ct obj Sr c, Eve nt Ar gs a r gs ) Model e s sdi a l ogbox dl g = (Model e s sdi a l ogbox) obj Sr c ; Random r nd = new Random( ) ; i nt i Shade = r nd. Next ( 255) ; i f (dl g. Gr aysha de s) Ba c kcol o r = Col o r. FromAr gb ( i Sha de, i Sha de, i Sha de ) ; e l s e Ba c kcol o r = Col o r. FromAr gb ( i Sha de, r nd. Next (2 55), r nd. Next ( 255) ) ; ButtonOnClick,. Change Show. Show. Change, Change. DialogOnChange. ModelessDialogBox. DialogBoxDemo, Change Color. ( ).. dlg dlg null. ButtonOnClick Change Color.

8 0 PROGRAMMING MICROSOFT WINDOWS FORMS ( ( But t on) obj Sr c). Ena bl ed = f al se ; Change Color. Close. dl g. Cl os ed += Di a l ogoncl o se d ;. voi d Di al ogoncl os ed (obj ect obj Sr c, Event Ar gs a r gs) Cont rol s [0]. Enabl e d = t r ue ;. Controls..NET Framework 2.0 CommonDialog,. ColorDialog, FolderBrowserDialog, FontDialog, OpenFileDialog SaveFileDialog(FileDialog ), PageSetupDialog, PrintDialog. DLL DLL.. DLL Main. DLL public. namespace. ( DLL ) DLL DLL..

Chapter 1 8 1. MessageButton DLL. MessageButtonLib.cs / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Me s sa ge But t onli b. c s (c ) 200 5 by Cha r l e s Pet zol d / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - us i ng Sy st em; us i ng Sy st em. Dr awi ng ; us i ng Sy st em.wi ndows. Fo r ms ; name spac e Pet zol d. Pr og r ammi ngwi ndows Fo rms publ i c c l a s s Me s sa ge But t on : But t on st r i ng st rme s sa ge BoxText ; publ i c Me s s agebut t on ( ) Enabl e d = f al se ; publ i c st r i ng Me s sa ge BoxText set st r Me s s ageboxtext = va l ue ; Ena bl ed = va l ue!= nul l && va l ue. Le ngt h > 0 ; get r et ur n st r Me s s ageboxtext ; p rot e ct ed ove r r i de voi d OnCl i c k( Event Ar gs a r gs ) ba se. OnCl i c k (a r gs) ; Me s s agebox. Show(Me s s ageboxtext, Text ) ; namespace public MessageButton.cs. OnClick (Button )., MessageButton Click.

8 2 PROGRAMMING MICROSOFT WINDOWS FORMS MessageButtonLib.cs / target :library. MessageButtonLib.dll. Visual Studio. MessageButtonLibraryDemo Visual Studio MessageButtonLib. ProgramUsingLibrary. MessageButtonDemo. ProgramUs inglibrary.cs / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Pr og r amusi ngli br a r y. c s ( c) 200 5 by Cha r l e s Pet zol d / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - us i ng Syst em; us i ng Syst em. Dr awi ng ; us i ng Syst em. Wi ndows. Fo rms ; us i ng Pet zol d. Progr ammi ngwi ndows Fo r ms ; cl a s s Progr amus i ngli b r a ry : Fo rm [STATh r e ad] publ i c st at i c voi d Ma i n () Appl i cat i on. Ena bl evi s ua l St yl e s ( ) ; Appl i cat i on. Run (new Progr amus i ngli b r a ry () ) ; publ i c Progr amus i ngli b r a ry () Text = " Pr og r am Us i ng Li br a r y" ; Me s sa ge But t on msgbt n = new Me s sa ge But t on () ; msgbt n. Pa r e nt = t hi s ; msgbt n. Text = "Cal cul at e 10, 000, 000 di gi t s of PI " ; msgbt n. Me s s ageboxtext = "Thi s but t on i s not yet i mpl eme nt ed!" ; msgbt n. Locat i on = new Poi nt ( 50, 50) ; msgbt n. Aut osi ze = t r ue ; DLL using. using using

Chapter 1 8 3. using, Petzold.ProgrammingWindows Forms.MessageButton.. Windows Forms System System.Drawing, System.Windows.Forms ( DLL ). MessageButtonLib.dll. / reference MessageButtonLib.dll., MessageButtonLib., DLL DLL. DLL, DLL. ( ).,,.. ProgramUsingLibrary.. DLL. ProgramUsingLibrary.exe MessageButtonLib.dll, DLL EXE.

8 4 PROGRAMMING MICROSOFT WINDOWS FORMS DLL Windows DLL.