By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,276 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,276 IT Pros & Developers. It's quick & easy.

custom combobox display issue

P: 4
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. Here is the code. Can anybody help?

arevans

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);
}
}
}
Sep 11 '07 #1
Share this Question
Share on Google+
2 Replies


P: 2
dfvdfdfvcbxcvxbxcvbcv gfhfghfgh
Sep 12 '07 #2

Expert 100+
P: 390
Your code has some where backcolor white.may be that is causing error
Sep 12 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.