リストボックスを透明にする必要があります。トリックを行う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# に正しく変換していませんか? より良い方法はありますか?リストボックスを透明にする必要があります...