Visual Basic - Lock ProgressBar Controls To Your Form Using A StatusBar Control (Visual Basic .NET)
Visual Basic .NET makes it easy to add a progress bar to a form with its built-in ProgressBar control. And for the most part, locking a ProgressBar control on a form works well. Until, of course, you resize the form. If you make the form too small, you'll end up clipping the progress bar and hiding portions of it from view. One way to prevent this problem is to place the progress bar inside an object that can grow and shrink with the form, such as a status bar.
To see what we mean, create a new Visual Basic .NET Windows Application and add a ProgressBar and a StatusBar control to the form. Right away you should notice that the StatusBar automatically fills the form and anchors itself to the bottom of the form. On the other hand, the ProgressBar will be only as large as you draw it. Now, right-click on the design page and select View Code from the shortcut menu. Then, add the following two lines of code to the form's Load() event:
- ProgressBar1.Parent = StatusBar1
- ProgressBar1.Dock = DockStyle.Fill
The first line makes the StatusBar control the parent of the ProgressBar control. The second line locks the progress bar inside the status bar and tells .NET to devote the entire status bar to the progress bar. Now, when you run the program and resize the form, the progress bar shrinks and grows with it.