jhasty Posted March 10, 2003 Posted March 10, 2003 I am trying to implement a ComboBox control with 6 items and no editing by the user. When I select an item, I want it to display in normal (black on white), not selected (white on blue) colors. I have tried several ugly kludges, none of which work. Does anyone know how to do this? Quote
TechnoTone Posted March 10, 2003 Posted March 10, 2003 How about just moving the focus away from the control? Quote TT (*_*) There are 10 types of people in this world; those that understand binary and those that don't.
jhasty Posted March 10, 2003 Author Posted March 10, 2003 Yeah, I think that works, but I would like to have the text display in normal color immediately, as soon as the item is selected. All of the ComboBox events seem to fire before the text is selected, so I don't have a hook to automatically deselect the text. I'm thinking about placing some other control where it will be overlapped by the combobox's dropdown box, and using the overlapped control's paint event. Maybe I just shouldn't be so picky, and learn to like white on blue text! Quote
*Gurus* divil Posted March 10, 2003 *Gurus* Posted March 10, 2003 You should, really. The white on blue is configuration in the display settings, so any user that doesn't like that highlight colour is free to change it, and probably already will have. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
jhasty Posted March 11, 2003 Author Posted March 11, 2003 (edited) This is ugly, but it works. Open a new Windows Form project, put a button and a combobox on the form, put a timer in the tray, and paste in the code below. When the combobox gets control, the timer is enabled. When the user selects a combobox item, or the mouse leaves the combobox, a flag is set. The timer tick event checks the flag, and when it finds the flag set, the focus is moved to the button (thus unselecting the text), and the timer is disabled. Here's the code: Dim FirstTime = True Dim IndexChanged = True Private Sub Form1_Load(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles MyBase.Load ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList ComboBox1.Items.Add("Apple") ComboBox1.Items.Add("Banana") ComboBox1.Items.Add("Cherry") ComboBox1.Items.Add("Date") ComboBox1.SelectedIndex = 0 Timer1.Enabled = True End Sub Private Sub ComboBox1_Enter(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles ComboBox1.Enter Timer1.Enabled = True End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged If Not FirstTime Then IndexChanged = True Else FirstTime = False End If End Sub Private Sub Timer1_Tick(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles Timer1.Tick If IndexChanged Then Button1.Focus() Timer1.Enabled = False IndexChanged = False End If End Sub Private Sub ComboBox1_MouseLeave(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles ComboBox1.MouseLeave Button1.Focus() Timer1.Enabled = False End Sub Edited March 11, 2003 by divil Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.