首页 技术 正文
技术 2022年11月12日
0 收藏 901 点赞 3,888 浏览 6155 个字

原文地址: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文件

  1. //ComboBoxDIY.cs
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Data;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace WindowsApplication7
  10. {
  11. public partial class ComboBoxDIY : UserControl
  12. {
  13. public bool buttondown = false;
  14. public ComboBoxDIY()
  15. {
  16. InitializeComponent();
  17. this.listBox1.Visible = false;
  18. this.vScrollBar1.Visible = false;
  19. }
  20. private void button1_Click(object sender, EventArgs e)
  21. {
  22. //下拉按钮未曾按下
  23. if (this.buttondown==false)
  24. {
  25. //listbox所有数据的项数
  26. int count = this.listBox1.Items.Count;
  27. //获取listbox所能显示的项数
  28. int displaycount = this.listBox1.Height / this.listBox1.ItemHeight;
  29. //滚动条显示的最大值
  30. int scrollmax = 0;
  31. //垂直方向上显示内容数目大于所能显示的数目时
  32. //垂直滚动条直接可见
  33. if (count > displaycount)
  34. {
  35. scrollmax = count – 1;
  36. this.vScrollBar1.Visible = true;
  37. }
  38. this.vScrollBar1.LargeChange = displaycount;
  39. this.vScrollBar1.Maximum = scrollmax;
  40. this.vScrollBar1.Minimum = 0;
  41. this.vScrollBar1.Scroll += new ScrollEventHandler(vscroll);
  42. this.listBox1.Visible = true;
  43. //下拉按钮按下
  44. this.buttondown = true;
  45. }
  46. //下拉按钮已按下
  47. else
  48. {
  49. if(this.vScrollBar1.Visible)this.vScrollBar1.Visible = false;
  50. this.listBox1.Visible = false;
  51. //下拉按钮弹起
  52. this.buttondown = false;
  53. }
  54. }
  55. private void vscroll(object sender, ScrollEventArgs e)
  56. {
  57. //ScrollBar控制listBox滚动
  58. this.listBox1.TopIndex=e.NewValue;
  59. }
  60. private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  61. {
  62. //文本框显示选择结果
  63. this.textBox1.Text =this.listBox1.Items[this.listBox1.SelectedIndex].ToString();
  64. this.vScrollBar1.Visible = false;
  65. this.listBox1.Visible = false;
  66. //下拉按钮弹起
  67. this.buttondown = false;
  68. }
  69. }
  70. }

//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文件

  1. //ComboBoxDIY.Designer.cs
  2. namespace WindowsApplication7
  3. {
  4. partial class ComboBoxDIY
  5. {
  6. /// <summary>
  7. /// 必需的设计器变量。
  8. /// </summary>
  9. private System.ComponentModel.IContainer components = null;
  10. /// <summary>
  11. /// 清理所有正在使用的资源。
  12. /// </summary>
  13. /// <param name=”disposing”>如果应释放托管资源,为 true;否则为 false。</param>
  14. protected override void Dispose(bool disposing)
  15. {
  16. if (disposing && (components != null))
  17. {
  18. components.Dispose();
  19. }
  20. base.Dispose(disposing);
  21. }
  22. #region 组件设计器生成的代码
  23. /// <summary>
  24. /// 设计器支持所需的方法 – 不要
  25. /// 使用代码编辑器修改此方法的内容。
  26. /// </summary>
  27. private void InitializeComponent()
  28. {
  29. this.button1 = new System.Windows.Forms.Button();
  30. this.textBox1 = new System.Windows.Forms.TextBox();
  31. this.listBox1 = new System.Windows.Forms.ListBox();
  32. this.vScrollBar1 = new System.Windows.Forms.VScrollBar();
  33. this.SuspendLayout();
  34. //
  35. // button1
  36. //
  37. this.button1.Location = new System.Drawing.Point(85, 0);
  38. this.button1.Name = “button1”;
  39. this.button1.Size = new System.Drawing.Size(65, 44);
  40. this.button1.TabIndex = 0;
  41. this.button1.Text = “▼”;
  42. this.button1.UseVisualStyleBackColor = true;
  43. this.button1.Click += new System.EventHandler(this.button1_Click);
  44. //
  45. // textBox1
  46. //
  47. this.textBox1.Font = new System.Drawing.Font(“宋体”, 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  48. this.textBox1.Location = new System.Drawing.Point(0, 0);
  49. this.textBox1.Name = “textBox1”;
  50. this.textBox1.Size = new System.Drawing.Size(88, 44);
  51. this.textBox1.TabIndex = 1;
  52. //
  53. // listBox1
  54. //
  55. this.listBox1.Font = new System.Drawing.Font(“宋体”, 24F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  56. this.listBox1.FormattingEnabled = true;
  57. this.listBox1.ItemHeight = 33;
  58. this.listBox1.Items.AddRange(new object[] {
  59. “0”,
  60. “1”,
  61. “2”,
  62. “3”,
  63. “4”,
  64. “5”,
  65. “6”,
  66. “7”,
  67. “8”,
  68. “9”});
  69. this.listBox1.Location = new System.Drawing.Point(0, 44);
  70. this.listBox1.Name = “listBox1”;
  71. this.listBox1.Size = new System.Drawing.Size(148, 103);
  72. this.listBox1.TabIndex = 2;
  73. this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
  74. //
  75. // vScrollBar1
  76. //
  77. this.vScrollBar1.Location = new System.Drawing.Point(85, 44);
  78. this.vScrollBar1.Name = “vScrollBar1”;
  79. this.vScrollBar1.Size = new System.Drawing.Size(63, 103);
  80. this.vScrollBar1.TabIndex = 3;
  81. //
  82. // UserControl1
  83. //
  84. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  85. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  86. this.Controls.Add(this.vScrollBar1);
  87. this.Controls.Add(this.listBox1);
  88. this.Controls.Add(this.textBox1);
  89. this.Controls.Add(this.button1);
  90. this.Name = “UserControl1”;
  91. this.Size = new System.Drawing.Size(149, 148);
  92. this.ResumeLayout(false);
  93. this.PerformLayout();
  94. }
  95. #endregion
  96. private System.Windows.Forms.Button button1;
  97. private System.Windows.Forms.TextBox textBox1;
  98. private System.Windows.Forms.ListBox listBox1;
  99. private System.Windows.Forms.VScrollBar vScrollBar1;
  100. }
  101. }
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,958
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,482
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,328
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,111
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,743
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,776