熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C#窗口透明

2022-06-13   來源: .NET編程 

  using System;

  using SystemCollectionsGeneric;

  using SystemText;

  using SystemRuntimeInteropServices;

  namespace TransForm

  {

  class WinAPI

  {

  [DllImport(userdll)]

  public extern static IntPtr GetDesktopWindow();

  [DllImport(userdll)]

  public extern static bool SetLayeredWindowAttributes(IntPtr hwnd uint crKey byte bAlpha uint dwFlags);

  public static uint LWA_COLORKEY = x;

  public static uint LWA_ALPHA = x;

  [DllImport(userdll)]

  public extern static uint SetWindowLong(IntPtr hwnd int nIndex uint dwNewLong);

  [DllImport(userdll)]

  public extern static uint GetWindowLong(IntPtr hwnd int nIndex);

  public enum WindowStyle : int

  {

  GWL_EXSTYLE =

  }

  public enum ExWindowStyle : uint

  {

  WS_EX_LAYERED = x

  }

  }

  }

  DeviceFormcs單元是API函數的調用方式

  using System;

  using SystemCollectionsGeneric;

  using SystemComponentModel;

  using SystemData;

  using SystemDrawing;

  using SystemText;

  using SystemWindowsForms;

  namespace TransForm

  {

  public partial class Form : Form

  {

  public Form()

  {

  InitializeComponent();

  }

  private void Form_Load(object sender EventArgs e)

  {

  thisSetWindowTransparent();

  }

  private void SetWindowTransparent(byte bAlpha)

  {

  try

  {

  WinAPISetWindowLong(thisHandle (int)WinAPIWindowStyleGWL_EXSTYLE

  WinAPIGetWindowLong(thisHandle (int)WinAPIWindowStyleGWL_EXSTYLE) | (uint)WinAPIExWindowStyleWS_EX_LAYERED);

  WinAPISetLayeredWindowAttributes(thisHandle bAlpha WinAPILWA_COLORKEY | WinAPILWA_ALPHA);

  }

  catch

  {

  }

  }

  protected override CreateParams CreateParams

  {

  get

  {

  CreateParams cp = baseCreateParams;

  cpParent = WinAPIGetDesktopWindow();

  cpExStyle = x | x;//WS_EX_TOOLWINDOW | WS_EX_TOPMOST

  return cp;

  }

  }

  }

  }


From:http://tw.wingwit.com/Article/program/net/201311/11509.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.