Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Windows Forms
  4. Form Resizing and Docked Controls

Form Resizing and Docked Controls

Scheduled Pinned Locked Moved Windows Forms
helpwinformsquestionannouncement
12 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    farzadmf
    wrote on last edited by
    #1

    Hi everybody, I have an issue with Windows Forms: I created a Windows Form and docked a picture box to fill the entire form, but the problem I have is that the picture box's size change only when either "Width" and "Height" properties of the Form (or both of them) are increasing and in fact, if I resize the form so that it becomes smaller (both in Width and Height) the picture box's size wouldn't change. To test this, I tried to update the Text property of the form in the Form's Paint event to reflect the picture box's Size property and when I'm making the Form smaller, neither Width nor the Height of the picture box is changing, any ideas?

    H Z G 3 Replies Last reply
    0
    • F farzadmf

      Hi everybody, I have an issue with Windows Forms: I created a Windows Form and docked a picture box to fill the entire form, but the problem I have is that the picture box's size change only when either "Width" and "Height" properties of the Form (or both of them) are increasing and in fact, if I resize the form so that it becomes smaller (both in Width and Height) the picture box's size wouldn't change. To test this, I tried to update the Text property of the form in the Form's Paint event to reflect the picture box's Size property and when I'm making the Form smaller, neither Width nor the Height of the picture box is changing, any ideas?

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      Do you have the SizeMode property of the PictureBox set to AutoSize? If that is so, could you please describe what effect, you are trying to achieve, so that people can suggest workarounds/alternative strategies. :)

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      F 1 Reply Last reply
      0
      • H Henry Minute

        Do you have the SizeMode property of the PictureBox set to AutoSize? If that is so, could you please describe what effect, you are trying to achieve, so that people can suggest workarounds/alternative strategies. :)

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        F Offline
        F Offline
        farzadmf
        wrote on last edited by
        #3

        Thank you for your reply: Firstly, the picture box's SizeMode property determines how the size changes according to the size of the picture being shown in the picture box. Secondly, I want to achieve a condition in which resizing the Form ALWAYS causes the picture box's size to change even when both Width and Height properties of the form are decreasing; and in fact, as soon as every one of them begins to increase, the picture box's size is also changed.

        H 1 Reply Last reply
        0
        • F farzadmf

          Hi everybody, I have an issue with Windows Forms: I created a Windows Form and docked a picture box to fill the entire form, but the problem I have is that the picture box's size change only when either "Width" and "Height" properties of the Form (or both of them) are increasing and in fact, if I resize the form so that it becomes smaller (both in Width and Height) the picture box's size wouldn't change. To test this, I tried to update the Text property of the form in the Form's Paint event to reflect the picture box's Size property and when I'm making the Form smaller, neither Width nor the Height of the picture box is changing, any ideas?

          Z Offline
          Z Offline
          Zoki Manas
          wrote on last edited by
          #4

          I've tried your example. I have one form and put one picture box inside. I've only set Dock property of the picture box to "Fill" and everything was working fine. Forget about showing picture box size, in the text property of the form. Set Dock = Fill, and just to see that it is resizing, set BackgroundColor of the picture box to some color and test it.

          F 1 Reply Last reply
          0
          • Z Zoki Manas

            I've tried your example. I have one form and put one picture box inside. I've only set Dock property of the picture box to "Fill" and everything was working fine. Forget about showing picture box size, in the text property of the form. Set Dock = Fill, and just to see that it is resizing, set BackgroundColor of the picture box to some color and test it.

            F Offline
            F Offline
            farzadmf
            wrote on last edited by
            #5

            Yes, you are right; if you set the BackgroundColor and make the Form smaller, you notice no difference because there is only one solid color, BUT imagine a situation where you have a picture or something being displayed in the picture box, if you make the Form smaller and the picture box isn't resized accordingly, some parts of the image would not be visible.

            1 Reply Last reply
            0
            • F farzadmf

              Thank you for your reply: Firstly, the picture box's SizeMode property determines how the size changes according to the size of the picture being shown in the picture box. Secondly, I want to achieve a condition in which resizing the Form ALWAYS causes the picture box's size to change even when both Width and Height properties of the form are decreasing; and in fact, as soon as every one of them begins to increase, the picture box's size is also changed.

              H Offline
              H Offline
              Henry Minute
              wrote on last edited by
              #6

              I'm sorry that I have taken so long to answer your post. However, you did not answer my first question.

              farzadmf wrote:

              Firstly, the picture box's SizeMode property determines how the size changes according to the size of the picture being shown in the picture box.

              I know this already, I asked what you had SizeMode set to in your application.

              Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

              F 1 Reply Last reply
              0
              • H Henry Minute

                I'm sorry that I have taken so long to answer your post. However, you did not answer my first question.

                farzadmf wrote:

                Firstly, the picture box's SizeMode property determines how the size changes according to the size of the picture being shown in the picture box.

                I know this already, I asked what you had SizeMode set to in your application.

                Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                F Offline
                F Offline
                farzadmf
                wrote on last edited by
                #7

                SizeMode is set to Normal, but I tried with AutoSize but it didn't make any difference.

                H 2 Replies Last reply
                0
                • F farzadmf

                  SizeMode is set to Normal, but I tried with AutoSize but it didn't make any difference.

                  H Offline
                  H Offline
                  Henry Minute
                  wrote on last edited by
                  #8

                  This is very odd. I have never noticed this behaviour before. I had thought that there might be a problem if SizeMode was set to AutoSize, because of some strange conflict between it and the Dock.Fill property. But, as you say, it happens with SizeMode.Normal too. I even tried Dock.None with Anchor set to Top, Left, Bottom, Right, but it was exactly the same. I am at a loss. There are two Articles here on CP that (supposedly) have PictureBox functionality without actually using a PictureBox. In case they are of help in your situation, they are: C# Scrollable Picturebox Custom Control[^] and A Zoomable and Scrollable PictureBox[^]. When people post here asking for advice on PictureBox problems, I usually tell them not to use a PictureBox, as it is an awful control. You have given me an extra bullet to use. Between the PictureBox and ImageList, Microsoft don't seem to be very good with images, do they? Sorry not to be able to offer more help. :(

                  Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                  F 1 Reply Last reply
                  0
                  • F farzadmf

                    SizeMode is set to Normal, but I tried with AutoSize but it didn't make any difference.

                    H Offline
                    H Offline
                    Henry Minute
                    wrote on last edited by
                    #9

                    I'm not sure that you are correct. Simple Form, PictureBox.

                    public Form1()
                    {
                        InitializeComponent();
                    
                        this.Form1\_ResizeEnd(null, EventArgs.Empty); // just to get the correct caption
                    }
                    
                    private void Form1\_ResizeEnd(object sender, EventArgs e)
                    {
                        this.Text = string.Format("Form1 \[{0}, {1}\] - {2}", this.pictureBox1.Width, this.pictureBox1.Height, this.pictureBox1.Dock);
                    }
                    

                    Connect the ResizeEnd event of the Form to the handler above. All now appears to be hunky-dory. What do you think?

                    Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                    1 Reply Last reply
                    0
                    • H Henry Minute

                      This is very odd. I have never noticed this behaviour before. I had thought that there might be a problem if SizeMode was set to AutoSize, because of some strange conflict between it and the Dock.Fill property. But, as you say, it happens with SizeMode.Normal too. I even tried Dock.None with Anchor set to Top, Left, Bottom, Right, but it was exactly the same. I am at a loss. There are two Articles here on CP that (supposedly) have PictureBox functionality without actually using a PictureBox. In case they are of help in your situation, they are: C# Scrollable Picturebox Custom Control[^] and A Zoomable and Scrollable PictureBox[^]. When people post here asking for advice on PictureBox problems, I usually tell them not to use a PictureBox, as it is an awful control. You have given me an extra bullet to use. Between the PictureBox and ImageList, Microsoft don't seem to be very good with images, do they? Sorry not to be able to offer more help. :(

                      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                      F Offline
                      F Offline
                      farzadmf
                      wrote on last edited by
                      #10

                      Don't mind please. It's OK. Anyway thank you very very much for your concern. I will surely check the controls you mentioned. Thank you again.

                      1 Reply Last reply
                      0
                      • F farzadmf

                        Hi everybody, I have an issue with Windows Forms: I created a Windows Form and docked a picture box to fill the entire form, but the problem I have is that the picture box's size change only when either "Width" and "Height" properties of the Form (or both of them) are increasing and in fact, if I resize the form so that it becomes smaller (both in Width and Height) the picture box's size wouldn't change. To test this, I tried to update the Text property of the form in the Form's Paint event to reflect the picture box's Size property and when I'm making the Form smaller, neither Width nor the Height of the picture box is changing, any ideas?

                        G Offline
                        G Offline
                        geali_dor
                        wrote on last edited by
                        #11

                        Hey there, if you change the form's or any controll's size to smaller, i guess it won't repaint, but there is a possibility to tell the form/controll to do so:

                        public ExampleForm()
                        {
                        this.SetStyle(ControlStyles.ControlStyles, true);
                        }

                        hope this helps!

                        hack the planet

                        F 1 Reply Last reply
                        0
                        • G geali_dor

                          Hey there, if you change the form's or any controll's size to smaller, i guess it won't repaint, but there is a possibility to tell the form/controll to do so:

                          public ExampleForm()
                          {
                          this.SetStyle(ControlStyles.ControlStyles, true);
                          }

                          hope this helps!

                          hack the planet

                          F Offline
                          F Offline
                          farzadmf
                          wrote on last edited by
                          #12

                          Thanks, I will try that and let you know.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups