Windows Forms (1), Windows Forms
Guide
1. What is Windows Forms
2. Do I need to learn Windows Forms?
3. How to Write a simple Windows Forms Program
4. Description of the above program
5. Form and Control
6. event processing and handwriting in Windows Forms a form with a mouse moving event
What is Windows Forms
In general, Windows Forms refer to a type of GUI (graphical user interface) programs. NET 1.0 was released together, but Windows Forms programs on the market are mainly.. NET 2.0 or later ,. NET 3.5, the main GUI program becomes WPF, Windows Forms back to the second line.
Do you need to learn Windows Forms?
The answer to this question varies from person to person. For students, I suggest skipping Windows Forms to learn WPF. WPF's thinking mode is much better than Windows Forms's event processing mode. For programmers looking for a job (or already working), this depends on the company's needs. In many industry software companies, there are more Windows forms than WPF, although the WPF interface is much more dazzling than the Native Windows Forms interface, the third-party control library of Windows Forms makes up for this problem.
How to Write a simple Windows Forms Program
Directly run the code: FirstWinForm. cs
using System;using System.Windows.Forms;namespace DemoWinForm{ class App : Form { static void Main() { Application.Run(new App()); } }}
Compile command: csc/t: winexe FirstWinForm. cs
Running Effect
Using System; using System. windows. forms; namespace DemoWinForm {// note here I use static class App {static void Main () {Application. run (new MainForm () ;}} public class MainForm: Form {}}
Form and Control
Let's take a look at the inheritance relationship diagram of System. Windows. Forms. Form.
System. Object
System. externalbyrefobject
System. ComponentModel. Component
System. Windows. Forms. Control
System. Windows. Forms. ScrollableControl
System. Windows. Forms. ContainerControl
System. Windows. Forms. Form
The highlighted classes are the ones that I think need to be focused on. All visual controls (such as buttons) are inherited from System. windows. forms. the component is inherited from System. componentModel. component.
System. windows. forms. the Control class provides the vast majority of members of a visual Control (Control name, Size, Font, foreground and background color, parent container, common events such as mouse, keyboard, etc.). For details, see the MSDN
Example of using the Control class:
Using System; using System. windows. forms; using System. drawing; namespace DemoWinForm {static class App {static void Main () {Application. run (new MainForm () ;}} public class MainForm: Form {public MainForm () {Text = "one window"; Height = 300; Width = 500; BackColor = Color. green; Cursor = Cursors. hand ;}}}
Compile csc/t: winexe UseControlDemo. cs
Using System; using System. windows. forms; using System. drawing; namespace DemoWinForm {static class App {static void Main () {Application. run (new MainForm () ;}} public class MainForm: Form {public MainForm () {this. text = "a window"; this. height = 300; this. width = 500; BackColor = Color. green; Cursor = Cursors. hand; this. mouseMove + = new MouseEventHandler (MainForm_MouseMove);} void MainForm_MouseMove (object sender, MouseEventArgs e) {this. text = string. format ("current mouse coordinates: [{0}, {1}]", e. x, e. Y );}}}
Compile csc/t: winexe MouseMoveDemo. cs
Running Effect
End of this Article