How to have a TextBox control fill a Split Container panel? - vb.net

I am running Visual Studio 2010 Professional (10.0.40219.1 SP1Rel) with no updates showing in Windows Update. When I drop a TextBox control into a Split Container panel, make it Multiline, then Dock in Parent = Fill, it shrinks down to 1 pixel wide and disappears. Of course, at runtime it is invisible.
Is this a bug? Is there a fix? I actually don't need text input - what I want is to display text in a resizable panel, with scroll bars. I could perhaps put code on the events (SizeChanged, SplitterMoved, SplitterMoving...) but that's an ugly solution. Is that the only one?

Apparently I didn't realize I had put a Flow Layout container inside the Split Container panel. This was preventing it from filling the panel.

Related

Resize Panel Size On Windows Form Vb.net

I have 2 panels on windows form and both occupied the equal portion on form (i.e. 50%- 50%). Once i run the application, I want to resize the panel size by dragging form with mouse (i.e. 25%-75%). The portion given is not fixed it can be in any size. I just want to resize the panel by dragging/streching mouse.
Please help to resolve the issue.
Thanks,
Soorajbhan kuntal
I think you want to use a SplitContainer control on your form. Put the Panel controls into the two different containers of the SplitContainer, and set their Dock property to Fill. You can set the SplitContainer to Dock.Fill too or set the Anchor properties such that the SplitContainer stretches along with the form.

AutoScaling WinForm Display (Small, Medium)

First and foremost, please forgive me but my screenshots are in French due to my Windows installation at work. It is still very easy to understand though. I'll include screenshots to make it more visually appealing.
Here's some background information:
Windows 7 64bit
Visual Studio 2010
Default display is 100%
AutoScaleMode: DPI
AutoSize: True
My application is a windows form that was developped in a default (small - 100%) display. Like so:
As you can see, the "Petite" or Small display is the default selection.
Small Display - 100% (default)
Here is how my application looks with this setting. This is the correct display
Medium Display - 125%
The red rectangles point out the unwanted empty space.
I have tried:
Anchoring / Docking my controls such as my split containers, table layout panels, list views on Form_Load and via the UI. This didn't work.
Adding a split container to the form, and all controls respectively separated into it
Adding Table layout panels, where all textboxes and buttons are located in their respective cells
I really thought it was having a scaling problem because of the anchoring and docking. Although that didn't seem to be the problem ... What seems to be having trouble is the Tab Control and Listviews ...
Some users (most) have their settings as the default (100%) but there are a few who have it at a Medium setting, causing this scaling issue. Is there a way to fix this?
I cant see your screenshots or links for some reason so I cannot visualize the problem. If scaling is the problem, try setting AutoScaleMode to None.
I recently had to do this because my winform app was image intensive and it would not render correctly on Medium Settings because I built it using the default Small Settnigs display. Changing scale mode to None worked for me.
I fixed my issue by putting the tab controls and list views in a tablelayoutpanel. Everything that wasn't scaled properly had to be put inside a TableLayoutPanel. I kept my AutoScaleMode to DPI and AutoSize to True
Be sure to dock everything in their parent containers.
Here's the document outline for the more visual (like me):
Just click on the form and go to property pane. Find the Anchor element and click the dropdown. You click on all the lines in the square structure to become grey. Then click enter. Problem resolved.

Decrease the Space Between a Menu Item's Icon and its Text

In my .net windows form (I am using XP Pro SP3 and VS 2010), I have created a menustrip. In the menustrip are several menu items, each with a dropdown menu. The menu items in the dropdown menus each have an icon with some text. I want to make the menu more compact by decreasing the horizontal space between the icon and the text. (I added a red arrow to the picture to show the space I am talking about).
So far, I have set the padding of all the menuitems to 0, but this seems only to affect the vertical spacing between one menu item and the next.
I want to use the system rendermode for the menustrip (although the problem persists no matter what rendermode I use. The icons in the menu are 16x16, and have the property sizetofit.
Funny thing is that this very same spacing is just the way I want it in the menustrip - the icon is right next to the text.
This will remove the image margin completely, but it removes the images too; I just want to change the width of the image margin.
For Each menuItem As ToolStripMenuItem In menu_main.Items
DirectCast(menuItem.DropDown, ToolStripDropDownMenu).ShowImageMargin = False
Next
What can I do here?
So, this is kinda cheating, and probably isn't going to look as clean as you'd like, but I was able to do it by making the image have the text and then setting following properties in the designer for the menu item:
DisplayStyle = Image
ImageScaling = None

winforms - usercontrol with dockstyle fill not correct size during form load

My main form has two panels, left docked and right docked. The right side panel has two child panels with top dock and bottom dock settings. The usercontrol is added to the right side top panel.
My usercontrol has a panel and a label. The panel is anchored on all 4 sides, the label is anchored on all except the bottom. At runtime I create this usercontrol and set it to dockstyle=fill and then I add it to my top right panel.
With everything set to "fill" I expect that when I add my usercontrol to the panel it will take on the appropriate width and height and pass that info to the child controls (labels) inside of my usercontrol.
My problem is that this stretching of the size does not happen when I create my objects during the Load event on my usercontrol. Even though initializecomponent has ran for the usercontrol the panel inside of it (4 corners anchored) has not taken the x/y values of the available space. As a result my usercontrol shows up about 50% of the width I want.
Lets say that instead of creating objects during usercontrol load that I instead start a timer and have the timer call my create routine when it raises the tick event. When I do things like this my objects are created with the full width/height that I expect. The only issue here is that this causes a delay in my interface.
Can someone help explain this behavior? My mainform is calling a "load gui" routine which is instantiating usercontrols, setting panel sizes, and then adding usercontrols to those panels. This particular user control is the last to load into the panels from that load gui routine so it does not make sense that the parent panel width/height would not be known yet. This is one of my first apps where I am purposely trying to use dockstyle=fill to keep things consistent across different main form sizes without writing all the extra size_changed code handlers. I'm sure this one is easy to work around once I know where the problem lies.
Thanks for any help provided!
this turned out to be a padding issue on the parent usercontrol. I also had to allow a bit of wiggle room to make sure that the controls didn't overflow the panel so I did a parent.width - 15 and that along with the padding made everything work much better.

How can I show scrollbars on a PictureBox control?

Sometimes, I have a picturebox lets say 100x100. But the image it will display is actually 100x400.
I don't want to increase the size of the picturebox itself. Instead, I would like to create a vertical scrollbar (or horizontal if needed).
I could not find a scrollbar in the toolbox, so I guess I have to code it. But, how?
And I still wonder if I didn't make a mistake and didn't see the scrollbar in the toolbox. My apologies then :(
I suppose you could add separate scrollbar controls and sync their Scroll events up with the offset at which the picture in the PictureBox is drawn, but that sounds like actual work. There's a better way.
Add a Panel control to your form, and set its AutoScroll property to "True". This will cause the control to automatically show scrollbars when it contains content that lies outside of its currently visible bounds. The .NET Framework will take care of everything for you under the covers, without you having to write a single line of code.
Drag and drop your PictureBox control inside of the Panel control that you just added. The Panel control will then detect that one of its child controls is larger than its visible area and show scrollbars, thanks to the AutoScroll property. When the user moves the scrollbars, the portion of the image in your PictureBox that is visible will be automatically adjusted. Magic.
(The reason you have to use a Panel control as a container is because PictureBox does not inherit directly from the ScrollableControl base class, which is what provides the AutoScroll property.)
I tried this and it worked well. But I noted that if the picturebox is docked in the panel, the picturebox is automatically set to the size of the parent panel, and can't be set larger (at least not in any way I could find). This defeats the purpose of the technique. So -- put the picturebox on the panel, but don't dock it, and it will work perfectly.
There are no automatic scroll bars on a picture box, but you can add the VScrollBar (and HScrollBar) control to the form and handle the image scrolling manually by redrawing it at a different offset each time the Scroll event is fired.