Hi,
Although this is possible theoretically, it is not preferred. I would recommend you to use C1ComboBox which is part of C1Input. If that is not possible refer this code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
List<Person> Persons = Person.GetRandomList();
foreach(var person in Persons)
{
var opn = new CustomInputOptionHost(person.Image, person.Name);
_icb.Items.Add(opn);
}
}
}
public class CustomInputOptionHost : C1.Win.C1InputPanel.InputControlHost
{
public CustomInputOptionHost(Image img, string txt)
: base(new CustomInputOption(img, txt))
{
this.Height = 40;
}
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
this.BackColor = SystemColors.MenuHighlight;
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
this.BackColor = Color.White;
}
}
public class Person
{
public string Name { get; set; }
public Bitmap Image { get; set; }
internal static List<Person> GetRandomList()
{
var Persons = new List<Person>();
for(int i = 0; i< 100; i++)
{
Persons.Add(new Person()
{
Name = Guid.NewGuid().ToString(),
Image = PadImage(new Bitmap(20, 20))
});
}
return Persons;
}
internal static Bitmap PadImage(Bitmap originalImage)
{
var largestDimension = Math.Max(originalImage.Height, originalImage.Width);
var squareSize = new Size(largestDimension, largestDimension);
var squareImage = new Bitmap(squareSize.Width, squareSize.Height);
using (Graphics graphics = Graphics.FromImage(squareImage))
{
graphics.FillRectangle(Brushes.Green, 0, 0, squareSize.Width, squareSize.Height);
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.DrawImage(
originalImage,
(squareSize.Width / 2) - (originalImage.Width / 2),
(squareSize.Height / 2) - (originalImage.Height / 2),
originalImage.Width,
originalImage.Height
);
}
return squareImage;
}
}
public class CustomInputOption : UserControl
{
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this._pb = new System.Windows.Forms.PictureBox();
this._lb = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this._pb)).BeginInit();
this.SuspendLayout();
//
// _pb
//
this._pb.Location = new System.Drawing.Point(0, 0);
this._pb.Name = "_pb";
this._pb.Size = new System.Drawing.Size(40, 31);
this._pb.TabIndex = 0;
this._pb.TabStop = false;
this._pb.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
//
// _lb
//
this._lb.Location = new System.Drawing.Point(41, 0);
this._lb.Name = "_lb";
this._lb.Size = new System.Drawing.Size(268, 31);
this._lb.TabIndex = 1;
this._lb.Text = "label1";
this._lb.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// CustomInputOption
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this._lb);
this.Controls.Add(this._pb);
this.Name = "CustomInputOption";
this.Size = new System.Drawing.Size(321, 31);
((System.ComponentModel.ISupportInitialize)(this._pb)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox _pb;
private System.Windows.Forms.Label _lb;
public CustomInputOption()
{
InitializeComponent();
}
protected override void OnMouseEnter(EventArgs e)
{
this.Parent.BackColor = Color.White;
this.BackColor = SystemColors.Highlight;
}
public CustomInputOption(Image image, string text)
{
InitializeComponent();
Text = text;
Image = image;
}
public override string Text
{
get
{
return _lb.Text;
}
set
{
_lb.Text = value;
}
}
public Image Image
{
get
{
return _pb.Image;
}
set
{
_pb.Image = value;
}
}
}
~nilay