G
Guest
Here is my goal:
I want a combo box that has a font size of 8.25pt
When the user clicks the dropdown I want the size to change to 15pt
Simple I thought.
So I Created the DropDown Event to handle the font size to change to 15pt.
Then I Created the SelecttionChangeCommitted Event to handle the font size
to change back to 8.25pt.
The problem that I have is if the user clicks on the combobox, the dropdown
event is fired and the font changes to 15pt. But if the user clicks on the
combo box again (or the form or another control) the dropdown hides but the
font doesn't change because the value for the control never changed. Now I
can handle the LostFocus event to monitor if they click on another control.
But if they click on the combo box or the form what event gets fired? I'm
looking for a dropdownhide event or something. (Note: onClick event only
fires when dropdown is dropped.)
Bellow is sample code. When you run it click on the combo box, then click
either on the combo box again (without selecting somthing) or on the form.
**********************************************************
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Test
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ComboBox comboBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.Items.AddRange(new object[] {
"Test1",
"Test2",
"Test3",
"Test4",
"Test5",
"Test6"});
this.comboBox1.Location = new System.Drawing.Point(52, 48);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 21);
this.comboBox1.TabIndex = 0;
this.comboBox1.DropDown += new
System.EventHandler(this.comboBox1_DropDown);
this.comboBox1.SelectionChangeCommitted += new
System.EventHandler(this.comboBox1_SelectionChangeCommitted);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.comboBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void comboBox1_DropDown(object sender, System.EventArgs e)
{
Font newFont = new Font(comboBox1.Font.FontFamily.Name,15F);
comboBox1.Font = newFont;
}
private void comboBox1_SelectionChangeCommitted(object sender,
System.EventArgs e)
{
Font newFont = new Font(comboBox1.Font.FontFamily.Name,8.25F);
comboBox1.Font = newFont;
}
}
}
************************************************************
Thanks
KeithH
I want a combo box that has a font size of 8.25pt
When the user clicks the dropdown I want the size to change to 15pt
Simple I thought.
So I Created the DropDown Event to handle the font size to change to 15pt.
Then I Created the SelecttionChangeCommitted Event to handle the font size
to change back to 8.25pt.
The problem that I have is if the user clicks on the combobox, the dropdown
event is fired and the font changes to 15pt. But if the user clicks on the
combo box again (or the form or another control) the dropdown hides but the
font doesn't change because the value for the control never changed. Now I
can handle the LostFocus event to monitor if they click on another control.
But if they click on the combo box or the form what event gets fired? I'm
looking for a dropdownhide event or something. (Note: onClick event only
fires when dropdown is dropped.)
Bellow is sample code. When you run it click on the combo box, then click
either on the combo box again (without selecting somthing) or on the form.
**********************************************************
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Test
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ComboBox comboBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.Items.AddRange(new object[] {
"Test1",
"Test2",
"Test3",
"Test4",
"Test5",
"Test6"});
this.comboBox1.Location = new System.Drawing.Point(52, 48);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 21);
this.comboBox1.TabIndex = 0;
this.comboBox1.DropDown += new
System.EventHandler(this.comboBox1_DropDown);
this.comboBox1.SelectionChangeCommitted += new
System.EventHandler(this.comboBox1_SelectionChangeCommitted);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.comboBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void comboBox1_DropDown(object sender, System.EventArgs e)
{
Font newFont = new Font(comboBox1.Font.FontFamily.Name,15F);
comboBox1.Font = newFont;
}
private void comboBox1_SelectionChangeCommitted(object sender,
System.EventArgs e)
{
Font newFont = new Font(comboBox1.Font.FontFamily.Name,8.25F);
comboBox1.Font = newFont;
}
}
}
************************************************************
Thanks
KeithH