Can't get flow layout panel to disappear when empty - winforms

I have a custom Windows Forms (a class which extends System.Windows.Forms). Its layout is as follows:
FLP: Flow Layout Panel. Flow directions is specified in the name.
PB: Picture Box
RTB: RichTextBox
b: Button
Onto the problem: it is possible for the FLP at the bottom to be empty (no buttons). When that happens, I'd like it to shrink to zero height, and let the FLP above, and the RTB, grow and fill that space. This is because all that empty space looks ugly when there are no buttons.
I configured the lower flp with AutoSize = True and AutoSize = GrowAndShrink. Then, for the upper flp, I set AutoSize = True, AutoSizeMode = GrowOnly and Dock = Fill. But when I create a form with no buttons, the space is still there. If I draw the control borders, where the lower flp should be, I see a little square dot.
Where am I going wrong?
UPDATE: I'm willing to redo the layout in a more convenient way, or even redo the whole form using WPF.

I doesn't look like you need the Top-Down FlowLayoutPanel.
Try taking your Right-Left FlowLayoutPanel and Dock it to the bottom. Then take your Left-Right FlowLayoutPanel and Dock Fill it in the remaining area.
Where your button panel has no visible buttons, then you can just hide the panel and the Filled panel will take up that remaining space.

If you remove FLP_top_down, change flp_left_to_right to be .Dock = DockStyle.Fill and change flp_left_to_right to be .Dock = DockStyle.Bottom, you should get what you are after.

Related

How to make a RichTextBox automatically resize horizontally & vertically and make its parent resize as well?

I need to put a RichTextBox inside a container such as a canvas/grid/stackpanel or anything which serves the purpose best.
look at the example I made:
in the picture RichTextBox is white, Canvas is LightBlue, and the main window's Grid is salmon(=light orange)
The user starts typing inside the RichTextBox. as far as he DOESN'T press enter or shift+enter, the RichTextBox must resize horizontally as long as the sentence is, on the condition that it doesn't exceed the main grid's boundaries.
RichTextBox must also resize vertically, when the user starts typing in new lines, but should not exceed the grid's boundaries.
So how is it done ?
This is not the best aproach that you looking for but i't works...
Just increase the Document.PageWidth based on the content inside the textbox by doing this
richTextBox1.Document.PageWidth = 1000;
However, consider looking for No Wrap for the richtext box. Wich i'm out of time to give more help.

Windows forms app, autoscale controls with form

I'm a newbie. Designing a form that can be resized, and I want my textboxes, labels and buttons to resize with the form, can someone tell me how to do this?
It depends on the type of layout you need. The "basic tools" you have to do that are following properties: Anchor and Dock.
Anchor
With the Anchor property you "attach" a side of an element to a side of its container. For example if you place a button in the bottom-right corner of a window and you set "Bottom, Right" as Anchor then when you'll resize the form the button will keep its relative position to that corner.
Now imagine you place a multiline text-box in the form, resize as needed (for example 4 px from top, left and right border and 128 px height) and set the Anchor property to "Left, Top, Right". When you'll resize the form that control will keep its height but it'll resize to keep its margins (so if you'll make the form wider its width will be increased).
Dock
Dock is different. With docking you "say" to the Layout Manager to use all available space in one direction. For example if you set to Left then your control will keep its width but it'll use all the available height and its location will be most left as possible.
You may have more than one control docked in a container, imagine you have 5 textbox with Top docking inside a form. They'll be stacked to the top of the form using all the width (and resizing). Another example: a Top docked control (as a banner) and a "Fill" docked control (as main content). Remember that with docking the order of controls matters (if you first place the "Fill" control it'll use ALL the available space and the "Top" dock control will overlap).
Even more
Moreover you have some layout controls too (tables and stacks). They're really easy to use and a 30 minutes of "experiments" will clarify much better than a long text.

How should I display a notification bar in WinForms?

You all know the "You've got new answers!" notification bar on SO. I'd like the same thing in a Form, preferably just as smooth. Is there a simple way? Or do I have to completely create this myself?
My searches did not yield any good results, only lots of progress bars and popups in the system notification area, but that's not what I'm looking for.
The messages I want to display belong to a Form, not to the whole application
You could simply animate a panel dropping down from the top of the client area of the form.
Increasing the y coordinate of the panel in a timed loop. The panel would start invisible and slowly become visible. (The panel would start at -panel.height and work its way down to 0.)
Create two panels in your form, a notification panel docked to top, and below that a content panel anchored to top. In your Form.Load, set the height of the notification panel to zero. Don't set the height to zero in Design View, you won't be able to click on the notification panel to edit it.
Then when you get a notification, draw the contents in the notification panel and create a System.Windows.Form.Timer that increases the height of the notification panel by a few pixels every few dozen milliseconds or so. Stop when the panel is of the desired height. Do the same with a negative height to hide the panel.
This does not require repainting or recalculating sizes or positions of anything, does not overdraw anything, and looks slick. I have done this and it works.
If you want it constrained to a particular form, it should be easy enough to put a Panel on the form with its Dock set to DockStyle.Top, then place a label for the description and a button that hides it.
It's not difficult to do with a panel or a UserControl, but the fiddly part is making the contents of the form slide down as the bar slides down. To simplify that I would use a SplitContainer. The top splitpanel contains the notification bar and the splitter distance is initially 0. Slide the bar into view by incrementing the SplitterDistance property. Doing it this way means you don't have to worry about making the other contents of the form slide down (which is a hassle because it prevents you from using docking).
The only downside to using SplitContainer I can think of is that the animation of the bar will be slightly different: the text won't scroll down with the bar, it will be revealed in place as the bar slides down. If this bothers you, you can fix it by having the text (or your panel/custom control) slide down as you increase the splitter distance (only a couple more lines of code).
Showing the bar:
for (int i = 0; i <= 33; i++)
{
splitContainer1.SplitterDistance = i;
Thread.Sleep(5);
Refresh();
}
Hiding the bar:
for (int i = 33; i >= 0; i--)
{
splitContainer1.SplitterDistance = i;
Thread.Sleep(5);
Refresh();
}
Of course, if you don't mind the notification bar simply covering the top part of your form, then you can just do the whole thing very easily with a panel. :)
I was looking for the same thing just now and found this on code project
I have not used it yet, So I have no idea how solid it is.

How to make WPF WebBrowser grow horizontally and vertically?

In WPF, we are using a WebBrowser control to view HTML content. When we place the control on our window, it grows horizontally with the window as it grows/shrinks. However, we have not found a way to make the control grow vertically with the window. We are looking for some sample code that will allow the WebBrowser WPF control to grow both vertically and horizontally with the window.
With WPF and wanting to grow with the window, the magical starting point is to set the Margin to 0 and avoid setting width and height. (You can have margin equal to another number, but start with zero and see how it looks first!)
Another option is to use a dock panel with last child fill set to true, where the web browser control is the last element (as you read down the page - it doesn't have to be the last element in the rendered UI.

Spreading controls to fill space as a dialog resizes

I have a dialog with column down the right side filled with buttons. The dialog is built with Windows Forms. I have a mockup at the following link:original dialog
(I would have included it but apparently i'm not allowed to use image tags)
I would like for the buttons in the right column to resize themselves to fill the remaining vertical space when the dialog resizes. It doesn't particularly matter to me whether or not buttons simply increase in size or whether the buttons remain the same size while the gaps between them increase. I'm simply want the buttons to go from the top to the bottom. (I have a mockup for this as well but apparenlty i can only include one link)
I've tried hosting the buttons in a FlowLayoutPanel but they do not increase as the dialog stretches, I only get whitespace at the bottom after I run out of buttons. I also tried a TableLayoutPanel and had the same result but I may have misused it. Does anyone have any ideas how I could accomplish this?
Thanks in advance,
Jeremy
To get you started. Use the TableLayoutPanel, set its Anchor property to top, bottom, left, and right. Set the rows and columns to percentages as needed. I suggest each control have it own cell. Note that each control in a "cell" can have its Dock and Anchor property set as needed.
You can do this with a TableLayoutPanel. Create a column for the buttons, with each button having it's own row / cell in the column. Set each row to be an even percentage for height (if there are 10 buttons, each row would be 10%), and dock the TableLayoutPanel to the right side of the screen. Then, put the buttons into their rows and set them to full docking. Then, when the dialog expands, the TableLayoutPanel will expand to fill the entire right side of the screen, each row will adjust proportionally, and each button would expand to fit the new row size.
You may have to adjust this a bit to fit your needs, especially in how it relates to the other content in the window.

Resources