C # intercepts form messages

Source: Internet
Author: User
Functions for overloading C#from

The above work requires some of the functions of the form to be overloaded so that it can be done, first of all, here is a knowledge point: How to overload the function of a form?

After building the good one WinForm project, we can find the form method that can be overloaded using the following method:

(1) Popup Object Browser

(2) Select the base type from

(3) Object Browser settings

(4) Adding overloaded methods, taking Defwndproc as an example

This is a good way to reload the function where it's needed. Because the method overloads generally do not write their own overloaded functions, to copy the function from the base class.

Intercept C#form messages

First, accept the form message, and then do some custom processing based on the intercepted message.

The first thing to do is to overload a WndProc function to receive the message and handle the message accordingly.

Then write the processing code of the message in this function:

protected override void WndProc (ref Message m) {const int wm_syscommand = 0x0112;const int sc_close = 0xf060;if (m.msg = = WM _syscommand && (int) M.wparam = = sc_close) {//this. WindowState = Formwindowstate.minimized;this. Hide (); return;} Base. WndProc (ref m);} WndProc ()

This function knowledge intercepts Wm_syscommand's sc_close message, and other messages are to be given to the message handler function Base.wndproc of the base class form.

C # intercepts form messages

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.