473,385 Members | 1,311 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

.NET 1.1 OwnerDraw ComboBox

I wrote a class that inherits ComboBox to create a dropdown that contains
both an image and a text description. This is for an IE browser toolbar. I
use the OwnerDrawFixed method to do this.

The first time click the arrow for the drop down, and shows an empty
dropdown, and immediately closes it. The second time I click the arrow, it
works perfectly. It does this same behavior on Vista, XP, IE6 and IE7.

I'm stumped, I'm sure there is some type of a timing problem, but I'll be
darned if I can figure out why the drop down area is not drawn the first time
I click the arrow. Any help greatly appreciated.

protected override void OnDrawItem(DrawItemEventArgs ea)
{
try
{
int spacer = 5;
ImageComboItem item = (ImageComboItem)Items[ea.Index];
float width = item.Icon.Width + spacer +
ea.Graphics.MeasureString(item.Text, ea.Font).Width + spacer;
if(width this.DropDownWidth)
{
this.DropDownWidth = Convert.ToInt32(Math.Ceiling(width));
}

ea.DrawBackground();
ea.DrawFocusRectangle();
Rectangle bounds = ea.Bounds;
ea.Graphics.DrawImage(item.Icon, bounds.Left, bounds.Top,
item.Icon.Width, item.Icon.Height);
ea.Graphics.DrawString(item.Text, ea.Font, new SolidBrush(ea.ForeColor),
bounds.Left + item.Icon.Width + spacer, bounds.Top);

base.OnDrawItem(ea);
}
catch(Exception Ex)
{
EventLog myEventLog = new EventLog("Application", ".", "ToolBar Error");
myEventLog.WriteEntry(Ex.ToString(), EventLogEntryType.Error);
}
}

Dec 26 '07 #1
0 1459

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: anand | last post by:
Hi All, Are ownerdraw buttons supported in C# ? I have an active X control which I would like to use in CSharp. Buttons have a style BS_OWNERDRAW, and to do custom drawing you have to...
0
by: Apollo440 | last post by:
If MenuItem.OwnerDraw Property is true,.NET framework does not recognize the overlapped accelerator keys. Is there a workaround? eg) +------+ |&Test | <- |&Tea | <- MenuItems has...
2
by: Stuart Norris | last post by:
Dear Group, I am new to c# and windows form designer - coming from a Motif background. I am attempting to develop an application for a touch screen and I need to have a menu system with a...
2
by: jm | last post by:
There are properties for OwnerDraw on ContextMenu items. I know it can be done with regular menus. I cannot find anyone doing it with the systray icon contextmenu (notifyicon.) Is it possible to...
0
by: Michel | last post by:
I come back with a new question regarding my OwnerDraw menu. That is a classical ownerDraw menu to add icon and some other color properties. My feature is to color all the menu bar with the...
2
by: Peter Proost | last post by:
Hi group, I've got this ownerdraw menu module which I got from a site and modified to my personal needs, but the only problem I'm having is with the lines in a menu, when you type - as text, it...
1
by: Lars Netzel | last post by:
Hi! In VB.NET want to draw my own items in a ComboBox I have added a ComboBox to the Form with this. -----------------------------------------------------------------------------------...
0
by: genojoe | last post by:
This code is derived from: ms-help://MS.VSCC.2003/MS.MSDNQTR.2005JUL.1033/cpref/html/frlrfSystemWindowsFormsMenuItemClassOwnerDrawTopic.htm The sample works as presented but does not contain a...
1
by: tmda | last post by:
I'm using OwnerDraw for some customization in my ListView - adding color to item backgrounds. I'm using the ListView specifically for it's OwnerDraw capability. I originally was using the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.