4

I have a Form which contains controls whose properties', such as their positions, are defined in a resx file, like so:

Form1.rex:

<data name="textBox1.Location" type="System.Drawing.Point, System.Drawing">
<value>15, 61</value>

And those properties are then retrieved using the following method call:

resources.ApplyResources(this.textBox1, "textBox");

What I want though, is to get rid of this method call as well a the resx file, and directly set the control properties in the designer.cs file, like so:

Form1.Designer.cs:

textBox1.Location = new System.Drawing.Point(15,61);

Of course I could do this manually, but I have a lot of Forms and it would take me a while so I was wondering if there was some way to do this?

Toto
  • 736
  • 9
  • 33
  • Are you not using Visual Studio? Every time I've done winforms UI in VS, it always uses the *.designer.cs file automatically... – Broots Waymb Feb 12 '18 at 20:55
  • I am using Visual Studio 2017. I am working on a project which has been written, maybe 5 or 6 years ago though, so I am dealing with code migration here, not implementing new code. – Toto Feb 12 '18 at 21:08
  • Just did a quick search, but maybe try this? https://stackoverflow.com/a/14153997/2957232 – Broots Waymb Feb 12 '18 at 21:11

1 Answers1

4

I found the solution, for those facing the same issue, what you need to do is simply set the "Localizable" property of the form to false. This will cause all the properties of the different controls to be coded in the designer, and not be dynamically retrieved at runtime from the resource file.

enter image description here

Toto
  • 736
  • 9
  • 33
  • How was this parameter set to `true`? The default is `false`. – Tobias Knauss Mar 26 '20 at 14:39
  • @TobiasKnauss Yes, `Localizable` is `false` by default indeed, but OP mentioned he inherited an old C# WinForms project. So I'm assuming the previous author chose to set that setting to `true` for all forms. I found myself in a similar situation before with legacy projects. – Fabien Teulieres Apr 10 '23 at 22:34