C # message processing when developing a WINDOWS application (C # Note 2)-Windows development-. NET tutorial-micro

Source: Internet
Author: User

Author: Wang Jun, Wenling Telecom Bureau, Zhejiang Province
WINDOWS applications are message-driven. In VC, we can use CLASSWIZARD to add message processing functions for a window class. CLASSWIZARD will add message ing for you. For WINDOWS messages, the generated message processing function reloads the Virtual Methods of the base class. In C #, how does one process messages? This article introduces WINDOWS messages and how to process custom messages in C # In VS. NET BETA1.
Download Sample Code 17 K
1. Generate a project named MSGApplication
For how to create a project, see one of C # study notes.
Ii. Process WM_PAINT messages
Let's take WM_PAINT message processing as an example. In C #, message processing is similar to that in MFC, but it is simpler. In MFC, DECLARE_MESSAGE_MAP must be used to define message ing, which is not required in C. For example, for the WM_PAINT message, we only need to reload the OnPaint virtual method in the parent class (although the process of reloading the parent virtual method in BETA1 is a bit cumbersome), the method is as follows:
Choose View> Other Windows> Object Browser to open the Object browsing window (or press CTRL + ALT + J to open the window), find the Form under our project name, and select, in this case, the window on the right lists all Form class member functions ,:
We select OnPaint (System. WinForms. PaintEventArgs). The complete OnPaint function protected void OnPaint (System. WinForms. PaintEventArgs e) is displayed below. We Copy this line of string. Open Form1.cs to edit the code. Copy the copied function definition to the Form1 class and add the override keyword. Then, we can add our message processing code to it, see the following code snippet:
Protected override void OnPaint (System. WinForms. PaintEventArgs e)
{
Font font = new Font ("", 28); // defines the Font:, size: 28
SolidBrush bluepen = new SolidBrush (Color. Blue); // create a Blue paint brush
SolidBrush blackpen = new SolidBrush (Color. FromARGB (0xa0, 0xa0, 0xb0); // create a black brush

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.