Keeping buttons in the same place and shape - c#

I've been making a stock tracker app in C# with Windows Forms for fun, besides a few issues everything is going relatively well.
Except: I don't know how to make the lay-out do what I want it to do. In particular, I want to makes sure that a set of buttons (add, delete, exit) within a TableLayoutPanel at the bottom always remain in the same space with the same size. I've tried things like docking, setting Min/Max sizes, anchoring, locking but I just can't seem to get it right. They will keep moving around/changing shape.
I've recorded a short video to illustrate my point: https://puu.sh/IszTh/7c31c8e846.mp4
Anyone have any advice? I didn't think it would be necessary to show the code but if you do need it just tell me to edit this post.

As Jimi pointed out in the comments to the question, I hadn't set the absolute value for the TableLayoutPanel containing previously mentioned TableLayoutPanel.

Related

How i can to change the size of a form c# without losing the structure

I made a virtual keyboard in C# Visual Studio, but I have problems when I try to change the dimensions.
This is the virtual keyboard:
and this is when I try to change the dimensions:
I lose the buttons. I found a tutorial where he uses a rectangle.
In this photo is the "main" function, and after I called this function for every button from list (I make a list with all the buttons), I lose all the buttons. Only shift/caps remain because they are special characters.
Your best bet is to anchor the buttons and enable auto size then set the AutoSize mode to grow and shrink.
If all else fails, writing a function to change the font of each button to change down in size according to the size of the form is your only option.
What the problem most likely is is that the font sizes for the individual keys is too big and when you re-scale the keyboard the font doesn't change to compensate for the scaling down in buttons.
(EDIT)
Also, next time you make a post on these forums try to keep up with the formatting and try to use more accurate descriptions of the problem as well as the properties of the buttons because all of my possible solutions are just going off a whim based on prior experience. Thanks
(EDIT EDIT)
Ok I just saw the resizeControl method, I didnt see that before, however, my previous edit still applies. Properties for the buttons would be much appreciated to help answer your question. Also, try to edit the image to instead of being an image, just use the markup language like so:
//Like this
To make it easier for us to use and help debug, if you need to know how, just add 4 spaces before your code. Again, thanks

How to initially place WPF controls on dynamic fullscreen application

Alright, so I'm trying to figure out the best way to accomplish this for my rather unique case. I have a fullscreen WPF application where controls are added to a Grid dynamically and the user is given the option to freely move/resize them. The controls can be individually moved or resized anywhere on the parent Grid but I have prevented them from overlapping via their MouseMove events. They also cannot be moved outside of their container. Since the app will be running on machines with different monitor sizes, I need to take that into consideration when making the original layout. I have an initial layout that I would like to use, but it would seem that I'm out of options:
I first tried using rows and columns just to (initially) place the controls that are added. This method places them correctly but becomes a problem when I need to move or resize the elements because the control is already assigned to a particular row and column. I could try to use this method and then remove any rows/columns after placing the controls, but I don't think that would work well.
I've also considered a Viewbox, but that's not practical in my case for fairly obvious reasons (as it merely resizes the controls to fit the screen). I'd prefer not to use this because I would only need it to standardize my initial layout. That's it. I also don't want to mess up any text that will be displayed on the window.
So yeah, this is more of a "best practice" question because any solution I can think of would not look very professional or elegant. Feel free to ask any questions if you need clarification.
Edit: As an additional note, I'd prefer to stick with a Grid as opposed to a Canvas as my container.
Edit 2: Just to be clear, I would not need the specific (inital) layout after the first launch. When the program exits, the layout (Margins, Width & Heights, etc. for each element) is saved to a file to use for the next launch.
I've developed a number of kiosk/interactive applications using WPF. If you are trying to show the element transitions (while moving), then it might be best to use a parent Canvas and bind the Canvas.Left and Canvas.Top properties. You can mimic the grid alignment, using a Canvas, if you put in place mechanisms (e.g. Manipulation/Mouse events, converters) to make sure that the Canvas attached properties adjust to the row/column offsets.
It is not uncommon at all to use the Viewbox to mitigate display differences (and your use case is not "rather unique"). You set the Viewbox to a target resolution (e.g. 1920x1080) and allow the control to fill the available space. The other alternative would be to dynamically apply a content template based on the application window size/ratio.
After looking at multiple options, I've decided to just use a calculation to (sort of) simulate the behavior of rows/columns. Because my application is fullscreen, I can take my SystemParameters.PrimaryScreenWidth and SystemParameters.PrimaryScreenHeight to orient my layout. Using a combination of universal padding (static values) and ratio-based calculations (dynamic values), I can smoothly set my initial layout.
For instance, I'm dividing the width of my monitor by 6 (rounded up to avoid decimals) and using that (minus half the control's width) as the control's Margin.Left property, centering it on a 'column' of sorts.
Honestly, my initial layout is fairly simple right now, so we'll see if this will suffice going forward. Thanks to everyone who contributed to the question, and sorry if I was unclear on what I was asking.

How to make the elements of a panel have their location adjusted by the size of the panel?

Imagine a panel with 4 PictureBox aligned in one line and then you decrease the size of the window and hence the panel size (it's anchored). Then, when there is no space for 4 PictureBox in one line, the last one goes down to the second line, becoming three PB in the superior line and the forth PB in the second.
If you continue decreasing the window size, the boxes will go down until remain a unique column of PictureBox.
The only idea that came mind was use "if" conditions... Is there an easier way to do that? I thought it could be made by some property of the panel or PB, but I'm wrong I suppose...
Summarizing: How to make the elements inside a panel be adjusted to fit in the panel when you change your size?!
Here it goes a image to illustrate the situation:
#Idle_Mind, Yes, Windows Forms Application. I've forgotten the FlowLayoutPanel, but I don't like it very much, if someone knows some way more easy, feel free to comment. For now, I will use the FLP. Thank you n_n
Just passing to mark the question as answered (on a comment in my question). I didn't use to know controls as FlowLayoutPanel or WrapPanel, etc. Thanks Idle_Mind.

Converting GUI from C# to Java

I'm trying to convert a form which I currently have in C# to Java, utilising layout managers. And it's turning out to be a nightmare.
I've tried setting the sizes of the components, however no difference is present. Also, I cannot get the labels and textboxes to move closer to each other.
For all of the buttons and text fields, just put then in a Panel that has nothing but that one item in it. That will prevent the button/textfield from filling the entire space in the layout.
Other than that the only thing it seems you need to do is put a bit of a margin around the whole thing so that your items aren't right up against the edges of the window.
Try GridBagLayout instead of GridLayout.
GridLayout forces all components to be the same size.
See also javax.swing.Box, to put the label - text field pairs in one pane.

C# Containers -- Filling a Space Vertically on Resize

I'm new to C# and I've been working on a small project to get the feel with Visual Studio 2008. I'm designing the GUI in C#, and I have a TabControl with three GroupBoxes. These three GroupBoxes are anchored to the left and right of the screen and work perfectly when resized horizontally.
I would like these three boxes to take up 33% of the height of the screen, and gracefully resize. I've tried messing around with anchoring, but I can't seem to find the answer. I've also been searching for something similar, but unfortunately, searching for positioning containers yields all CSS and HTML stuff.
This seems like a pretty common thing to do, but I can't seem to find an easy to way to do it. If someone could point me in the right direction, I'd greatly appreciate it.
Thanks!
Try out the TableLayoutPanel. I believe it does exactly what you want. It allows you to define columns and rows within its area, specifying their width (for columns) and height (for rows) in percentages or pixels. You can then drop a group box into each cell and set its Dock property to Fill, and it will nicely resize along with the cell when the TableLayoutPanel resizes (which can be easily achieved by using docking or anchoring).
This is really a shot in the dark but maybe you could try using split-panels ?
Edit: I've just checked in Visual Studio and I think the TableLayoutPanel might do what you want.
Edit2: dang, beaten to the punch :)
Handle the form's Resize event: Add code to compute the new size/position of the controls in there. Beware to interferences with the controls' Anchor property. You may have to Anchor to None and compute left and right position yourself as well.
Since you're learning, I guess you prefer not to receive a full solution but rather a direction. No code from me then ;-)

Categories