我需要使列表框透明。我在 VB.NET 中找到了可以解决问题的代码。但是,我怎么能在 C# 中实现呢?
这是VB代码:
Option Explicit
Private Const WS_EX_TRANSPARENT = &H20&
Private Const GWL_EXSTYLE = (-20)
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Function MakeListTransparent(ListCtl As Object) As Boolean
On Error Resume Next
ListCtl.BackColor = ListCtl.Parent.BackColor
SetWindowLong ListCtl.hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT
MakeListTransparent = Err.LastDllError = 0
End Function
这是我的 C# 尝试:
public const int WS_EX_TRANSPARENT = 0x20;
public const int GWL_EXSTYLE = (-20);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, UInt32 dwNewLong);
//somewhere in my form:
listBox1.BackColor = Color.AliceBlue; // <-- to see an INITIAL color
SetWindowLong(listBox1.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT); // <-- to see if it turns TRANSPARENT
我没有正确地将它从 VB 翻译成 C# 吗?有没有更好的方法?我迫切需要使列表框透明...