cool hit counter [C#] Component Sharing: FormDragger Form Dragger_Intefrankly

[C#] Component Sharing: FormDragger Form Dragger


Applies to. net2.0+ winform project

Presentation.

Similar to QQ, Xunlei and other UI-conscious software, they all support dragging the window in multiple places within the window, instead of having to honestly go to the top title bar. This component is what allows winform to be dragged and dropped like this, with a degree of spontaneity or even more. First, look at the results.

Draggable areas include, but are not limited to.

  • Blank areas of container controls such as Forms, Panel, GroupBox, TabControl, etc..
  • Blank areas in menu bars, toolbars, status bars, etc. bar, and invalid items.
  • Label, PictureBox, ProgressBar and other controls that do not normally interact with the mouse.
  • All invalid controls (Enabled is false).

Basically, it's wherever you think you should be able to tow.

Usage.

First, look at the open membership.

 //Dragger Switch
bool Enabled { get; set; }

 // Exclusion List. Instances of controls can be added to or removed from the list, controls in the list do not accept drag and drop
List<Control> ExcludeControls { get; }

 //event: occurs when ready to drag and drop, available e. Cancel = true cancels the drag and drop, e also carries other information
event EventHandler<FormDraggingCancelEventArgs> Dragging;

 //event: after the state of the dragger switch changes
event EventHandler EnabledChanged;

It's pretty easy to use, anytime FormDragger.Enabled = true/false you can turn on and off the drag and drop function, for example in the Main function, and finish all the Build your own formYou can happily drag and drop, but, like the message box MessageBox, various dialog boxes (such as open file dialog box) and other forms provided by the system can not be dragged, the reason is that the message of these windows do not enter the program, you need to hook to capture the guilty (in fact, the program has been implemented a DialogDragger.cs, which is used to drag the system dialog box, but the color selection dialog ColorDialog is known to have problems, so it is not integrated for the time being, later feel the need and solve the update again, it is recommended Watch). Regarding the message box, there is also the option of this one , since it's homemade, it can be towed.

For controls where drag-and-drop rules apply, a left mouse click message (such as MouseDown) will not reach it. If you want a draggable control not to be dragged, such as an image box, and you want it to have the ability to "hyperlink" and execute the registered MouseDown event handler when you click on it, then there are two ways to achieve the exception.

  1. Add this control to the exception list: FormDragger.ExcludeControls.Add(pictureBox1);
  2. Dragging event, in the event handling method, the incoming e has a Control property, which indicates the control to point to, so you can determine whether e.Control is the control you want to exception, if so, make e.

All the above scenarios have examples in the source code for reference.

Principle.

AddMessageFilter to the program to intercept and process the left mouse click message sent to the program form, and if the logic is satisfied, intercept the message and send a click on the title bar message to the form where the control is located, so that when the control is clicked on, the system thinks it is clicking on the title bar of the form. For more information, please go to the address below.

Programme location.

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 program, that's what the screenshot looks like, feel free to download and experience it.

-Bunbi-


Recommended>>
1、The official Smart Fair App is now live Thats a bit of a lot of information
2、RMAN Backup and Recovery 7 SemiAutomated OffMachine Recovery of Databases
3、Ctrip Spring Festival data Spring Festival becomes global golden month with 3 billion trips
4、These Media People Give a Portrait of the American Media in 2018 above
5、From paper to test a first look at the Facebook Detectron open source project

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号