0

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.

  • 1
    Just anchor the Buttons on the left to Left/Bottom and the Button on the right to Right/Bottom. -- Remove any other setting / coded procedure you may have used besides this. – Jimi Nov 30 '21 at 14:14
  • Could you give me a hint which settings could affect this? I tried anchoring them as you said and removing everything else, but they still change size when I change the size of the form – borovanhout Nov 30 '21 at 14:55
  • 1
    Could it be the fact they're set in a TableLayoutPanel that's messing things up? – borovanhout Nov 30 '21 at 14:55
  • 1
    If the Buttons are contained in Cells of a TLP, then the TLP should be docked to the bottom of your Form, its Cells set to auto-size to their content (so the Cells' size is determined by the size of the Buttons). Leave one free Cell in the middle, to fill the gap. – Jimi Nov 30 '21 at 15:13
  • Alright that helped a bit. The exit/add buttons now always remain in the same place when I make the form larger. However, there is a large visible gap between the add ticker and delete ticker buttons that I don't want to have there. For reference: https://puu.sh/IsAIS/cbfba136ec.png Also, when I make the screen smaller the button still falls off: https://puu.sh/IsAIX/180b12af55.png – borovanhout Nov 30 '21 at 15:15
  • Maybe a dumb question, but how am I supposed to edit the values of a single cell? They don't show up in the properties tab, or am I supposed to do so through code? – borovanhout Nov 30 '21 at 15:16
  • 1
    I suppose you use the TLP for the Buttons only. If that'not the case, then it should. In this senario, a TLP with 1 Row and 4 Columns (add more, eventually), the setting of each Cell is simply determined by the settings of its Column. – Jimi Nov 30 '21 at 15:21
  • I guess what I'm really looking for is a way to make sure the buttons always stay completely visible/same size – borovanhout Nov 30 '21 at 15:21
  • 1
    If the TLP is dockedd to the Bottom of a Form, its content will always be visible, of course. To have the Button always of the same size is less simple if you support multiple languages and Font/DPI scaling. If you don't, then maybe set the maximum/minimum size of your Buttons. -- Only the middle Cell (Column) of your TLP changes width. The others either autosize or use a fixed width. – Jimi Nov 30 '21 at 15:27
  • Alright that actually fixed the issue for the largest part, thanks a bunch! However, the buttons still fall off when I make the form too small (in either height or width). Is there any way that I can prevent this from happening (i.e., making sure the form prevents me from making the screen so small that the buttons fall off). Or should I make a new post for that issue? – borovanhout Nov 30 '21 at 15:35
  • 1
    Set the MinimumSize of your Form to a *discrete* value. -- Note that you can set just one of the dimensions of the Minimum/MaximumSize properties -- Also consider what will happen in a Screen with different Font or DPI scaling. – Jimi Nov 30 '21 at 15:41
  • The only issue that persists is that the buttons are still falling off the bottom of the screen like this: https://puu.sh/IsBmP/f06dbfe1e7.png I docked the TLP to bottom and set all the min/max sizes for the buttons and the form like you said, not sure what could still be going wrong. Am I forced to set the min height even higher? BTW: If you would write your next comment as an answer, I could select it as the right answer :) Thanks a bunch for all your help! – borovanhout Nov 30 '21 at 16:16
  • If the TLP is *pushed* down even when docked, then there's another Control that doesn't resize with the Form that causes this. So, yes, set the minimum height of your Form(s) to a higher value (keeping in mind what has been said before about the Screen scaling) -- Unfortunately, I cannot post answers as of now. I usually post an animation that explains the procedure in these cases; now I cannot. -- If you find an adequate solution using these hints, post the answer yourself. – Jimi Nov 30 '21 at 16:29

1 Answers1

0

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

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92