c#多选下拉框(ComboBox)

论坛 期权论坛     
选择匿名的用户   2021-6-2 18:51   274   0
<div class="blogpost-body" id="cnblogs_post_body">
<p>代码如下</p>
<div class="cnblogs_code">
  <img alt="" class="code_img_closed" id="code_img_closed_d569f1df-fa0b-4534-a2fb-3ce1019c87fc" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-8f900a89c6347c561fdf2122f13be562.gif">
  <img alt="" class="code_img_opened" id="code_img_opened_d569f1df-fa0b-4534-a2fb-3ce1019c87fc" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-961ddebeb323a10fe0623af514929fc1.gif">
  <div class="cnblogs_code_hide" id="cnblogs_code_open_d569f1df-fa0b-4534-a2fb-3ce1019c87fc">
   <pre class="blockcode"><span style="color:#008080;">  1</span> <span style="color:#0000ff;">using</span><span style="color:#000000;"> System;
</span><span style="color:#008080;">  2</span> <span style="color:#0000ff;">using</span><span style="color:#000000;"> System.Collections.Generic;
</span><span style="color:#008080;">  3</span> <span style="color:#0000ff;">using</span><span style="color:#000000;"> System.ComponentModel;
</span><span style="color:#008080;">  4</span> <span style="color:#0000ff;">using</span><span style="color:#000000;"> System.Drawing;
</span><span style="color:#008080;">  5</span> <span style="color:#0000ff;">using</span><span style="color:#000000;"> System.Data;
</span><span style="color:#008080;">  6</span> <span style="color:#0000ff;">using</span><span style="color:#000000;"> System.Linq;
</span><span style="color:#008080;">  7</span> <span style="color:#0000ff;">using</span><span style="color:#000000;"> System.Text;
</span><span style="color:#008080;">  8</span> <span style="color:#0000ff;">using</span><span style="color:#000000;"> System.Windows.Forms;
</span><span style="color:#008080;">  9</span> <span style="color:#0000ff;">using</span><span style="color:#000000;"> System.Collections;
</span><span style="color:#008080;"> 10</span> <span style="color:#0000ff;">using</span><span style="color:#000000;"> System.Reflection;
</span><span style="color:#008080;"> 11</span> <span style="color:#0000ff;">using</span><span style="color:#000000;"> Newtonsoft.Json.Linq;
</span><span style="color:#008080;"> 12</span>
<span style="color:#008080;"> 13</span> <span style="color:#0000ff;">namespace</span><span style="color:#000000;"> ControlsAA
</span><span style="color:#008080;"> 14</span> <span style="color:#000000;">{
</span><span style="color:#008080;"> 15</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span><span style="color:#000000;"> ComboBoxEx : ComboBox
</span><span style="color:#008080;"> 16</span> <span style="color:#000000;">    {
</span><span style="color:#008080;"> 17</span>         TreeView lst &#61; <span style="color:#0000ff;">new</span><span style="color:#000000;"> TreeView();
</span><span style="color:#008080;"> 18</span>      
<span style="color:#008080;"> 19</span>         <span style="color:#0000ff;">public</span><span style="color:#000000;"> ComboBoxEx()
</span><span style="color:#008080;"> 20</span> <span style="color:#000000;">        {
</span><span style="color:#008080;"> 21</span>             <span style="color:#0000ff;">this</span>.DrawMode &#61; DrawMode.OwnerDrawFixed;<span style="color:#008000;">//</span><span style="color:#008000;">只有设置这个属性为OwnerDrawFixed才可能让重画起作用</span>
<span style="color:#008080;"> 22</span>             lst.KeyUp &#43;&#61; <span style="color:#0000ff;">new</span><span style="color:#000000;"> KeyEventHandler(lst_KeyUp);
</span><span style="color:#008080;"> 23</span>             lst.MouseUp &#43;&#61; <span style="color:#0000ff;">new</span><span style="color:#000000;"> MouseEventHandler(lst_MouseUp);
</span><span style="color:#008080;"> 24</span>             <span style="color:#008000;">//</span><span style="color:#008000;"> lst.KeyDown &#43;&#61; new KeyEventHandler(lst_KeyDown);</span>
<span style="color:#008080;"> 25</span>             lst.Leave &#43;&#61; <span style="color:#0000ff;">new</span><span style="color:#000000;"> EventHandler(lst_Leave);
</span><span style="color:#008080;"> 26</span>             lst.CheckBoxes &#61; <span style="color:#0000ff;">true</span><span style="color:#000000;">;
</span><span style="color:#008080;"> 27</span>             lst.ShowLines &#61; <span style="color:#0000ff;">false</span><span style="color:#000000;">;
</span><span style="color:#008080;"> 28</span>             lst.ShowPlusMinus &#61; <span style="color:#0000ff;">false</span><span style="color:#000000;">;
</span><span style="color:#008080;"> 29</span>             lst.ShowRootLines &#61; <span style="color:#0000ff;">false</span><span style="color:#000000;">;
</span><span style="color:#008080;"> 30</span>             <span style="color:#0000ff;">this</span>.DropDownHeight &#61; <span style="color:#800080;">1</span><span style="color:#000000;">;
</span><span style="color:#008080;"> 31</span> <span style="color:#000000;">        }
</span><span style="color:#008080;"> 32</span>
<span style="color:#008080;"> 33</span>         <span style="color:#0000ff;">void</span> lst_Leave(<span style="color:#0000ff;">object</span><span style="color:#000000;"> sender, EventArgs e)
</span><span style="color:#008080;"> 34</span> <span style="color:#000000;">        {
</span><span style="color:#008080;"> 35</span> <span style="color:#000000;">            lst.Hide();
</span><span style="color:#008080;"> 36</span> <span style="color:#000000;">        }
</span><span style="color:#008080;"> 37</span>         <span style="color:#
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP