Hi
I built a custom control 'ChooseBox' that inherits from ComboBox. When I select an item from a choosebox control, the selected item does not show up; I mean, the background is blue, but the text is hidden. I have checked my backcolor and forecolor, and don't see anything wrong there. I know this is probably a simple q. Can anybody help?
Andy
AndyPosted Sep 11, 2007, 8:26 AM
Mike G:
Here is the code. Thanks for your help! (I may have one too many/too few braces; I had to reformat the code for this window.
Andy
using
System;using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using UtilityCode;
namespace
WindowsControlLibrary{
public class ChooseBox : ComboBox
{
public ChooseBox()
{
this.CausesValidation = true;
this.GotFocus += new EventHandler(ChooseBox_GotFocus);
this.LostFocus += new EventHandler(ChooseBox_LostFocus);
this.DropDown += new EventHandler(ChooseBox_DropDown);
this.Font = new Font("Andale Mono", 11F, FontStyle.Regular);
} // constructor void ChooseBox_GotFocus(object sender, EventArgs e)
{
this.BackColor = Color.Yellow;
this.Font = new Font(this.Font, FontStyle.Bold);
} // method: GotFocus void ChooseBox_LostFocus(object sender, EventArgs e)
{
this.BackColor = Color.White;
this.Font = new Font(this.Font, FontStyle.Regular);
} // method: LostFocus protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
bool retValue = base.ProcessCmdKey(ref msg, keyData);
const int WM_KEYDOWN = 0x100;
const int WM_SYSKEYDOWN = 0x104;
if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
switch (keyData)
{
case Keys.Down:
SendKeys.Send("{TAB}");
retValue = true;
break; case Keys.Up:
SendKeys.Send("+{TAB}");
retValue = true;
break; case Keys.Enter:
SendKeys.Send("{TAB}");
retValue = true; // setting retValue =true here prevents a beep
break;
}
return retValue;
} // method: ProcessCmdKey void ChooseBox_DropDown(object sender, EventArgs e)
{
this.BackColor = Color.White;
this.Font = new Font(this.Font, FontStyle.Regular);
}
}
}
Mike GoldPosted Sep 11, 2007, 1:28 AM