如何重载ComboBox 使其下拉按钮(带下箭头的)和下拉列表的垂直滚动条的宽度改变?(自绘ComboBox) [转]
原文地址:http://bbs.csdn.net/topics/390135022
http://blog.csdn.net/scsdn/article/details/4363299
想使用winform的combox控件,但是觉得控件太小了,想在触摸屏上使用,感觉combox后面的下拉选择的三角形太小了,combox的宽度也太小了,请问下,combox的这些属性,可以更改吗?能够使小三角形大一些嘛?能够使combox的宽度宽些不?请大家给予帮助,谢谢
设置字体可以使得combobox变大。
combobox,listview等一些控件的外观会由于字体大小的改变而改变。
这个没办法。
除非重绘
http://blog.csdn.net/scsdn/article/details/4363299
关于如何重载ComboBox 使其下拉按钮(带下箭头的)和下拉列表的垂直滚动条的宽度改变的问题,通过自绘自定义控件得以解决。
ComboBoxDIY.cs文件
- //ComboBoxDIY.cs
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Text;
- using System.Windows.Forms;
- namespace WindowsApplication7
- {
- public partial class ComboBoxDIY : UserControl
- {
- public bool buttondown = false;
- public ComboBoxDIY()
- {
- InitializeComponent();
- this.listBox1.Visible = false;
- this.vScrollBar1.Visible = false;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- //下拉按钮未曾按下
- if (this.buttondown==false)
- {
- //listbox所有数据的项数
- int count = this.listBox1.Items.Count;
- //获取listbox所能显示的项数
- int displaycount = this.listBox1.Height / this.listBox1.ItemHeight;
- //滚动条显示的最大值
- int scrollmax = 0;
- //垂直方向上显示内容数目大于所能显示的数目时
- //垂直滚动条直接可见
- if (count > displaycount)
- {
- scrollmax = count - 1;
- this.vScrollBar1.Visible = true;
- }
- this.vScrollBar1.LargeChange = displaycount;
- this.vScrollBar1.Maximum = scrollmax;
- this.vScrollBar1.Minimum = 0;
- this.vScrollBar1.Scroll += new ScrollEventHandler(vscroll);
- this.listBox1.Visible = true;
- //下拉按钮按下
- this.buttondown = true;
- }
- //下拉按钮已按下
- else
- {
- if(this.vScrollBar1.Visible)this.vScrollBar1.Visible = false;
- this.listBox1.Visible = false;
- //下拉按钮弹起
- this.buttondown = false;
- }
- }
- private void vscroll(object sender, ScrollEventArgs e)
- {
- //ScrollBar控制listBox滚动
- this.listBox1.TopIndex=e.NewValue;
- }
- private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- //文本框显示选择结果
- this.textBox1.Text =this.listBox1.Items[this.listBox1.SelectedIndex].ToString();
- this.vScrollBar1.Visible = false;
- this.listBox1.Visible = false;
- //下拉按钮弹起
- this.buttondown = false;
- }
- }
- }
//ComboBoxDIY.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication7
{
public partial class ComboBoxDIY : UserControl
{
public bool buttondown = false;
public ComboBoxDIY()
{
InitializeComponent();
this.listBox1.Visible = false;
this.vScrollBar1.Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
//下拉按钮未曾按下
if (this.buttondown==false)
{
//listbox所有数据的项数
int count = this.listBox1.Items.Count;
//获取listbox所能显示的项数
int displaycount = this.listBox1.Height / this.listBox1.ItemHeight;
//滚动条显示的最大值
int scrollmax = 0;
//垂直方向上显示内容数目大于所能显示的数目时
//垂直滚动条直接可见
if (count > displaycount)
{
scrollmax = count - 1;
this.vScrollBar1.Visible = true;
}
this.vScrollBar1.LargeChange = displaycount;
this.vScrollBar1.Maximum = scrollmax;
this.vScrollBar1.Minimum = 0;
this.vScrollBar1.Scroll += new ScrollEventHandler(vscroll);
this.listBox1.Visible = true;
//下拉按钮按下
this.buttondown = true;
}
//下拉按钮已按下
else
{
if(this.vScrollBar1.Visible)this.vScrollBar1.Visible = false;
this.listBox1.Visible = false;
//下拉按钮弹起
this.buttondown = false;
}
}
private void vscroll(object sender, ScrollEventArgs e)
{
//ScrollBar控制listBox滚动
this.listBox1.TopIndex=e.NewValue;
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//文本框显示选择结果
this.textBox1.Text =this.listBox1.Items[this.listBox1.SelectedIndex].ToString();
this.vScrollBar1.Visible = false;
this.listBox1.Visible = false;
//下拉按钮弹起
this.buttondown = false;
}
}
}
ComboBoxDIY.Designer.cs文件
- //ComboBoxDIY.Designer.cs
- namespace WindowsApplication7
- {
- partial class ComboBoxDIY
- {
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- #region 组件设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要
- /// 使用代码编辑器修改此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.button1 = new System.Windows.Forms.Button();
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.listBox1 = new System.Windows.Forms.ListBox();
- this.vScrollBar1 = new System.Windows.Forms.VScrollBar();
- this.SuspendLayout();
- //
- // button1
- //
- this.button1.Location = new System.Drawing.Point(85, 0);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(65, 44);
- this.button1.TabIndex = 0;
- this.button1.Text = "▼";
- this.button1.UseVisualStyleBackColor = true;
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // textBox1
- //
- this.textBox1.Font = new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.textBox1.Location = new System.Drawing.Point(0, 0);
- this.textBox1.Name = "textBox1";
- this.textBox1.Size = new System.Drawing.Size(88, 44);
- this.textBox1.TabIndex = 1;
- //
- // listBox1
- //
- this.listBox1.Font = new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.listBox1.FormattingEnabled = true;
- this.listBox1.ItemHeight = 33;
- this.listBox1.Items.AddRange(new object[] {
- "0",
- "1",
- "2",
- "3",
- "4",
- "5",
- "6",
- "7",
- "8",
- "9"});
- this.listBox1.Location = new System.Drawing.Point(0, 44);
- this.listBox1.Name = "listBox1";
- this.listBox1.Size = new System.Drawing.Size(148, 103);
- this.listBox1.TabIndex = 2;
- this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
- //
- // vScrollBar1
- //
- this.vScrollBar1.Location = new System.Drawing.Point(85, 44);
- this.vScrollBar1.Name = "vScrollBar1";
- this.vScrollBar1.Size = new System.Drawing.Size(63, 103);
- this.vScrollBar1.TabIndex = 3;
- //
- // UserControl1
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.Controls.Add(this.vScrollBar1);
- this.Controls.Add(this.listBox1);
- this.Controls.Add(this.textBox1);
- this.Controls.Add(this.button1);
- this.Name = "UserControl1";
- this.Size = new System.Drawing.Size(149, 148);
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- #endregion
- private System.Windows.Forms.Button button1;
- private System.Windows.Forms.TextBox textBox1;
- private System.Windows.Forms.ListBox listBox1;
- private System.Windows.Forms.VScrollBar vScrollBar1;
- }
- }
如何重载ComboBox 使其下拉按钮(带下箭头的)和下拉列表的垂直滚动条的宽度改变?(自绘ComboBox) [转]的更多相关文章
- Qt中QComboBox中自定义界面使用stylesheet实现下拉按钮独立效果
使用QSS自定义控件界面时,QT中控件QCombobox含有两个子控件drop-down和down-arrow.一般而言,当改变QCombox时,很多效果都会出来,但是,针对下拉按钮和下拉图标的自定义 ...
- 重绘ComboBox —— 让ComboBox多列显示
最近在维护一个winform项目,公司购买的是DevExpress控件 (请问怎么联系DevExpress工作人员? 我想询问下,广告费是怎么给的.:p),经过公司大牛们对DevExpress控件疯狂 ...
- Bootstrap页面布局15 - BS带下拉菜单的按钮
带下拉菜单的按钮 <div class='btn-toolbar'> <div class='btn-group'> <a href='javascript:;' cla ...
- EazyUI_Datagrid_行内编辑(editor)的combobox下拉框带图片
1.业务需求: 商品的明细列表里面下拉框需要 [图片+文字 ] 显示 2.我们使用的是EazyUI,而我比较懒,不习惯用拼接html来显示列表页面,使用的是eazyui的数据网格(datagrid) ...
- 转:控制ComboBox下拉框的下拉部分宽度,使内容能够显示完全
一般的情况下,如果下拉框的选项的文字太长,下拉框ComboBox的Width宽度属性我们又不想要改变(默认不变),下拉选项的文字内容就会被截剪,如下图所示: 解决办法: 1.自动判断下拉选项的文字长度 ...
- easyui combobox点击输入框弹出下拉框
由于easyui combobox需要点击下拉箭头才能下拉,不能像select标签那样点击输入框就下拉,所以觉得不太方便,查看了一下,combobox弹出框是一个div,原本想在他的输入框的点击事件中 ...
- 修改select下拉框的下拉按钮
ie上的下拉框下拉按钮真是太丑了,如何把他自定义一下呢? 首先,把浏览器自带的下拉框去掉: select::-ms-expand { display: none; } 接下来,用自己喜欢的下拉图片去 ...
- jquery带下拉菜单和焦点图
jQuery,下拉菜单,二级菜单,索引按钮,焦点图代码,jquery带下拉菜单和焦点图是一款顶部通栏带二级下拉菜单和banner导航菜单代码. JQuery特效代码来源:http://www.huiy ...
- Bootstrap单按钮的下拉菜单
简介 把任意一个按钮放入 .btn-group 中,然后加入适当的菜单标签,就可以让按钮作为菜单的触发器了. 插件依赖 按钮式下拉菜单依赖下拉菜单插件 ,因此需要将此插件包含在你所使用的 Bootst ...
随机推荐
- SQL Server里的 ISNULL 与 NULLIF
SQL Server 中有两个參数,语法: ISNULL(check_expression, replacement_value) check_expression 与 replacement ...
- hive 配置文件以及join中null值的处理
一.Hive的參数设置 1. 三种设定方式:配置文件 · 用户自己定义配置文件:$HIVE_CONF_DIR/hive-site.xml · 默认配置文件:$HIVE_CONF_DIR/hi ...
- MapReduce输出格式
针对前面介绍的输入格式,MapReduce也有相应的输出格式.默认情况下只有一个 Reduce,输出只有一个文件,默认文件名为 part-r-00000,输出文件的个数与 Reduce 的个数一致. ...
- Java基础知识强化之集合框架笔记27:ArrayList集合练习之去除ArrayList集合中的重复字符串元素
1. 去除ArrayList集合中的重复字符串元素(字符串内容相同) 分析: (1)创建集合对象 (2)添加多个字符串元素(包含重复的) (3)创建新的集合 (4)遍历旧集合,获取得到每一个元素 (5 ...
- C#学习第一天
主要看了一些关于C#的发展期情况,对这门语言有了初步的了解,下面慢慢道来. 首先是C#语言的特点,相比较其他的语言,C#具有以下突出的特点: 1.语法简洁,不允许直接操作内存,去掉了指针操作: 2.彻 ...
- Adb工具常用操作(一)
一.启动或关闭server 1.3 Android SDK中的常用命令行工具 在<Android SDK安装目录>\tools目录中带了很多命令行工具.虽然一般的开发人员并不需要完全掌握 ...
- (转)ecshop刷新页面出现power by ecshop和链接的解决办法
当小伙伴在使用echop模板进行修改的时候,如果你删掉底部自带版权后,再调试程序刷新界面的时候,时不时就会冒出一个power by ecshop,而且是带有链接的,很不舒服,所以需要去掉,下面是最简单 ...
- angularjs kindEditor 中自定义按钮 弹出dialog
1.angular-kindeditor.js 第38行左右加 editorConfig.items = ["placehoder"]; 2.en.js 第234行 placeho ...
- 绘图quartz之加水印
实现在图片上加一个水印 并存在document的路径下 同时在手机相册中也存一份 //首先开启imageContext找到图片 UIGraphicsBeginImageContext( ...
- 移动端touchstar、touchmove、touchend 事件如果页面有滚动时不让触发 touchend 事件。
/*仅适用于内容中点击元素.对于拖动等元素,需要自行在页面处理. * 主要是绑定touchstart和touchmove事件,并判断用户按下之后手指移动了多少像素. * 如果手指移动距离小于10像素, ...