Visual Studio WinForm Bug Or Am I Doing Something Wrong? - c#

I have a WinForm that mysteriously changes height seemingly randomly. Usually everything is evenly spaced, but sometimes when I look back at my form, it has a large margin under the bottom button.
screenshot: http://min.us/mv00PK
This is pretty weird, I'm not sure what's going on here, but I hate changing it back each time it happens. Whatever the case may be, I'm not manually changing the height so that gap is there, but could I be doing something else that causes this to happen?
Please let me know if you have an idea of what's happening here, thanks!

when I look back at my form, it has a large margin under the bottom button
There are about a dozen factors involved (FormBorderStyle, ScaleMode, FontSize, Anchors, Docking, ...).
You mentioned exactly 0 of them.
I'm not sure what's going on here
Neither are we.

Override or subscribe to the form size changed event, and set a breakpoint in it in the debugger. This will let you know what operation it is that causes the form to change size. From there, you should be able to debug it.

If you find the gap appearing consistently, yuo can consider setting the MaximumSize property of the form to the desired size. That should prevent it from growing.

Related

Keeping buttons in the same place and shape

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.

C# WinForms Panel Child Positioning Being Very Wonky?

Here is the problem. If you dynamically place controls in a panel, it works fine, but only until the vertical scrollbar appears. Once there is enough content for this to happen, it starts positioning controls nonsensically.
In my window, you can click a button to add another row of controls inside the panel, which represent options for an item in a list. If you scroll the vertical scrollbar on the panel all the way down and click the button again, the new row of controls will be positioned below the bottom edge of the panel out of view. If you scroll down, there is a huge gap between the new row and the previous row of controls. This should not happen. The positioning code is working flawlessly, as proven by debug output. As far as I can tell, the problem is the stupid anchoring system, however disabling anchoring on these controls does not fix the problem as one might expect. Instead, it just makes it position them wrong in a different manner. This makes no sense at all, and is super annoying!
I tried disabling Autoscroll in code before controls are added to the panel. No change. So I modified that code to disable both the vertical scroll bar and Autoscroll and set the scrollbar to not visible before controls are added. No change again, except that the now disabled vertical scrollbar still manages to appear usable when there is enough content in the panel in spite of it being disabled and set not visible!? That's not supposed to happen when I disabled and made it invisible! With anchoring disabled on the controls being added to the panel and once the vertical scrollbar has appeared, clicking the button to add a few more rows of controls now causes them to be indented a bit for no reason and positioned overlapping each other a bit vertically! It's as if the coordinate system in the panel has somehow arbitrarily changed, because of the presence of a vertical scrollbar and anchoring being disabled on the controls? The debug code shows that the controls are all being placed at correct coordinates, yet they appear positioned very wrongly. So my code is working perfectly, and therefore something else is the problem here.
Everything behaves exactly as expected up until the vertical scrollbar appears. This is so bizarre. Does anyone have any idea what on earth is going on with this stuff? Apparently it is far easier to make it do stupid stuff than to get it working properly.
Thanks again! I got it working. I went with TaW's solution first since it seemed like the simplest solution. Incidentally, I already tried TaW's approach days ago when I was fighting with it, but I had naturally subtracted the AutoScrollPosition value rather than add it, because I didn't expect it to be a negative value!
It seems very odd that control positioning is relative to the current AutoScrollPosition, as absolute coordinates seems like a much more natural, intuitive approach than having negative numbers. I guess that would make it slightly harder to place a control in the currently visible area, but I suppose that's not a big deal as most scrollable interfaces are probably initialized ahead of time and don't need to do that anyway.

Resizing columns not refreshing properly

I made some change, I don't know what, and now when I try to resize columns on my DataGridView it just moves the line the control doesn't redraw properly. Basically parts of the control just don't redraw at all until I do something like move another window over them to force a redraw.
The only thing I can think of is that I tried suspending and resuming layout to fix another issue. It didn't work so I removed those lines of code. Don't see how that could affect it since those lines of code are not even there anymore though?
Not even sure how to debug this further.
I added a call to Refresh() the control in its OnColumnDisplayIndexChanged event and that seems to have fixed it.
A strange, but not problematic, side effect is that I can now see the columns moving for a half a second as the application programmatically sets the column widths after loading data. I guess this makes sense, however in the past it would only display after the code had updated the widths. But oh well, that's not a big deal.

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 do I get two panels to share a parent's width in Devexpress

This sounds simple to me but I'm not sure if there's a best/suggested way to do it.
I'd like my UI to have a panel docked along the top, split into two panels, left and right, that always share the width of the parent equally. There'll be a minimum overall width so nothing gets squashed, but on resizing I'd like the two panels' widths to always be equal.
I thought of using a split container control but it doesn't do what I want in this case as I can't disable manual resizing.
My current idea is just to override the onResize method (forgot the exact name), and just manually set the two widths to parent.width/2, but it seems a bit roundabout, and potentially slow if it's calling onResize for every pixel's worth of movement.
Is there a better way to do this, or a control/layout that handles this for me?
Disclaimer: I'm using an older version of DevExpress, 10.1.4. It's not my decision and I don't think I can get the team to upgrade at the moment. Using C# on .Net platform 3.5.
I would drop a couple of panels onto the form and set their Size within the form's ResizeEnd event handler. This looks to be the best solution from my point of view.
You can use the XtraLayoutControl to achieve this, but that might be overkill.
Otherwise, you'd have to do it manually.

Categories