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 7708583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:38:56+00:00 2026-06-01T00:38:56+00:00

I have a bitmap that contains 24×24 icons. I would like to use it

  • 0

I have a bitmap that contains 24×24 icons. I would like to use it in an image list for a toolstrip. Is it possible to use the bitmap and select the right portion of it based on the ImageIndex of a ToolStripButton? I would like to avoid splitting it into multiple files.

  • 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-06-01T00:38:57+00:00Added an answer on June 1, 2026 at 12:38 am

    You could inherit ToolStripButton and provide a new source for the image. Here is a fairly simplistic approach; you might need to expand upon the idea for your exact needs.

        public class ToolStripImageButton: ToolStripButton
    {
        public ToolStripImageButton()
            : base()
        {
        }
    
    
        private Image iconMap;
        private Int32 iconMapIndex;
    
        [RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)]
        public Image IconMap
        {
            get { return this.iconMap; }
            set
            {
                this.iconMap = value;
                this.RecalculateImage();
            }
        }
        [RefreshProperties(System.ComponentModel.RefreshProperties.Repaint)]
        public Int32 IconMapIndex
        {
            get { return this.iconMapIndex; }
            set
            {
                this.iconMapIndex = value;
                this.RecalculateImage();
            }
        }
    
        protected void RecalculateImage()
        {
            if (base.Image != null)
            {
                base.Image.Dispose();
                base.Image = null;
            }
            if (this.iconMap != null)
            {
                // assumes each icon is 16x16, you could add more properties for flexibility
                Int32 x = this.iconMap.Width / 16;
                Int32 y = this.iconMap.Width / 16;
    
                Int32 iconCount = x * y;
                if (this.iconMapIndex < 0 || this.iconMapIndex >= iconCount) return;
    
                Int32 offsetX = (this.iconMapIndex % x) * 16;
                Int32 offsetY = (this.iconMapIndex / x) * 16;
    
                Bitmap bitmap = new Bitmap(16, 16);
                using (Graphics g = Graphics.FromImage(bitmap))
    
                g.DrawImage(
                    this.iconMap,
                    new Rectangle(0,0,bitmap.Width,bitmap.Height), 
                    new Rectangle(offsetX, offsetY, bitmap.Width, bitmap.Height), 
                        GraphicsUnit.Pixel);
    
                base.Image = bitmap;
            }
        }
    
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Image Image
        {
            get
            {
                return base.Image;
            }
            set
            {
                // ignore
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object that contains: the image itself (type: {System.Drawing.Bitmap}) image type (type:
I have a large png that I would like to use as a background
I have three array, like this, that contains my bitmap images: static unsigned char
I have a PNG image that has an unsupported bitmap graphics context pixel format.
I developed an activity that contains canvas to draw image and I have a
I have a png with transparency that I'd like to use for the background
I have a canvas that contains several bitmap images, I want the user to
I have a byte[]. It contains data of an image (jpeg or bitmap) with
I have a C header file that contains 10x12 pixel bitmap font characters in
I have a ListView where each cell contains a bitmap that is downloaded from

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.