91在线一级黄片|91视频在线观看18|成人夜间呦呦网站|91资源欧美日韩超碰|久久最新免费精品视频一区二区三区|国产探花视频在线观看|黄片真人免费三级片毛片|国产人无码视频在线|精品成人影视无码三区|久久视频爱久久免费精品

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#透明窗體代碼詳解

實(shí)現(xiàn)C#透明窗體是如何實(shí)現(xiàn)的呢?這里向你介紹通過調(diào)用Windows API來實(shí)現(xiàn)C#透明窗體。那么具體的過程和步驟是什么呢?讓我們來看看具體的實(shí)現(xiàn)。

創(chuàng)新互聯(lián)于2013年創(chuàng)立,先為慈溪等服務(wù)建站,慈溪等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為慈溪企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

C#透明窗體實(shí)現(xiàn)實(shí)例:

C#透明窗體之WinAPI.cs類文件,Invoke & Wrap了窗體透明所需要的API函數(shù):

 
 
 
  1. [coolcode lang="cpp" download="WinAPI.cs"]  
  2. using System;  
  3. using System.Collections.Generic;  
  4. using System.Text;  
  5. using System.Runtime.InteropServices;  
  6.  
  7. namespace TransForm  
  8. {  
  9. class WinAPI  
  10. {  
  11. [DllImport("user32.dll")]  
  12. public extern static IntPtr GetDesktopWindow();  
  13.  
  14. [DllImport("user32.dll")]  
  15. public extern static bool   
  16. SetLayeredWindowAttributes(  
  17. IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);  
  18. public static uint LWA_COLORKEY = 0×00000001;  
  19. public static uint LWA_ALPHA = 0×00000002;  
  20.  
  21. [DllImport("user32.dll")]  
  22. public extern static uint   
  23. SetWindowLong(IntPtr hwnd,   
  24. int nIndex, uint dwNewLong);  
  25. [DllImport("user32.dll")]  
  26. public extern static uint   
  27. GetWindowLong(IntPtr hwnd, int nIndex);  
  28.  
  29. public enum WindowStyle : int 
  30. {  
  31. GWL_EXSTYLE = -20  
  32. }  
  33.  
  34. public enum ExWindowStyle : uint 
  35. {  
  36. WS_EX_LAYERED = 0×00080000  
  37. }  
  38.  
  39. }  
  40. }  
  41. [/coolcode]  

C#透明窗體之DeviceForm.cs單元是API函數(shù)的調(diào)用方式:

 
 
 
  1. [coolcode lang="cpp" download="form1.cs"]  
  2. using System;  
  3. using System.Collections.Generic;  
  4. using System.ComponentModel;  
  5. using System.Data;  
  6. using System.Drawing;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9.  
  10. namespace TransForm  
  11. {  
  12. public partial class Form1 : Form  
  13. {  
  14. public Form1()  
  15. {  
  16. InitializeComponent();  
  17. }  
  18.  
  19. private void Form1_Load(object sender, EventArgs e)  
  20. {  
  21. this.SetWindowTransparent(100);  
  22. }  
  23. private void SetWindowTransparent(byte bAlpha)  
  24. {  
  25. try 
  26. {  
  27. WinAPI.SetWindowLong(  
  28. this.Handle,   
  29. (int)WinAPI.WindowStyle.GWL_EXSTYLE,  
  30. WinAPI.GetWindowLong(  
  31. this.Handle,   
  32. (int)WinAPI.WindowStyle.GWL_EXSTYLE) |   
  33. (uint)WinAPI.ExWindowStyle.WS_EX_LAYERED);  
  34.  
  35. WinAPI.SetLayeredWindowAttributes(  
  36. this.Handle, 0, bAlpha,  
  37.  WinAPI.LWA_COLORKEY | WinAPI.LWA_ALPHA);  
  38. }  
  39. catch 
  40. {  
  41. }  
  42. }  
  43. protected override CreateParams CreateParams  
  44. {  
  45. get 
  46. {  
  47. CreateParams cp = base.CreateParams;  
  48.  
  49. cp.Parent = WinAPI.GetDesktopWindow();  
  50. cp.ExStyle = 0×00000080 | 0×00000008;  
  51. //WS_EX_TOOLWINDOW | WS_EX_TOPMOST  
  52.  
  53. return cp;  
  54. }  
  55. }  
  56. }  
  57. }  
  58. [/coolcode]  

C#透明窗體的實(shí)現(xiàn)基本內(nèi)容就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C#透明窗體有所幫助。


分享題目:C#透明窗體代碼詳解
網(wǎng)頁網(wǎng)址:http://m.jiaoqi3.com/article/cdhhppg.html