Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6324233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:39:57+00:00 2026-05-24T16:39:57+00:00

Is there a way that I can have the SelectedItem’s height larger than the

  • 0

Is there a way that I can have the SelectedItem’s height larger than the rest of the items in a ListBox? This is what I have right now, yet it just acts as a normal listbox:

public class BuddyListBox : ListBox
{

    public BuddyListBox() 
    {
        this.ResizeRedraw = true;
        this.DoubleBuffered = true;
        this.BorderStyle = BorderStyle.None;
        this.Dock = DockStyle.Fill;
        this.DrawMode = DrawMode.OwnerDrawVariable;
        this.ItemHeight = 16;
    }
    protected override void OnDrawItem(DrawItemEventArgs e)
    {
        if (e.Index == -1 || e.Index >= this.Items.Count)
            return;

        Buddy current = (Buddy)this.Items[e.Index];
        //Bitmap icon = current.StatusImage;

        //e.Graphics.DrawImage(icon, e.Bounds.Left, e.Bounds.Top, 16, 16);
        e.DrawBackground();
        e.Graphics.DrawString(current.Address, e.Font, new SolidBrush(current.Status != BuddyStatus.offline ? e.ForeColor : Color.DarkGray), 16 + e.Bounds.Left, e.Bounds.Top);
        e.Graphics.DrawString(current.Status.ToString(), e.Font, new SolidBrush(Color.LightGray), e.Bounds.Right - (int)(e.Graphics.MeasureString(current.Status.ToString(), e.Font).Width) - this.Margin.Right, e.Bounds.Top);
        e.DrawFocusRectangle();
    }

    protected override void OnSelectedIndexChanged(EventArgs e)
    {
        this.Refresh();
    }

    protected override void OnMeasureItem(MeasureItemEventArgs e)
    {
        if (e.Index == this.SelectedIndex)
            e.ItemHeight = this.ItemHeight * 2;
        else
            e.ItemHeight = this.ItemHeight;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:39:59+00:00Added an answer on May 24, 2026 at 4:39 pm

    Your OnMeasureItem isn’t doing anything while the DrawMode is OwnerDrawFixed. Change the mode to OwnerDrawVariable.

    Unfortunately, the MeasureItem event only happens when the handle gets created, so here is a work-around:

    public class BuddyListBox  : ListBox
    {
      int thisIndex = -1;
    
      public BuddyListBox()
      {
        this.DrawMode = DrawMode.OwnerDrawVariable;
      }
    
      protected override void OnDrawItem(DrawItemEventArgs e)
      {
        if (this.Items.Count > 0)
        {
          if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
          else
            e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds);
          e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, Brushes.Black, e.Bounds.Left, e.Bounds.Top);
          base.OnDrawItem(e);
        }
      }
    
      protected override void OnSelectedIndexChanged(EventArgs e)
      {
        base.OnSelectedIndexChanged(e);
        thisIndex = this.SelectedIndex;
        this.RecreateHandle();
      }
    
      protected override void OnMeasureItem(MeasureItemEventArgs e)
      {
        if (e.Index > -1)
        {
          if (e.Index == thisIndex)
            e.ItemHeight = 32;
          else
            e.ItemHeight = 16;
        }
        base.OnMeasureItem(e);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way that I can pass arguments in selector? example: I have
Does anyone know do there have any way that I can encrypt the array
Is there a way to have a custom control send events that can be
I have a listbox that can potentially have a large number of items with
Is there way that I can read the file from remote server using fopen
Is there any way that I can create a new delegate type based on
Is there any way that I can use C# to load and then render
Is there a way that I can add alias to python for encoding. There
Is there a way that I can find out how many matches of a
Is there a way that I can insert values into a VB.NET Dictionary when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.