[C #] component sharing: FormDragger-form dashboard,

Source: Internet
Author: User

[C #] component sharing: FormDragger-form dashboard,

Applicable:. Net2.0 + winform Project

Introduction:

Similar to QQ, thunder, and other software that focuses on UI experience, you can drag windows in multiple places in the window without having to drag the top title bar. This component allows winform to drag and drop as needed, casual or even worse. First look at the effect:

Drag-and-drop options include:

  • Blank areas of container controls such as forms, Panel, GroupBox, and TabControl;
  • Blank areas of bar, such as the menu bar, toolbar, and status bar, and invalid items;
  • Labels, PictureBox, ProgressBar, and other controls that do not normally interact with the mouse;
  • All invalid controls (Enabled is false );

Basically, you can drag it wherever you think it is possible.

Usage:

First look at the public members:

// The drag-and-drop tool enables or disables the bool Enabled {get; set ;}// exclusion list. You can add or remove Control instances to the Control List. The Control in the List does not accept the drag List <Control> ExcludeControls {get;} // event: when you are about to drag the Control instance, e is available. cancel = true Cancel drag, and e also carries Other Information event EventHandler <FormDraggingCancelEventArgs> Dragging; // event: event EventHandler EnabledChanged after the drag/drop switch status changes;

It is easy to use. The drag and drop function can be opened and closed anytime, anywhere. Enabled = true/false. For example, it can be Enabled in the Main function, and allSelf-built formsYou can drag and drop it happily. However, forms provided by the system, such as MessageBox in the message box and various dialogs (such as opening a file dialog box), cannot be dragged, the reason is that the messages in these windows do not enter the program and need to be checked before they can be captured. (In fact, a DialogDragger has been implemented in the solution. cs is used to drag the system dialog box, but it is known that the ColorDialog of the color selection dialog box has a problem, so it is not integrated for the time being. It is necessary to solve the problem and update it later. We recommend that you Watch it ). You can also choose this option for message boxes. It can be dragged because it is self-made.

For a drag-and-drop control, you cannot click a message (such as MouseDown) with the left mouse button,Because the event is intercepted, it will not be triggered if you register this type of event. If you want a drag-and-drop control not to be dragged, such as an image box, you want it to have the "HYPERLINK" function, execute the registered MouseDown event processing method when you click it. There are two ways to implement exceptions:

The above scenarios are provided in the source code for reference.

Principle:

Use Application. addMessageFilter adds a message filter to the program to intercept and process the left-click message sent to the program form. If the logic is met, the message is blocked and the message clicked on the title bar is sent to the form where the control is located, when you click this control, the system determines that it is a point to the title bar of the form. For more information, go to the address below.

Solution:

Https://github.com/ahdung/formdraggerdemo】 priority]

Https://coding.net/u/ahdung/p/FormDraggerDemo/git

Http://git.oschina.net/ahdung/FormDraggerDemo

The tester has been written in the solution. You are welcome to download it.

-Wen Bi-

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.