Help with creating Custom ComboBox

D

David Clegg

I need to have the ability to allow the user to change many colour
attributes of controls, including in many cases attributes that aren't
supported by the standard CF controls. While I've been able to kludge a
custom TextBox control to do what I want (don't ask, its really ugly
<g>), I'm a bit stumped as to how to do it for a ComboBox.

I gather I probably need to create my own ComboBox control by
descending from Control (basically re-inventing the ComboBox wheel then
extending from there), but all my attempts so far have been a bit off
the mark.

I guess what I'm really after is help with the code which implements
much of the standard ComboBox behaviour, so I can then extend it from
there. Otherwise I fear I'd be in a situation where I'd be doing much
unnecessary or sub-optimal coding which could've been easily avoided by
a gentle P/Invoke here or message handler there.

A custom ComboBox template would be ideal, but a push in the right
direction would be just dandy too. All my attempts so far have been not
quite right, so any suggestions would be greatfully received. And all
the examples I've found on the web are controls that extend from
ComboBox, which I don't think will work in this case as I'll have to
implement some custom painting.

--
Cheers,
David Clegg
(e-mail address removed)

Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 :)
Now supports Google Groups searching with Dyna-extend(tm) technology!

QualityCentral. The best way to bug Borland about bugs.
http://qc.borland.com

"When I first heard that Marge was joining the police academy, I
thought it would be fun and zany, like that movie -- Spaceballs. But
instead it was dark and disturbing like that movie, Police Academy." -
Homer Simpson
 
P

Peter Foot [MVP]

At a very basic level you could create a control using a Textbox/Label a
Button and an owner drawn list (www.opennetcf.org/sdf/) which you show/hide
based on the button or user selection.
What you haven't specified is exactly what colour behaviour you require.
From .NETCF SP2 onwards a number of colour properties which were previously
unused were implemented, so while there isn't any designer support you can
set foreground/background colours through code.

Peter
 
D

David Clegg

Peter said:
At a very basic level you could create a control using a
Textbox/Label a Button and an owner drawn list
(www.opennetcf.org/sdf/)
which you show/hide based on the button or
user selection.

Thanks, I'll check it out.
What you haven't specified is exactly what colour
behaviour you require.

In a nutshell, we require our app to have 'Day' and 'Night' settings.
Day settings would have dark text/control borders on white background
(pretty much how controls are normally painted), whereas Night would
require a black background and green text/control borders. So any
controls that don't allow the appropriate elements to have their
properties set, or which don't allow for Owner Draw capabilities have
to be implemented differently to cater for this.

I don't think my boss will be happy to wait until CF 2.0 is released
before we can implement this feature, but it may be worth pitching the
idea to him, considering the task is not as straightforward as he'd
expected.


--
Cheers,
David Clegg
(e-mail address removed)

Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 :)
Now supports Google Groups searching with Dyna-extend(tm) technology!

QualityCentral. The best way to bug Borland about bugs.
http://qc.borland.com

"Heh Heh Heh! Lisa! Vampires are make believe, just like elves and
gremlins and eskimos." - Homer Simpson
 
P

Peter Foot [MVP]

If you are after a blanket change for all items in the ComboBox then you are
in luck as long as you install at least Service Pack 2 to your device
(Service Pack 3 is the latest). Then in your code add:-

comboBox1.BackColor = Color.Black;
comboBox1.ForeColor = Color.Green;

For example in your form constructor after the InitializeComponent method is
called. This affects both the text portion and the drop down list.

Peter
 
D

David Clegg

Peter said:
If you are after a blanket change for all items in the ComboBox then
you are in luck as long as you install at least Service Pack 2 to
your device

Excellent, I'll check it out. While I do have the beginnings of a
custom combobox working, it's extremely kludgy, slower to dropdown than
the WinForms one, and has a few other annoying issues which I'd not
resolved yet. Also I'd rather not get too deeply entrenched in
component development for this task if I can help it.

But for future reference, do you have any good online references for
component development? I already have the OpenNETCF site bookmarked,
and we use the SDF in our product already, so any other references
would be greatfully received. Of particular interest would be ones that
explore building components from the ground up (i.e descend from
Component).

Thanks for all your help.

--
Cheers,
David Clegg
(e-mail address removed)

Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 :)
Now supports Google Groups searching with Dyna-extend(tm) technology!

QualityCentral. The best way to bug Borland about bugs.
http://qc.borland.com

"Being eaten by a crocodile is just like falling asleep, in a blender."
- Homer Simpson
 
D

David Clegg

Peter said:
install at least Service Pack 2 to your device
(Service Pack 3 is the latest).

It would appear that, while I can freely redistribute SP2 to my end
users, I cannot do the same for SP3. Additionally, SP2 must be applied
before SP3 can be. Is this correct?

If so, it's probably best if I target my solution towards SP2 at this
stage.

--
Cheers,
David Clegg
(e-mail address removed)

Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 :)
Now supports Google Groups searching with Dyna-extend(tm) technology!

QualityCentral. The best way to bug Borland about bugs.
http://qc.borland.com

"Being eaten by a crocodile is just like falling asleep, in a blender."
- Homer Simpson
 
D

David Clegg

Tim said:
SP3 does not rely on SP2. Service packs are cumulative, as usual. So
you only need to install SP3.

Thanks. That's what I thought was usually the case, but I read
elsewhere that SP3 required SP2 first.

--
Cheers,
David Clegg
(e-mail address removed)

Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 :)
Now supports Google Groups searching with Dyna-extend(tm) technology!

QualityCentral. The best way to bug Borland about bugs.
http://qc.borland.com

"Here's to alcohol : The cause of, and answer to all of life's
problems." - Homer Simpson
 
T

Tim Wilson

There's a fair amount of information out on the web in relation to custom
component/control development. I don't know of any one article (or series of
articles) that is comprehensive, so here's a decent list of stuff to get you
started.

"Button with a Picture"
http://samples.gotdotnet.com/quickstart/CompactFramework/doc/picturebutton.aspx

"How to Create a Microsoft .NET Compact Framework-based Image Button"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/ImageButton.asp

"Creating a Microsoft .NET Compact Framework-based Animation Control"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/animationcontrol.asp

"Design-time functionality for custom controls in Compact Framework and
SDE."
http://www.intelliprog.com/articles/index.html

"Debugging Custom Controls at Design-Time with the Microsoft .NET Compact
Framework 1.0"
http://msdn.microsoft.com/smartclie...library/en-us/dnnetcomp/html/debugdestime.asp

Other things to look at:
http://www.codeproject.com/netcf/
http://msdn.microsoft.com/library/d..._evtuv/html/etconcustomcontroldevelopment.asp
Google search.

In addition, the OpenNETCF LinkLabel control is a fairly simple control. So
looking at the source for that might be a good start. Just go to the vault
(http://vault.netcf.tv/VaultService/VaultWeb/login.aspx) and login using
"guest" for both username and password. If you're really after a Component,
then you may want to look at the OpenNETCF BatteryMonitor, which is also
pretty simple.
 
D

David Clegg

Tim said:
I don't know of any one article (or series of
articles) that is comprehensive, so here's a decent list of stuff to
get you started.

Thanks Tim.

--
Cheers,
David Clegg
(e-mail address removed)

Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 :)
Now supports Google Groups searching with Dyna-extend(tm) technology!

QualityCentral. The best way to bug Borland about bugs.
http://qc.borland.com

"What about those red balls they have on car aerials so you can spot
your car in a park? I think all cars should have them." - Homer Simpson
 
D

David Clegg

Peter said:
If you are after a blanket change for all items in the ComboBox then
you are in luck as long as you install at least Service Pack 2

Bummer! Not quite good enough. I need to be able to also change the
colour of the combobox border, and colour for the dropdown arrow as
well. Looks like I may have to create my own custom ine instead. I
better go study some of those links Tim posted. :-(

--
Cheers,
David Clegg
(e-mail address removed)

Vote 1 http://cc.borland.com/codecentral/ccweb.exe/listing?id=21489 :)
Now supports Google Groups searching with Dyna-extend(tm) technology!

QualityCentral. The best way to bug Borland about bugs.
http://qc.borland.com

"Hello? Operator! Give me the number for 911!" - Homer Simpson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top