16,555
社区成员
发帖
与我相关
我的任务
分享
Imports System.Runtime.InteropServices
Public Class AddressCombobox : Inherits ComboBox
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32
Private Declare Function MoveWindow Lib "user32.dll" (ByVal hwnd As Int32, ByVal x As Int32, ByVal y As Int32, ByVal nWidth As Int32, ByVal nHeight As Int32, ByVal bRepaint As Int32) As Int32
Private Declare Function GetClientRect Lib "user32.dll" (ByVal hwnd As Int32, ByRef lpRect As RECT) As Int32
Private w As Integer
Private h As Integer
Private t As Integer
Private _handle As Integer
Private Const WM_PAINT As Int32 = &HF
Private Const sp As Integer = 20
Private Const _top As Integer = 4
<StructLayout(LayoutKind.Sequential)> _
Private Structure RECT
Public Left As Int32
Public Top As Int32
Public Right As Int32
Public Bottom As Int32
End Structure
Public Property Image As Image = Nothing
Protected Overrides Sub OnHandleCreated(e As System.EventArgs)
MyBase.OnHandleCreated(e)
_handle = FindWindowEx(Me.Handle, 0, "Edit", Nothing)
Dim r As RECT
GetClientRect(_handle, r)
w = Me.Width - r.Right - r.Left + sp
h = r.Bottom - r.Top
changeSize()
End Sub
Protected Overrides Sub OnSizeChanged(e As System.EventArgs)
MyBase.OnSizeChanged(e)
changeSize()
End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
If Image Is Nothing Then Return
If m.Msg = WM_PAINT Then
Using g As Graphics = Graphics.FromHwnd(Me.Handle)
g.DrawImage(Image, New Rectangle(2, 2, 16, 16))
End Using
End If
End Sub
Private Sub changeSize()
MoveWindow(_handle, sp, _top, Me.Width - w, h, 0)
End Sub
End Class