473,408 Members | 2,839 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,408 software developers and data experts.

Custom Combo Box

Hello Sir,
Please help me ?
I am createing a custom combo box control in c#.net 3.0 by inherit combo box. in this control i am using OnPaint and OnPaintBackground to paint combo button .
The problem came when paint event fire's, it Black the inner combo box color(is this is nonclient area?).and not show back color in combo's inner area.
and here dropdownstyle=dropdown.

But when i set dropdownstyle=dropdownlist then it will fine. now the problem with this is it will not show the text in combox after drop down list is closed.
Now couldn't find the way how proceds further.
Thanks.
Dec 24 '08 #1
7 13237
vekipeki
229 Expert 100+
You could post some of your code to make it easier to find the problem. Something like this should work anyway (at least when talking about "black background":

Expand|Select|Wrap|Line Numbers
  1. public class CustomCombo : ComboBox
  2. {
  3.     public CustomCombo()
  4.     {
  5.         SetStyle(ControlStyles.UserPaint | 
  6.              ControlStyles.SupportsTransparentBackColor | 
  7.              ControlStyles.OptimizedDoubleBuffer, true);
  8.         this.BackColor = Color.Transparent;
  9.     }
  10.  
  11.     protected override void OnPaint(PaintEventArgs e)
  12.     {
  13.         // custom paint
  14.     }
  15.  
  16.     protected override void OnPaintBackground
  17.             (PaintEventArgs pevent)
  18.     {
  19.         base.OnPaintBackground(pevent);
  20.         // some custom paint code after this
  21.     }
  22. }
  23.  
Dec 24 '08 #2
Thanks viki:
here is my code:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Diagnostics;
  10.  
  11. namespace ComboBoxControl
  12. {
  13.     public partial class ComboBoxControl1 : ComboBox
  14.     {
  15.         private static string strcmbo = "";
  16.  
  17.         #region Variables
  18.  
  19.         ControlStyles styleTrue = ControlStyles.AllPaintingInWmPaint|
  20.             ControlStyles.DoubleBuffer |
  21.             ControlStyles.FixedHeight |
  22.             ControlStyles.ResizeRedraw |  
  23.           ControlStyles.UserPaint;   
  24.      private Rectangle m_clickButton;
  25.         private Color _ButtonBackColor;
  26.  
  27.         #region Class Constructor
  28.         public ComboBoxControl1()
  29.         {
  30.             InitializeComponent();
  31.  
  32.             SetStyle(styleTrue, true);
  33.             SetStyle(ControlStyles.Selectable, false); //to recive focuse if true
  34.  
  35.         }
  36.         #endregion
  37.  
  38.         #region Override Events
  39.  
  40.  
  41.         protected override void OnPaintBackground(PaintEventArgs pevent)
  42.         {
  43.             base.OnPaintBackground(pevent);
  44.  
  45.             Graphics g = pevent.Graphics;
  46.             BorderWidth = comboBox1.Width;
  47.             Rectangle rect = new Rectangle(comboBox1.Location.X, comboBox1.Location.Y, BorderWidth, comboBox1.Height + 3);
  48.             ControlPaint.DrawBorder(g, rect, _ButtonBackColor, ButtonBorderStyle.Solid);
  49.  
  50.             if (this.Text != "")
  51.             {
  52.                 strcmbo = this.Text;
  53.                 comboBox1.Text = strcmbo;
  54.             }
  55.         }
  56.  
  57.         protected override void OnPaint(PaintEventArgs e)
  58.         {
  59.  
  60.             OnPaintBackground(e);
  61.             OnPaintComboButton(e);
  62.  
  63.             if (this.Text != "")
  64.             {
  65.                 strcmbo = this.Text;
  66.                 comboBox1.Text = strcmbo;
  67.             }
  68.  
  69.         }
  70.  
  71.  
  72.  
  73.         #endregion
  74.  
  75.         #region Virtual Events
  76.         protected virtual void OnPaintComboButtonBackground(System.Windows.Forms.PaintEventArgs pevent)
  77.         {
  78.             Graphics g = pevent.Graphics;
  79.             Rectangle rc = ClientRectangle;
  80.             g.FillRectangle(new SolidBrush(BorderColor), rc.Right - 17, rc.Y + 2, 15, rc.Height - 4);
  81.  
  82.         }
  83.  
  84.         #endregion
  85.  
  86.     }
  87. }
  88.  
this is main code when i paint combo right side button then it will black the inner color of combo?
please fine some solutions.
Is this non client area of combo box.
Dec 26 '08 #3
Curtis Rutland
3,256 Expert 2GB
Please use [code] tags when you post code.

MODERATOR
Dec 26 '08 #4
Thanks Alias.for your Suggestion
Dec 29 '08 #5
Frinavale
9,735 Expert Mod 8TB
I've moved your thread to the C# forum.
Dec 30 '08 #6
RedSon
5,000 Expert 4TB
Ok... I have no idea what you are asking about. Can you describe or take a screen shot of what it looks like now, and can you describe or make an example of what you want it to look like?
Dec 30 '08 #7
Thanks Everybody, i find solution by redrawing the the text in the combo and overrids the Onpaint event in dropdown style.
Thank
Happy New Year
Dec 31 '08 #8

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

Similar topics

0
by: CGuy | last post by:
URGENT HELP REQUIRED FROM GURUS Hi, I have a custom object that implements ICollection and IListSource. This object has also an enumerator defined for it which implements IEnumerator and...
2
by: Ron | last post by:
I need to create a custom combo box that lists items and subitems along with descriptions in a particular format. For example Format of the Data Listed In Combo Box: Item Description...
0
by: TT (Tom Tempelaere) | last post by:
Hi, I have made my custom combo box column based on several articles (http://msdn.microsoft.com/smartclient/community/wffaq/ctrlsp.aspx & other articles). I derived the custom column from...
1
by: Dan Keeley | last post by:
Hi I'm trying to create a custom combo box so i can display a nice text name but return the actual key value for the database. So i have this class ( At the bottom of this post ) How do i...
0
by: steve | last post by:
i've built serveral controls designed for touch-screen use. i have a quirk with one and am not sure how to solve the problem. it is a drop-down style combo box that filters list items as the input...
9
by: Duncan Barnes-Ceeney | last post by:
I’m having problems with a custom Combo box. The main problem is that I want to modify the look of the combo which includes the size of the button. To do this I have inherited from the standard...
3
by: Lee | last post by:
Hi, I am wondering whether it is easily achievable to create a custom combo box control which contains certain items preloaded. Basically I have a form which will contains several combos, each...
3
by: saurabhnsit2002 | last post by:
Can anyone help me about how to create combo box with its items as checked boxes or radio buttons. This has to be done in C#. I have seen something similar to this named custom combo boxes but they...
6
by: Smokey Grindle | last post by:
Say I have a combo box with the following simple object Public class MyObject public ID as integer public Name as string public overrides sub ToString() as string return name end sub end...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.