Winform designer resets Label size and position properties - c#

I'm currently working on a project and I need a GUI for it, as I'm making the GUI I add a text/label to my form and when I tried to change the size of it, visual-studio/winform instantly resets it back to its original size, is this a bug?
( this isn't only for size, it also happens to position )

Related

Cannot Resize Form by Dragging In Designer

I have a Winform I want to resize. Not after launching; I want to resize it in the designer by dragging the edges.
I am aware that I can change the size manually in the form properties. This is not what I want to do. I want to quickly size the default size of the form with my mouse.
The problem appears to be that I cannot grab the edges of the form for some reason. I repeat, this is NOT DURING RUNTIME. It is not that I have disabled/enabled Autosize/Resizing.
It's almost like the edge grabs are a single pixel wide and I just can't hit it. I don't know. I've looked for accessibility settings. The last thing I want to do is reinstall MSVS. It's just maddening.
I've attached a photo. The little boxes on the bottom, right, and bottom-right corner are my targets.
you can try to click the form title before resizing. I think you may have a panel (or any container control) which is full docked in the form, that's why when you click the form body, you selected the panel instead of the form.
Another issue that I encountered was the windows font size was set to 120% (or more), so go to windows display setting and set the font size to 100%.

Screen has flickering

I have a problem with screen flickering. I read some other topics on this case, but there are solutions that didn't work for me, I think that's because I don't know what exactly causes the problem.
My screen is has a large number of controls, maybe this is what causes the problem. I'll try to describe it as best, as I can.
First of all, I am using WinForms.
I am making a video game, so the screen should be maximized all the time.
To allow stretching all the controls I am using TablePanels, one large that is docked to fill the whole form and a few smaller that also dock fill the large Table cells. In smaller cells of those tables, Buttons are docked fill.
To show the background drawn buttons, I made control buttons completely transparent. It needs to stay that way.
The screen flickers white at positions of TableLayoutPanels borders.
The screen flickers when a mouse enters the position of a Button, any Button, no matter where it is located.
For now, only one element changes actively during gameplay - a Label. When mouse enters the field of button, this label shows what this button does. For example if I enter the area of "Use" button, the label displays the word "USE".
I haven't tried that yet, but I must implement, that some images of button will change or become transparent, or lose transparency during game-play. Like there could be one image for closed cupboard, but when player opens it, another image of open cupboard appears. I think I know how to do it, all I want is to prevent flickering.
If you suggest using some code (and I expect it will be needed), please specify where I should put it.
It seems problem was solved.
I'll answer my question myself, in case someone else needs it.
The problem was caused by one of labels, although I can't guess why.
I am using a number of TableLayoutPanels, one of them fills the whole form. It has a number of rows, each of them is also a TableLayoutPanel, or just a Panel.
Flickering appeared when I tried to put a label inside main TableLayoutPanel by its own, and not in a sub panel. When I put a Panel inside main Table, and label inside it, the majority of flickering was gone.
To remove it completely, I used both recommendations just in case:
1) DoubleBuffering: Here (answer from Fabjan)
2) Article also recommended by Fabian
After that, only a few minor glitches remained. I did a few tests and it seems that the last glitches happened when mouse left the screen, then returned back inside. My game screen is maximized, so it took some time to check. To fix it, I used an easy command:
"Cursor.Clip = this.Bounds;" on FormLoad
I learned it from another question from this site: Here
Unfortunately, I didn't understand, why misplaced label was behind flickering, but since the problem was solved, I decided to write it here, in case someone else needs it.

Is there a programmatic variable for borders around windows form application?

I am trying to set the maximum size a windows form can be set to, which may be different depending on what data needs to be displayed.
Is there a way to get the size of the borders around your windows form without having to calculate it yourself?
Currently, I have used the difference of the Size and ClientSize properties, like:
windowDressingWidth = this.Size.Width - this.ClientSize.Width;
windowDressingHeigth = this.Size.Height - this.ClientSize.Height;
Which works, but seems a bit backwards. Is there some sort of SystemInformation or similar variable that stores this (like SystemInformation.HorizontalScrollBarHeight does for the scroll bar height).
The closest I've found is SystemInformation.FrameBorderSize, which is 8 on my system, and that is half of my windowDressingWidth (16), so that might be for each side.
In the case of this program, it has no menu, but (on my system) has the aero borders all around, and the thicker one on top for the title and the Maximize, Minimize, and close controls.
The only other one you could need is SystemInformation.CaptionHeight
I should note that this is a bad idea. Always set the ClientSize property instead, that automatically ensures that the window is large enough to provide the client area you need. Also the way the designer works, when you set the form's Size property in the Properties window then the designer actually records the ClientSize value in the InitializeComponent() method. Which ensures your form still works on another machine where the user changed the preferences. Like the caption font and button sizes. Or a machine that has Aero turned off.

How to only Paint viewable content in .net Forms 2.0 CF

I currently have a form with a scrollable panel that potentially contains over 100 child controls (only about 10 are viewable on screen at any time)
This causes a lot of flickering when scrolling.
I have been looking at some double-buffering techniques, but they won't work in my case since I am using several child controls (Buttons, Labels, Checkboxes) and they all get painted independently. I can't do anything in the panel's OnPaint method that affect the children.
And several answers I have read state that adding existing controls take more resources rather than, say, instead of a Label, just painting a colored square with text over top.
I have 2 main questions:
If I were to no longer us child controls, and instead just draw everything in OnPaint of the panel, how can I paint only what is currently visible (considering that the user can scroll)
How would I implement things like check boxes?
1) you would get scroll_position*one_stepscroll .you would find begining item index with scroll_position*one_stepscroll/item.height -1 and last item index with adding
constant item sizes (panel.height/item.height+1 ) .
then u would draw items to backbuffer (as u see from calculations its height will be greater than panel.height of course ) . then show that buffer on panel graphics .so this is how double buffering works .`(if your controls will contain big images to draw then you can use some lazy loading techniques. proxy pattern to speed up scrolling , check this : proxy pattern
1A)if your item.heights differ then you have find first item different way. i would
suggest you for performance to store each items begining position too . this way u will
reduce calculation instead of finding looping throw items and adding heights each time
2)you will get its state and show state . for example u can do . filled rectangle as for checked hollow rectangle for unchecked .(think it will be your own object with additional boolean state property ,or just boolean variable and with its x,y,width,height ) .on panel click you will check click position with visible checkbox items areas . then you would change its state = !state . then again you will redraw whole panel again for visible items .
3)3rd way just change contents when scrolling and use controls . and scrolling step will be one object movement . Trust me on long run user prefer easy workng over fance shamancy things. .just use 10 controls items . and 100 objects storing values for it . on scrolling you would just change those 10 items display properties (text ,state or image or whatever) from 100 objects . this way you will use controls itself .easy solution for performance and memory too.

Changes to Form.Size do not take effect when form is being moved

I have a simple System.Windows.Forms.Form.
Based on business requirements, once certain functionality becomes available as a result of some background processing, I am increasing the form's size and opening up a previously hidden area with additional controls (buttons etc). The changes to the form's size are done by a background thread, using BeginInvoke.
All this works fine. However, if the user is dragging around the form on the screen, and coincidentally during this time the method that changes form's size is called, the size change does not become effective (technically, the form changes size, but instantaneously reverts to the previous size).
I am changing the form size by setting the Form.Size property, but have tried other ways like setting Form.ClientSize, and calling Form.SetBounds(). Have also tried out Form.SuspendLayout()/Form.ResumeLayout() and forcing Form.PerformLayout().
Nothing I have tried so far works, and when it is being moved around, the form refuses to change size.
Put code in the Form_LocationChanged event to detect if the previously hidden area is visible (or should be via a bool variable) and resize the form accordingly. Otherwise the ResizeEnd event fires after a move ends, try that.

Categories

Resources