-1

I want to change the size of all forms in my desktop solution. I am sure I need to change in the designer file of every form a line like below:

this.ClientSize = new System.Drawing.Size(932, 620);

to the one below

this.ClientSize = new System.Drawing.Size(1366, 768);

These forms currently have different sizes but I want all of them to have same size. I tried a search replace but that doesnt work because the sizes for each from are different. I am think maybe if I search by regular expression it might work but have no clue about the regex needed to find all occurrences and replace them.

I am using VS2019 and it's winforms. Anyone please help.

41686d6564
  • 15,043
  • 11
  • 32
  • 63
  • Why do you want to hardcode this resolution? What if a user has a smaller screen or doesn't want to run the app fullscreen? What regex have you tried? Replacing `this.ClientSize = (.*);` with what you want should work... – CodeCaster Jan 23 '21 at 11:53
  • 1
    `CTRL + H`, then search for `this.ClientSize = new System.Drawing.Size\(.*\)` and replace with `this.ClientSize = new System.Drawing.Size(1366, 768);` – Jimi Jan 23 '21 at 11:56
  • I appreciate your response. So my objective is to have all forms start off as maximised but when a user Clicks a restore button on the form the form should restore to the same design size (1366, 768). I am trying to avoid an unpleasant look and feel issue where one for restores to one size and the other to another size. Is this the right approach I am taking? – Mutongi Gava Jan 23 '21 at 11:56
  • Usually, a Window is restored to the size the User set it. It's a User preference. Unless you want to set the MinimumSize... – Jimi Jan 23 '21 at 11:59
  • *"I tried a search replace but that doesnt work because the sizes for each from are different"*. The F&R dialogue supports regular expressions so you should look into that. That will enable you to search for specific text containing any numbers. – jmcilhinney Jan 23 '21 at 12:08
  • That said, how many forms do you have? How hard would it be to just F&R "this.ClientSize = new System.Drawing.Size(" and then paste in the numbers? – jmcilhinney Jan 23 '21 at 12:09
  • There are quite many across several projects in that solution – Mutongi Gava Jan 23 '21 at 12:15
  • If all the forms should have the same size, it basically means you need to use a shared settings for all the forms and bind the Size property to that setting. Another option is deriving from a base form and setting such properties in the base form. – Reza Aghaei Jan 23 '21 at 13:34
  • To apply Jimi's answer, make sure you check "Use regular expressions" in find/replace window. – Reza Aghaei Jan 23 '21 at 13:35

1 Answers1

2

Make your Find/Replace window look like this:

Find and replace dialog

  • Find: \.ClientSize = new System\.Drawing\.Size\(\d+, \d+\)
  • Repl: .ClientSize = new System.Drawing.Size(1366, 768)
  • Ensure that .* button is highlighted
41686d6564
  • 15,043
  • 11
  • 32
  • 63
Caius Jard
  • 47,616
  • 4
  • 34
  • 62
  • @41686 thanks for the edits, though I'm not sure it matters too much about the literal dot match, because . matches . (and I don't think the project will contain anything else that will match..) – Caius Jard Jan 23 '21 at 17:51