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

  • Home
  • SEARCH
  • 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 8052993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:42:49+00:00 2026-06-05T07:42:49+00:00

I have a PictureBox with size 1000, 20, and I set it’s bitmap like

  • 0

I have a PictureBox with size 1000, 20, and I set it’s bitmap like so on Form_Load event:

void Form1_Load ( object sender, EventArgs e )
{
    SetProgressBar ( pictureBox1, 25 );
}

void SetProgressBar ( PictureBox pb, int progress )
{
    Bitmap bmp = new Bitmap ( 100, 1 );

    using ( Graphics gfx = Graphics.FromImage ( bmp ) )
    using ( SolidBrush brush = new SolidBrush ( System.Drawing.SystemColors.ButtonShadow ) )
    {
        gfx.FillRectangle ( brush, 0, 0, 100, 1 );
    }

    for ( int i = 0; i < progress; ++i )
    {
        bmp.SetPixel ( i, 0, Color.DeepSkyBlue );
    }

    // If I don't set the resize bitmap size to height * 2, then it doesn't fill the whole image for some reason.
    pb.Image = ResizeBitmap ( bmp, pb.Width, pb.Height * 2, progress );
}

public Bitmap ResizeBitmap ( Bitmap b, int nWidth, int nHeight, int progress )
{
    Bitmap result = new Bitmap ( nWidth, nHeight );

    StringFormat sf = new StringFormat ( );
    sf.Alignment = StringAlignment.Center;
    sf.LineAlignment = StringAlignment.Center;
    Font font = new Font ( FontFamily.GenericSansSerif, 10, FontStyle.Regular );

    using ( Graphics g = Graphics.FromImage ( ( Image ) result ) )
    {
            // 20 is the height of the picturebox
        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
        g.DrawImage ( b, 0, 0, nWidth, nHeight );
        g.DrawString ( progress.ToString ( ), font, Brushes.White, new RectangleF ( 0, -1, nWidth, 20 ), sf );
    }
    return result;
}

Everything looks great until I set the BorderStyle to FlatSingle. It creates a gap at the end. How can I fix this so it still looks fully colored all the way?

EDIT: This is how it looks:

enter image description here

  • 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-05T07:42:51+00:00Added an answer on June 5, 2026 at 7:42 am

    It appears that adding the borders in increasing the size of your pictureboxes. I set up your example with BorderStyle set to FixedSingle,None and Fixed3D the results were different for each one. Each of these PictureBoxes are starting at the same location as you can see the visible width has actually changed.

    enter image description here

    It worked out to be about 4 pixels pn the FixedSingle and 2 pixels on the Fixed3D. I am not sure what is going on under the hood but you should be able to code around it like this.

     if (pb.BorderStyle == BorderStyle.FixedSingle)
         pb.Image = ResizeBitmap(bmp, pb.Width + 4, pb.Height * 2, progress);
     else if (pb.BorderStyle == BorderStyle.Fixed3D)
         pb.Image = ResizeBitmap(bmp, pb.Width + 2, pb.Height * 2, progress);
     else 
         pb.Image = ResizeBitmap(bmp, pb.Width, pb.Height * 2, progress);
    

    Which gives a result that looks like this.

    enter image description here


    If you look at the DisplayRectangle Property you will see that your client rectangle is changing when you change your BorderStyle:

    BorderStyle.None = 1000 pixels
    BorderStyle.Fixed3D = 996 pixels
    BorderStyle.FixedSingle = 998 pixels

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with DragDrop. private void Form0_Load(object sender, EventArgs e) { PictureBox
i have picturebox with picture cb. PBr1_1.Image = new Bitmap(@Logos\\Images\\cb.png); I'd like to change
I have a World ( a PictureBox and a Bitmap with is size (
I have a PictureBox that its size is fixed to 480x360 pixels. I write
In C# i have a picturebox. i would like to draw 4 colors. The
I have added an EventHandler for the Click-event to a picturebox but on runtime
I have created a picturebox within my panel and I would like to fill
I have a picturebox with a tiled background image (plane white bitmap), and an
I have a PictureBox with lots of transparent png's drawn into... Now I'd like
I have PictureBox picture . I use: picture.Size = bmp.Size; picture.Image = bmp; Let's

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.