原文地址: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.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;
- }
- }