程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> WinForm特效:桌面上的遮罩層,winform特效遮罩層

WinForm特效:桌面上的遮罩層,winform特效遮罩層

編輯:C#入門知識

WinForm特效:桌面上的遮罩層,winform特效遮罩層


一個窗體特效,幫你了解幾個windows api函數.效果:windows桌面上增加一個簡單的遮罩層,其中WS_EX_TRANSPARENT 比較重要,它實現了鼠標穿透的功能。

[csharp] view plaincopy
  1. using System;  
  2.   
  3. using System.Drawing;  
  4.   
  5. using System.Windows.Forms;  
  6.   
  7. using System.Runtime.InteropServices;  
  8.   
  9. namespace WindowsApplication40  
  10.   
  11. {  
  12.   
  13.     public partial class Form1 : Form  
  14.   
  15.     {  
  16.   
  17.         public Form1()  
  18.   
  19.         {  
  20.   
  21.             InitializeComponent();  
  22.   
  23.         }  
  24.   
  25.         [DllImport("user32.dll", EntryPoint = "GetWindowLong")]  
  26.   
  27.         public static extern long GetWindowLong(IntPtr hwnd, int nIndex);  
  28.   
  29.   
  30.   
  31.         [DllImport("user32.dll", EntryPoint = "SetWindowLong")]  
  32.   
  33.         public static extern long SetWindowLong(IntPtr hwnd, int nIndex, long dwNewLong);  
  34.   
  35.   
  36.   
  37.         [DllImport("user32", EntryPoint = "SetLayeredWindowAttributes")]  
  38.   
  39.         private static extern int SetLayeredWindowAttributes(IntPtr Handle, int crKey, byte bAlpha, int dwFlags);  
  40.   
  41.   
  42.   
  43.         const int GWL_EXSTYLE = -20;  
  44.   
  45.         const int WS_EX_TRANSPARENT = 0x20;  
  46.   
  47.         const int WS_EX_LAYERED = 0x80000;  
  48.   
  49.         const int LWA_ALPHA = 2;  
  50.   
  51.   
  52.   
  53.   
  54.   
  55.         private void Form1_Load(object sender, EventArgs e)  
  56.   
  57.         {  
  58.   
  59.             this.BackColor = Color.Silver;  
  60.   
  61.             this.TopMost = true;  
  62.   
  63.             this.FormBorderStyle = FormBorderStyle.None;  
  64.   
  65.             this.WindowState = FormWindowState.Maximized;  
  66.   
  67.             SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) | WS_EX_TRANSPARENT | WS_EX_LAYERED);  
  68.   
  69.             SetLayeredWindowAttributes(Handle, 0, 128, LWA_ALPHA );  
  70.   
  71.   
  72.   
  73.         }  
  74.   
  75.     }  
  76.   
  77. }  

C# winform中怎創建類似桌面上的那種圖標效果

做一個大小合適的圖片,存成gif,這樣背景透明。
把button的背景設為該圖片,borderwidth為0,樣式為flat,就可以了。

至於拖動,一般用類,沒有一個一個按鈕的編寫拖動代碼。下面是一個拖動類。
C#控件拖動和縮放類
這幾天,因為項目需要,要對窗體上的控件進行拖動並對大小進行縮放,於是封裝了該類:
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, //'無
MouseSizeRight = 1, //'拉伸右邊框
MouseSizeLeft = 2, //'拉伸左邊框
MouseSizeBottom = 3, //'拉伸下邊框
MouseSizeTop = 4, //'拉伸上邊框
MouseSizeTopLeft = 5, //'拉伸左上角
MouseSizeTopRight = 6, //'拉伸右上角
MouseSizeBottomLeft = 7, //'拉伸左下角
MouseSizeBottomRight = 8, //'拉伸右下角
MouseDrag = 9 // '鼠標拖動
}
#endregion
#region Constructor
public DragResizeControl()
{
// Nothing to do.
}
#endregion
#region Public Method
......余下全文>>

 

c# winform 裡我想點擊notifyicon控件後將窗體顯示在桌面最頂部?

雙擊notifyicon圖標事件中,將你的軟件的當前窗口設置為激活狀態就可以。這樣Windows系統會自動將你的窗口放在最前端,而且在操作其他窗口時,該窗口會自動後移不會擋住其他窗口。屬性好像是Form.Active(),具體名稱忘記了。你可查一下。
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved