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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:11:59+00:00 2026-05-30T05:11:59+00:00

Technology: .NET 4, C#, WinForms, Visual Studio 2010 I have run into an issue

  • 0

Technology: .NET 4, C#, WinForms, Visual Studio 2010

I have run into an issue when sizing a custom UserControl. The customer UserControl simply contains a PictureBox with the properties set such that scroll bars appear when necessary.

The UserControl has the following properties set:

  • AutoScaleMode: Font
  • AutoScroll: True
  • DoubleBuffered: True
  • MinimumSize: 100, 100
  • Size: 250, 250

The PictureBox has the following properties set:

  • Anchor: Top, Left
  • Location: 0,0
  • Size: 250, 250
  • SideMode: AutoSize

In the designer view for the custom control, the PictureBox fills the entire like is desired. However, in the designer view for the main application, the custom UserControl is initally 250 x 250 like its designer showed, but when I resize it to fit in the main application, only the UserControl panel is resized leaving the PictureBox to the originl 250 x 250. One of the properties I expose is the mouse cursor X,Y position inside the PictureBox and when there is no image loaded, the property returns nothing outside of the 250 x 250 area.

I have tried:

  • Setting the Anchor property to Top, Left, Right, Bottom, but that causes the UserControl not to display scroll bars.
  • Setting the Dock property of the PictureBox to fill, but that also results in UserControl not display scroll bars.

How can I make it such that the PictureBox is always the full size of the UserControl, even when being adjusted in the designer?

  • 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-30T05:12:01+00:00Added an answer on May 30, 2026 at 5:12 am

    You need scrollbars on the user control so when the user control is smaller than the picture shown in the picurebox, the user can scroll the to see other parts of the picture, right? And also when the user control is larger than the picture box, you want that the picture box to fill the user control (so you cant catch mouse events on the picture box). Right?

    First of all, you can also subscribe to the mouse event on the user control (in addition to the picture box) to do the desired action. If that’s not applicable, you can do this:

    Handle the Resize event of the user control, and change the aspects of the picture box:

    (put this in your user control)

        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
    
            MaintainPictureBoxSize();
        }
    
        private void MaintainPictureBoxSize()
        {
            pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
    
            pictureBox1.Location = new Point();
            pictureBox1.Size = new Size();
    
            var clientSize = this.ClientSize;
    
            if (pictureBox1.Image == null)
                pictureBox1.Size = clientSize;
            else
            {
                Size s = pictureBox1.Image.Size;
                pictureBox1.Size = new Size(
                    clientSize.Width > s.Width ? clientSize.Width : s.Width,
                    clientSize.Height > s.Height ? clientSize.Height : s.Height);
            }
        }
    

    Also call the MaintainPictureBoxSize method when you change the Image of the PictureBox.
    The effect of this is, when width or height of the image being shown in the picture box is smaller than the user control, the picture box will expand to fill the user control, and if not, the size of the picture box is the size of the image, so scrollbars are shown.

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

Sidebar

Related Questions

Technology used: .NET 2008, C#, winforms So I currently have an issue. I have
Technology: Visual Studio 2008 .NET, Winforms bsTransactions.DataSource = Transactions.Tables[2]; bsnTransactions.BindingSource = bsTransactions; txtTransOverrideDate.DataBindings.Add(Text, bsTransactions,
Thinking about getting into .net technology project management I've had plenty of experience with
I am a .NET WinForms/ASP.NET developer with what I think of as technology agnostic
I have to develop a application in .net technology which calls an external service
Technology: Dot Net, ASP.Net We have articles stored in XML repository and article contains
I'm coding an Outlook 2010 plug-in in .NET 4.0, which use WPF technology, and
Technology: C#, Winforms The Background: I have the following container structure (Form containing a
I am new to ASP.NET MVC, and the ASP.NET technology in general, so, please,
Technology Used:- Asp.Net 2.0 Code:- See Below Description:- hello code given below is working

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.