I'm trying to paint an image inside Combobox in a custom control, I use the following code:
public partial class Jo_ComboBox : ComboBox
{
#region Constructor
public Jo_ComboBox()
{
InitializeComponent();
}
#endregion
#region Fields
bool _IsRequired = false;
bool _IsEmpty = true;
Bitmap _xImg;
#endregion
#region Properties
[Category("Joul_Properties")]
public Bitmap xImg { get { return _xImg; } }
[Category("Joul_Properties")]
public bool IsEmpty { get { return _IsEmpty; } }
[Category("Joul_Properties")]
public bool IsRequired { get { return _IsRequired; } set { _IsRequired = value; } }
#endregion
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
if (IsRequired == true && this.Text == string.Empty)
{
_xImg = Resources._16Exc;
e.Graphics.DrawImage(xImg, new Point(this.Width - 18, 30));
_IsEmpty = true;
}
else
{
_IsEmpty = false;
}
}
#region Events
//OnLeave
protected override void OnLeave(EventArgs e)
{
base.OnLeave(e);
this.Invalidate();
}
#endregion
actually, I got a good result but I noticed that the image is not above the textbox of the Combobox, I noticed that when I tried to change the hight of combobox.
see the video please to know what is the problem:
edit: please see that there is editor area that is covering the image if I change the height