vb.net(C#) 改变COMBOBOXD的下拉箭头的小技巧
作者:互联网
原理:有时候我们嫌combobox自带的下拉箭头不符合整体界面风格,网上有集成改写combobox的方法,太复杂,而且本人试过也不够完美。我的做法是在combobox上面 贴一个LABEL,设置label的大小为下拉箭头区域的大小,正好覆盖掉combobox自己的下拉箭头,为label增加click(Lb_Click)事件,另外禁用了combocox的按键事件,这样你就把combobox的下拉箭头换成了你自己的样子。
Sub comlab(ByVal c As ComboBox)
Dim l As New Label
l.BackColor = Color.FromArgb(225, 225, 225)
l.Image = My.Resources.下拉‘下拉箭头的资源图片
l.Tag = c
c.Parent.Controls.Add(l)
l.BringToFront()
l.Cursor = Cursors.Hand
AddHandler l.Click, AddressOf Lb_Click
AddHandler c.KeyPress, AddressOf Comp
l.Width = 18
l.Height = c.Height - 2
l.Top = c.Top + 1
l.Left = c.Right - l.Width - 1
End Sub
Sub Lb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim l As Label = sender
Dim c As ComboBox = l.Tag
If c.DroppedDown Then
c.DroppedDown = False
Else
c.DroppedDown = True
End If
End Sub
Private Sub Comp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
e.Handled = True
End Sub
标签:vb,End,Sub,C#,combobox,COMBOBOXD,下拉箭头,ByVal,Click 来源: https://blog.csdn.net/fanyx_bj/article/details/122764940