Custom Combo Box 
December 24th, 2008, 10:58 AM
| | Newbie | | Join Date: Dec 2008
Posts: 4
| | 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.
Last edited by Frinavale; December 30th, 2008 at 07:04 PM.
Reason: moved to C# forum
| 
December 24th, 2008, 01:22 PM
|  | Expert | | Join Date: Nov 2007
Posts: 230
| |
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": -
public class CustomCombo : ComboBox
-
{
-
public CustomCombo()
-
{
-
SetStyle(ControlStyles.UserPaint |
-
ControlStyles.SupportsTransparentBackColor |
-
ControlStyles.OptimizedDoubleBuffer, true);
-
this.BackColor = Color.Transparent;
-
}
-
-
protected override void OnPaint(PaintEventArgs e)
-
{
-
// custom paint
-
}
-
-
protected override void OnPaintBackground
-
(PaintEventArgs pevent)
-
{
-
base.OnPaintBackground(pevent);
-
// some custom paint code after this
-
}
-
}
-
| 
December 26th, 2008, 04:10 AM
| | Newbie | | Join Date: Dec 2008
Posts: 4
| |
Thanks viki:
here is my code: -
using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Drawing;
-
using System.Data;
-
using System.Linq;
-
using System.Text;
-
using System.Windows.Forms;
-
using System.Diagnostics;
-
-
namespace ComboBoxControl
-
{
-
public partial class ComboBoxControl1 : ComboBox
-
{
-
private static string strcmbo = "";
-
-
#region Variables
-
-
ControlStyles styleTrue = ControlStyles.AllPaintingInWmPaint|
-
ControlStyles.DoubleBuffer |
-
ControlStyles.FixedHeight |
-
ControlStyles.ResizeRedraw |
-
ControlStyles.UserPaint;
-
private Rectangle m_clickButton;
-
private Color _ButtonBackColor;
-
-
#region Class Constructor
-
public ComboBoxControl1()
-
{
-
InitializeComponent();
-
-
SetStyle(styleTrue, true);
-
SetStyle(ControlStyles.Selectable, false); //to recive focuse if true
-
-
}
-
#endregion
-
-
#region Override Events
-
-
-
protected override void OnPaintBackground(PaintEventArgs pevent)
-
{
-
base.OnPaintBackground(pevent);
-
-
Graphics g = pevent.Graphics;
-
BorderWidth = comboBox1.Width;
-
Rectangle rect = new Rectangle(comboBox1.Location.X, comboBox1.Location.Y, BorderWidth, comboBox1.Height + 3);
-
ControlPaint.DrawBorder(g, rect, _ButtonBackColor, ButtonBorderStyle.Solid);
-
-
if (this.Text != "")
-
{
-
strcmbo = this.Text;
-
comboBox1.Text = strcmbo;
-
}
-
}
-
-
protected override void OnPaint(PaintEventArgs e)
-
{
-
-
OnPaintBackground(e);
-
OnPaintComboButton(e);
-
-
if (this.Text != "")
-
{
-
strcmbo = this.Text;
-
comboBox1.Text = strcmbo;
-
}
-
-
}
-
-
-
-
#endregion
-
-
#region Virtual Events
-
protected virtual void OnPaintComboButtonBackground(System.Windows.Forms.PaintEventArgs pevent)
-
{
-
Graphics g = pevent.Graphics;
-
Rectangle rc = ClientRectangle;
-
g.FillRectangle(new SolidBrush(BorderColor), rc.Right - 17, rc.Y + 2, 15, rc.Height - 4);
-
-
}
-
-
#endregion
-
-
}
-
}
-
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.
| 
December 26th, 2008, 02:12 PM
|  | Forum Leader | | Join Date: Apr 2008 Location: San Antonio, TX (USA) Age: 24
Posts: 2,486
| |
Please use [code] tags when you post code.
MODERATOR
| 
December 29th, 2008, 03:17 AM
| | Newbie | | Join Date: Dec 2008
Posts: 4
| |
Thanks Alias.for your Suggestion
| 
December 30th, 2008, 07:04 PM
|  | Site Moderator | | Join Date: Oct 2006 Location: Canada :)
Posts: 4,157
| |
I've moved your thread to the C# forum.
| 
December 30th, 2008, 07:19 PM
|  | Site Moderator | | Join Date: Jan 2007 Location: America
Posts: 3,239
| |
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?
| 
December 31st, 2008, 03:33 AM
| | Newbie | | Join Date: Dec 2008
Posts: 4
| |
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
|  | | Thread Tools | Search this Thread | | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 220,662 network members.
|