WinForm special effect: Mask Layer on the desktop and winform special effect Mask Layer

Source: Internet
Author: User

WinForm special effect: Mask Layer on the desktop and winform special effect Mask Layer

A form effect helps you understand several windows api functions. effect: A simple mask layer is added to the windows desktop. WS_EX_TRANSPARENT is important and implements the mouse penetration function.

[Csharp]View plaincopy
  1. Using System;
  2. Using System. Drawing;
  3. Using System. Windows. Forms;
  4. Using System. Runtime. InteropServices;
  5. Namespace WindowsApplication40
  6. {
  7. Public partial class Form1: Form
  8. {
  9. Public Form1 ()
  10. {
  11. InitializeComponent ();
  12. }
  13. [DllImport ("user32.dll", EntryPoint = "GetWindowLong")]
  14. Public static extern long GetWindowLong (IntPtr hwnd, int nIndex );
  15. [DllImport ("user32.dll", EntryPoint = "SetWindowLong")]
  16. Public static extern long SetWindowLong (IntPtr hwnd, int nIndex, long dwNewLong );
  17. [DllImport ("user32", EntryPoint = "SetLayeredWindowAttributes")]
  18. Private static extern int SetLayeredWindowAttributes (IntPtr Handle, int crKey, byte bAlpha, int dwFlags );
  19. Const int GWL_EXSTYLE =-20;
  20. Const int WS_EX_TRANSPARENT = 0x20;
  21. Const int WS_EX_LAYERED = 0x80000;
  22. Const int LWA_ALPHA = 2;
  23. Private void Form1_Load (object sender, EventArgs e)
  24. {
  25. This. BackColor = Color. Silver;
  26. This. TopMost = true;
  27. This. FormBorderStyle = FormBorderStyle. None;
  28. This. WindowState = FormWindowState. Maximized;
  29. SetWindowLong (Handle, GWL_EXSTYLE, GetWindowLong (Handle, GWL_EXSTYLE) | WS_EX_TRANSPARENT | WS_EX_LAYERED );
  30. SetLayeredWindowAttributes (Handle, 0,128, LWA_ALPHA );
  31. }
  32. }
  33. }

C # How to create an icon effect similar to that on the desktop in winform

Make an image of the right size and save it as gif, so that the background is transparent.
Set the background of the button to the image, borderwidth to 0, and style to flat.

As for the drag, the drag code is generally written using a class without a single button. Below is a drag class.
C # Drag and zoom controls
In the past few days, the project needs to drag the controls on the form and scale the size, so the class is encapsulated:
Using System;
Using System. Collections. Generic;
Using System. Drawing;
Using System. Linq;
Using System. Text;
Using System. Windows. Forms;
Namespace ItpClientProtype
{
Class DragResizeControl
{
# Region Field
Private const int Band = 5;
Private const int MinWidth = 10;
Private const int MinHeight = 10;
Private static EnumMousePointPosition m_MousePointPosition;
Private static Point p, p1;
# Endregion
# Region Inner Object
Private enum EnumMousePointPosition
{
MouseSizeNone = 0, // 'None
MouseSizeRight = 1, // 'Stretch the right border
MouseSizeLeft = 2, // 'Stretch the Left Border
MouseSizeBottom = 3, // 'Stretch The Bottom Border
MouseSizeTop = 4, // 'Stretch the upper border
MouseSizeTopLeft = 5, // 'Stretch the upper left corner
MouseSizeTopRight = 6, // 'Stretch the upper right corner
MouseSizeBottomLeft = 7, // 'Stretch the lower left corner
MouseSizeBottomRight = 8, // 'Stretch the bottom right corner
MouseDrag = 9 // drag the mouse
}
# Endregion
# Region Constructor
Public DragResizeControl ()
{
// Nothing to do.
}
# Endregion
# Region Public Method
... The remaining full text>


C # In winform, I want to click the yyicon control and display the form at the top of the desktop?

Double-click the policyicon event and set the current window of your software to active. In this way, the Windows system will automatically move your window to the frontend, and the window will be automatically moved back when you operate on other Windows and will not block other Windows. The property seems to be Form. Active (). The specific name is missing. You can check.

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.