Q: Character Casing in a ComboBox

  • Thread starter Thread starter Visual Systems AB \(Martin Arvidsson\)
  • Start date Start date
V

Visual Systems AB \(Martin Arvidsson\)

Hi!

Is it possible to enable Charater Casing in a ComboBox, if, how?

As of now i am using KeyUp event to make sure that the char entered is
Uppercase.

Regards
Martin Arvidsson
 
Is it possible to enable Charater Casing in a ComboBox, if, how?

You can enable the OS support for this by deriving your own control class
from Combobox, override the CreateParams property and include the
CBS_UPPERCASE style flag.


Mattias
 
A short example would be great, since i am kinda new to C#

Regards
Martin
 
Martin,
A short example would be great, since i am kinda new to C#

Here you go:

using System;
using System.Windows.Forms;

class UpperComboBox : ComboBox {
protected override CreateParams CreateParams {
get {
const int CBS_UPPERCASE = 0x2000;
CreateParams cp = base.CreateParams;
cp.Style |= CBS_UPPERCASE;
return cp;
}
}
}

class Demo : Form {
Demo() {
Controls.Add(new UpperComboBox());
}

[STAThread] static void Main() {
Application.Run(new Demo());
}
}


Mattias
 
Back
Top