PC Review


Reply
Thread Tools Rate Thread

Combo box items ( text with images)

 
 
sajin
Guest
Posts: n/a
 
      18th May 2007
Hi All,

I am new to windows forms C# 2005, How can i have a combo box with
image and text

meaning

* 1Star
** 2Start
*** 3Star

i have experimented something. but it shows only images.

Any help will be appreciated

Regards
-Sajin

 
Reply With Quote
 
 
 
 
Morten Wennevik [C# MVP]
Guest
Posts: n/a
 
      18th May 2007
Hi Sajin,

You need to specify DrawMode. OwnerDrawFixed is usually good enough, but use OwnerDrawVariable if the height of the items can vary.

Set DropDownStyle to DropDownList to be able to draw the selected item in the EditBox

Then subscribe to the ComboBox' DrawItem event. It will be called for each item in the list. Use the DrawItemEventArgs to find out what kind of item you are currently drawing and use DrawItemEventArgs.Bounds to position your drawing. You can then draw image and text any way you like. DrawItemEventArgs.State has information of wether the current item is highligted and so on.

If you need more specific information, please ask.



On Fri, 18 May 2007 09:12:50 +0200, sajin <(E-Mail Removed)> wrote:

> Hi All,
>
> I am new to windows forms C# 2005, How can i have a combo box with
> image and text
>
> meaning
>
> * 1Star
> ** 2Start
> *** 3Star
>
> i have experimented something. but it shows only images.
>
> Any help will be appreciated
>
> Regards
> -Sajin
>
>




--
Happy coding!
Morten Wennevik [C# MVP]
 
Reply With Quote
 
sajin
Guest
Posts: n/a
 
      21st May 2007
Hi Morten,

I did as u said, but still i can't show image with text :-(

I added a imageList and added the images in that and assiciated with
combobox , where am i going wrong
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
string[] items;

items = new string[ComboBoxImageList.Images.Count];

for (int i = 0; i < ComboBoxImageList.Images.Count; i++)
{
this.comboBox1.Items.Add(ComboBoxImageList.Images[i]);

}


this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
this.comboBox1.DrawMode = DrawMode.OwnerDrawVariable;
this.comboBox1.ItemHeight =
this.ComboBoxImageList.ImageSize.Height;
this.comboBox1.Width =
this.ComboBoxImageList.ImageSize.Width + 80;
this.comboBox1.MaxDropDownItems =
this.ComboBoxImageList.Images.Count;
}

private void comboBox1_DrawItem(object sender,
DrawItemEventArgs e)
{
if (e.Index != -1)
{

e.Graphics.DrawImage(this.ComboBoxImageList.Images[e.Index],
e.Bounds.Left, e.Bounds.Top);
}
}
}
}



Regards
-Sajin


On May 18, 9:45 pm, "Morten Wennevik [C# MVP]"
<MortenWenne...@hotmail.com> wrote:
> Hi Sajin,
>
> You need to specify DrawMode. OwnerDrawFixed is usually good enough, but use OwnerDrawVariable if the height of the items can vary.
>
> Set DropDownStyle to DropDownList to be able to draw the selected item in the EditBox
>
> Then subscribe to the ComboBox' DrawItem event. It will be called for each item in the list. Use the DrawItemEventArgs to find out what kind of item you are currently drawing and use DrawItemEventArgs.Bounds to position your drawing. You can then draw image and text any way you like. DrawItemEventArgs.State has information of wether the current item is highligted and so on.
>
> If you need more specific information, please ask.
>
>
>
>
>
> On Fri, 18 May 2007 09:12:50 +0200, sajin <s...@iprlab.com> wrote:
> > Hi All,

>
> > I am new to windows forms C# 2005, How can i have a combo box with
> > image and text

>
> > meaning

>
> > * 1Star
> > ** 2Start
> > *** 3Star

>
> > i have experimented something. but it shows only images.

>
> > Any help will be appreciated

>
> > Regards
> > -Sajin

>
> --
> Happy coding!
> Morten Wennevik [C# MVP]- Hide quoted text -
>
> - Show quoted text -



 
Reply With Quote
 
Moty Michaely
Guest
Posts: n/a
 
      21st May 2007
On May 21, 10:27 am, sajin <s...@iprlab.com> wrote:
> Hi Morten,
>
> I did as u said, but still i can't show image with text :-(
>
> I added a imageList and added the images in that and assiciated with
> combobox , where am i going wrong
> using System;
> using System.Collections.Generic;
> using System.ComponentModel;
> using System.Data;
> using System.Drawing;
> using System.Text;
> using System.Windows.Forms;
>
> namespace WindowsApplication1
> {
> public partial class Form1 : Form
> {
> public Form1()
> {
> InitializeComponent();
> }
>
> private void Form1_Load(object sender, EventArgs e)
> {
> string[] items;
>
> items = new string[ComboBoxImageList.Images.Count];
>
> for (int i = 0; i < ComboBoxImageList.Images.Count; i++)
> {
> this.comboBox1.Items.Add(ComboBoxImageList.Images[i]);
>
> }
>
> this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
> this.comboBox1.DrawMode = DrawMode.OwnerDrawVariable;
> this.comboBox1.ItemHeight =
> this.ComboBoxImageList.ImageSize.Height;
> this.comboBox1.Width =
> this.ComboBoxImageList.ImageSize.Width + 80;
> this.comboBox1.MaxDropDownItems =
> this.ComboBoxImageList.Images.Count;
> }
>
> private void comboBox1_DrawItem(object sender,
> DrawItemEventArgs e)
> {
> if (e.Index != -1)
> {
>
> e.Graphics.DrawImage(this.ComboBoxImageList.Images[e.Index],
> e.Bounds.Left, e.Bounds.Top);
> }
> }
> }
>
> }
>
> Regards
> -Sajin
>
> On May 18, 9:45 pm, "Morten Wennevik [C# MVP]"
>
> <MortenWenne...@hotmail.com> wrote:
> > Hi Sajin,

>
> > You need to specify DrawMode. OwnerDrawFixed is usually good enough, but use OwnerDrawVariable if the height of the items can vary.

>
> > Set DropDownStyle to DropDownList to be able to draw the selected item in the EditBox

>
> > Then subscribe to the ComboBox' DrawItem event. It will be called for each item in the list. Use the DrawItemEventArgs to find out what kind of item you are currently drawing and use DrawItemEventArgs.Bounds to position your drawing. You can then draw image and text any way you like. DrawItemEventArgs.State has information of wether the current item is highligted and so on.

>
> > If you need more specific information, please ask.

>
> > On Fri, 18 May 2007 09:12:50 +0200, sajin <s...@iprlab.com> wrote:
> > > Hi All,

>
> > > I am new to windows forms C# 2005, How can i have a combo box with
> > > image and text

>
> > > meaning

>
> > > * 1Star
> > > ** 2Start
> > > *** 3Star

>
> > > i have experimented something. but it shows only images.

>
> > > Any help will be appreciated

>
> > > Regards
> > > -Sajin

>
> > --
> > Happy coding!
> > Morten Wennevik [C# MVP]- Hide quoted text -

>
> > - Show quoted text -


Sajin

I can't see where the text of an item is added? You are adding an
Image item to the combo box items list.
I think that Morten suggested to draw both the image and the text
(using DrawText()).

Therfore, the item added to the list should contain information about
both the image and the text to be displayed. Maybe you can use a
wrapper class to hold the item information.

Feel free to ask any question regarding the custom drawing issue.

Moty

 
Reply With Quote
 
sajin
Guest
Posts: n/a
 
      21st May 2007
Thanks a ton to Morten and Moty....
It works fine. :-))

Regards
-Sajin





On May 21, 1:05 pm, Moty Michaely <Moty...@gmail.com> wrote:
> On May 21, 10:27 am, sajin <s...@iprlab.com> wrote:
>
>
>
>
>
> > Hi Morten,

>
> > I did as u said, but still i can't show image with text :-(

>
> > I added a imageList and added the images in that and assiciated with
> > combobox , where am i going wrong
> > using System;
> > using System.Collections.Generic;
> > using System.ComponentModel;
> > using System.Data;
> > using System.Drawing;
> > using System.Text;
> > using System.Windows.Forms;

>
> > namespace WindowsApplication1
> > {
> > public partial class Form1 : Form
> > {
> > public Form1()
> > {
> > InitializeComponent();
> > }

>
> > private void Form1_Load(object sender, EventArgs e)
> > {
> > string[] items;

>
> > items = new string[ComboBoxImageList.Images.Count];

>
> > for (int i = 0; i < ComboBoxImageList.Images.Count; i++)
> > {
> > this.comboBox1.Items.Add(ComboBoxImageList.Images[i]);

>
> > }

>
> > this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
> > this.comboBox1.DrawMode = DrawMode.OwnerDrawVariable;
> > this.comboBox1.ItemHeight =
> > this.ComboBoxImageList.ImageSize.Height;
> > this.comboBox1.Width =
> > this.ComboBoxImageList.ImageSize.Width + 80;
> > this.comboBox1.MaxDropDownItems =
> > this.ComboBoxImageList.Images.Count;
> > }

>
> > private void comboBox1_DrawItem(object sender,
> > DrawItemEventArgs e)
> > {
> > if (e.Index != -1)
> > {

>
> > e.Graphics.DrawImage(this.ComboBoxImageList.Images[e.Index],
> > e.Bounds.Left, e.Bounds.Top);
> > }
> > }
> > }

>
> > }

>
> > Regards
> > -Sajin

>
> > On May 18, 9:45 pm, "Morten Wennevik [C# MVP]"

>
> > <MortenWenne...@hotmail.com> wrote:
> > > Hi Sajin,

>
> > > You need to specify DrawMode. OwnerDrawFixed is usually good enough, but use OwnerDrawVariable if the height of the items can vary.

>
> > > Set DropDownStyle to DropDownList to be able to draw the selected item in the EditBox

>
> > > Then subscribe to the ComboBox' DrawItem event. It will be called for each item in the list. Use the DrawItemEventArgs to find out what kind of item you are currently drawing and use DrawItemEventArgs.Bounds to position your drawing. You can then draw image and text any way you like. DrawItemEventArgs.State has information of wether the current item is highligted and so on.

>
> > > If you need more specific information, please ask.

>
> > > On Fri, 18 May 2007 09:12:50 +0200, sajin <s...@iprlab.com> wrote:
> > > > Hi All,

>
> > > > I am new to windows forms C# 2005, How can i have a combo box with
> > > > image and text

>
> > > > meaning

>
> > > > * 1Star
> > > > ** 2Start
> > > > *** 3Star

>
> > > > i have experimented something. but it shows only images.

>
> > > > Any help will be appreciated

>
> > > > Regards
> > > > -Sajin

>
> > > --
> > > Happy coding!
> > > Morten Wennevik [C# MVP]- Hide quoted text -

>
> > > - Show quoted text -

>
> Sajin
>
> I can't see where the text of an item is added? You are adding an
> Image item to the combo box items list.
> I think that Morten suggested to draw both the image and the text
> (using DrawText()).
>
> Therfore, the item added to the list should contain information about
> both the image and the text to be displayed. Maybe you can use a
> wrapper class to hold the item information.
>
> Feel free to ask any question regarding the custom drawing issue.
>
> Moty- Hide quoted text -
>
> - Show quoted text -



 
Reply With Quote
 
New Member
Join Date: Feb 2011
Posts: 3
 
      23rd Feb 2011
Hi,

can you please tell me , how you get both text and image.

Quote:
Originally Posted by sajin View Post
Thanks a ton to Morten and Moty....
It works fine. :-))

Regards
-Sajin





On May 21, 1:05 pm, Moty Michaely <Moty...@gmail.com> wrote:
> On May 21, 10:27 am, sajin <s...@iprlab.com> wrote:
>
>
>
>
>
> > Hi Morten,
>
> > I did as u said, but still i can't show image with text :-(
>
> > I added a imageList and added the images in that and assiciated with
> > combobox , where am i going wrong
> > using System;
> > using System.Collections.Generic;
> > using System.ComponentModel;
> > using System.Data;
> > using System.Drawing;
> > using System.Text;
> > using System.Windows.Forms;
>
> > namespace WindowsApplication1
> > {
> > public partial class Form1 : Form
> > {
> > public Form1()
> > {
> > InitializeComponent();
> > }
>
> > private void Form1_Load(object sender, EventArgs e)
> > {
> > string[] items;
>
> > items = new string[ComboBoxImageList.Images.Count];
>
> > for (int i = 0; i < ComboBoxImageList.Images.Count; i++)
> > {
> > this.comboBox1.Items.Add(ComboBoxImageList.Images[i]);
>
> > }
>
> > this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
> > this.comboBox1.DrawMode = DrawMode.OwnerDrawVariable;
> > this.comboBox1.ItemHeight =
> > this.ComboBoxImageList.ImageSize.Height;
> > this.comboBox1.Width =
> > this.ComboBoxImageList.ImageSize.Width + 80;
> > this.comboBox1.MaxDropDownItems =
> > this.ComboBoxImageList.Images.Count;
> > }
>
> > private void comboBox1_DrawItem(object sender,
> > DrawItemEventArgs e)
> > {
> > if (e.Index != -1)
> > {
>
> > e.Graphics.DrawImage(this.ComboBoxImageList.Images[e.Index],
> > e.Bounds.Left, e.Bounds.Top);
> > }
> > }
> > }
>
> > }
>
> > Regards
> > -Sajin
>
> > On May 18, 9:45 pm, "Morten Wennevik [C# MVP]"
>
> > <MortenWenne...@hotmail.com> wrote:
> > > Hi Sajin,
>
> > > You need to specify DrawMode. OwnerDrawFixed is usually good enough, but use OwnerDrawVariable if the height of the items can vary.
>
> > > Set DropDownStyle to DropDownList to be able to draw the selected item in the EditBox
>
> > > Then subscribe to the ComboBox' DrawItem event. It will be called for each item in the list. Use the DrawItemEventArgs to find out what kind of item you are currently drawing and use DrawItemEventArgs.Bounds to position your drawing. You can then draw image and text any way you like. DrawItemEventArgs.State has information of wether the current item is highligted and so on.
>
> > > If you need more specific information, please ask.
>
> > > On Fri, 18 May 2007 09:12:50 +0200, sajin <s...@iprlab.com> wrote:
> > > > Hi All,

>
> > > > I am new to windows forms C# 2005, How can i have a combo box with
> > > > image and text

>
> > > > meaning
>
> > > > * 1Star
> > > > ** 2Start
> > > > *** 3Star

>
> > > > i have experimented something. but it shows only images.
>
> > > > Any help will be appreciated
>
> > > > Regards
> > > > -Sajin

>
> > > --
> > > Happy coding!
> > > Morten Wennevik [C# MVP]- Hide quoted text -

>
> > > - Show quoted text -
>
> Sajin
>
> I can't see where the text of an item is added? You are adding an
> Image item to the combo box items list.
> I think that Morten suggested to draw both the image and the text
> (using DrawText()).
>
> Therfore, the item added to the list should contain information about
> both the image and the text to be displayed. Maybe you can use a
> wrapper class to hold the item information.
>
> Feel free to ask any question regarding the custom drawing issue.
>
> Moty- Hide quoted text -
>
> - Show quoted text -
 
Reply With Quote
 
New Member
Join Date: Feb 2011
Posts: 3
 
      23rd Feb 2011
when i click image event will be fired and displat some data(but not when i click on text)
how it will possible.........
when i click on image combobox events was fired...........

Last edited by Plakshmi; 23rd Feb 2011 at 12:41 PM..
 
Reply With Quote
 
New Member
Join Date: Feb 2011
Posts: 3
 
      23rd Feb 2011
i want raise event wnen i click on image not raised click on text.

can you please help me.

Quote:
Originally Posted by Plakshmi View Post
I am trying like above i am not getting text.how to add both text and image?
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
control tip text for combo box items =?Utf-8?B?RGF2ZQ==?= Microsoft Access Form Coding 2 18th Sep 2006 12:51 PM
Need create small text & images files: any text editor that store images in .jpg format ? Simone Murdock Freeware 3 7th Aug 2005 04:12 PM
cannot paste web images, hyperlinked text, other Web items into Wo =?Utf-8?B?Y2FzdGFtYWRldXM=?= Microsoft Word Document Management 1 22nd Feb 2005 12:16 AM
Images on Menu Items Sumit Gupta Microsoft VB .NET 3 30th Apr 2004 01:51 AM
Connecting items in a combo box to items in a table Jon Microsoft Access 1 17th Sep 2003 12:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:47 PM.