i find a mistake in method resizeControl not int newX = (int)(r.Width * xRatio); int newY = (int)(r.Height * yRatio); true its: int newX = (int)(r.Location.X * xRatio); int newY = (int)(r.Location.Y * yRatio);
Would you mind remaking this tutorial with a bunch of controls of many different types. I tried it your way, precisely, but regardless of what I set the anchor property of a control to inside visual studio, the second the form got smaller than it’s initial size all the controls decided to throw a party on top of one another in the upper left hand corner. Even if the distance between the bottom of the form and the controls that were set to anchor at the bottom prior to resizing vs the distance between the bottom of the form and the bottom of the control set to anchor at the bottom were not even *remotely* similar. You’d think the y coordinate of the controls set to anchor at the bottom would be less after resizing than they were prior, right? Nope. Bigger. The (maybe) good news is I have managed (I think) to eliminate the need all the rectangle variables in the form load and the partial class except for the form size. I just declared/initialize the form size variable in the class and in the load method the way you said. Then I eliminated the resize method and put all the dirty work in the in form resize method. Like this: Form1_Resize(//the normal stuff here) { Int xRatio= this.width/ o.f.s.Width; //tried it as a float but still don’t work your way) int yRatio = this. Height/ o.f.s.height; Int initialX; Int initialY; int initialWidth; Int initialHeight; foreach(Control con in panel1.controls) { Con.width = initialWidth; Con.height= initialHeight; Con.Location.x = initialX; Con.Location.y = initialY; Con.Location = new Point(initialX*xRatio, initialY * yRatio); Con.Size = new Size(initialWidth * xRatio, initialHeight* yRatio); } } PS: before anyone tells me that I can’t blame him for my own code not working….I did it exactly the way he said in the video originally. The behavior of the controls were exactly the same as it is rn, at least when it comes to shrinking the form. At least this way I don’t have like a gazillion extra rectangle variables.
Thanks for this. I'm complete new to C#. I've dipped my toe into C# because I want to create a "launcher" window on startup where a user picks one of 2 applications. (for a home arcade setup, which won't have a keyboard or mouse - only a joystick/buttons which pass key presses) I've managed to create a static sized form window that works with both buttons. But now I want to see if I can make the window maximized and resize the buttons properly, regardless of the actual screen resolution. In my scenario, the window will not be resizable, but simply always maximized. Hopefully your tips here will guide me down that road.
Thank you for making this creative idea ! Not to say anything bad about this idea but I guess it is not really optimal and usable in reality ? Because I see people only make windowed mode or full-screen mode for apps. I also think this code really consumes memories as it literally render everything visible before our eyes in real time, and let's say we don't have just 1 button but thousand of actions at the moment. How do you think about my opinion ? Still, thanks for sharing this :D
I think that since the action is only called on form resize that it actually isn't too intensive? It only runs while the form is being actively resized
you neew to make the following corrections: int newX = (int)(r.Location.X * xRatio); int newY = (int)(r.Location.Y* yRatio); instead of int newX = (int)(r.Width * xRatio); int newY = (int)(r.Height* yRatio);
Great video, I am creating a borderless form application which has forms loaded within a panel on the mainform, I wish to drag and drop between 2 different screen resolutions, however the control is not resizing with the form when dragged from the smaller on to the larger one. If i close the childform on the larger screen and reopen it, it is correct size.
Is it possible to select all elements in my application without having to write a 'buttonOriginalRectangle' for each element? I have 7 buttons, 1 picture box, a menu strip, and a label, and I want them to dynamically resize perfectly.
Thanks it also works on visual studio 2019 cause 2019 and 2022 don't have much difference also good content keep it up! But how do I use it for multiple buttons and object? Or even for all object in the form?
Thanks for video. But I have problem and I cannot find solution. It works on computer where is visual studio. When I copy release build to the other computer where is not VS, the resize function causes the controls to not be displayed at all. If I comment resize function controls are showen. Do you have some idea?
Thanks for the kind words and glad you enjoyed it, that is a weird bug I don’t think I have heard of before. Feel free to add me on discord and I can take another look if you’d like
okay. but o. s.s that allow real time proportional sizing of all objects in a window. all objects shrink. everything in the window remains. just that reducing the size of a window makes the complete image shrink. guess it's hard to articulate.
Only works if you have one control. If you add controls they all go to the same position or stack on top of each other. This is more confusing than leaving it and just losing it when resizing.
Change newX and newY lines like this int newX = (int)(r.Location.X* xRatio); int newY = (int)(r.Location.Y* yRatio); you should use r.Location, not r.Width or r.Height
Thanks for the video. I am so close to actually making it work for me and yet so far. For some odd reason my "button1" cannot be called in my "resizeControl" function because it is of class Forms::button(Forms.button for C#) instead of Forms::Control (Forms.Control for C#) and it messes up my project. I would just copy ur entire project but I am trying to implement it on c++...
Unfortunately, your solution is also not true scaling. It is a good dirty method to fix a one off issue, but lacks text scaling and alignment anchoring. Thanks anyways.
I tried this with my picture box. I'm sure I've got everything correctly but every time I resize my window it just dissapears. Any ideas why? Edit: got it all sorted. Found solution in comments.