Configurator - Form Styling Properties

Is there a way to get to the form object variable inside a configurator (this)? Or a way to get to the form border styling properties?

I see @Aaron_Moreng showed how to do this with a customization (Center Screen on Load via c# Customization - #7 by Aaron_Moreng), but I’d like to “fix” the border style of a configurator instead of allowing them to re-size it.

Any ideas?

Thanks,

Josh

I don’t have configurator but there is a property to lock the size of a form, is that what you’re going for? I assume you tried this

You can do this

 Form fc =  System.Windows.Forms.Application.OpenForms["ConfigurationRuntimeForm"];
  fc.StartPosition = FormStartPosition.CenterScreen;
  fc.MaximizeBox = false;
  fc.MinimizeBox = false;
  fc.FormBorderStyle = FormBorderStyle.FixedDialog;
3 Likes

Another one that can be used if you want to remove the ability to click X to close the window.

fc.ControlBox = false;
1 Like

The problem I can’t seem to resolve is how to get to the form object itself (this) in order to set these properties.

If I try setting the code below (this is referring to the current object in which it is contained in), I get a syntax error message image

“this” is referring to an Event Collection. However, I need to get to the form object itself to set the properties.

this.FormBorderStyle = FormBorderStyle.FixedDialog;

Any ideas on how I get to the form object?

Did you try @danbedwards 's line:

 Form fc =  System.Windows.Forms.Application.OpenForms["ConfigurationRuntimeForm"];

If that doesn’t work, you can try using the inputs control property, and then get its parent.

The “ConfigurationRuntimeForm” object exists only after the form completely loads. If I place this code in the On Loaded event, I get an “object not set to an instance of an object”. However, as a test, if I place the code in a button, it finds it.

string forms = “”;

foreach (var f in System.Windows.Forms.Application.OpenForms)
{
forms += f.ToString() + “\n”;
}
MessageBox.Show(forms);

Inside On Loaded event:
image

Inside Button click event:
image

You can see the ConfigurationRuntimeForm at the bottom which doesn’t exist in the On Loaded list.

Any other way to set this after knowing when the object is available?

I used this in On Page Loaded (can sometimes be redundant)

Thanks for you help @danbedwards and @Aaron_Moreng. I’ll mess around with it here some more.

1 Like

Wait, are you running this code in the configurator, or a customization on a form that can luanch the configurator?

Inside a configurator.

The “ConfigurationRuntimeForm” object exists only after the form completely loads. If I place this code in the On Loaded event, I get an “object not set to an instance of an object”. However, as a test, if I place the code in a button, it finds it.

string forms = “”;

foreach (var f in System.Windows.Forms.Application.OpenForms)
{
forms += f.ToString() + “\n”;
}
MessageBox.Show(forms);

Inside On Loaded event:
image

Inside Button click event:
image

You can see the ConfigurationRuntimeForm at the bottom which doesn’t exist in the On Loaded list.

Any other way to set this after knowing when the object is available?

Did you try this in On Page Loaded? This event is where you will want to place this.
image

Yes.

After I place the code in the On Loaded event of the configurator, I Test Inputs and receive this error…

It’s because the FormsCollection doesn’t contain “ConfigurationRuntimeForm” object at the point On Loaded fires. However, if I run this code in a button click, it works.

Not sure why the “ConfigurationRuntimeForm” object doesn’t exist when the event fires.

This code will not work in the On Loaded event of the configurator and should be just in the Page On Loaded. Having it only in the Page On Loaded will do what you want. If you remove all code from your On Loaded of the configurator does this then pass the syntax check?

Is the Page On Loaded event here?

If this is the Page On Loaded area, I have the code inside, but still get the same error.

That is the Configurator On Loaded Event. See this for On Page Loaded event

That was were I first placed the block of code and received the Null Exception reference error. Same as the Configurator On Loaded.

So this is interesting. In Page 2 On Page Loaded this works which is where I have used it. For Page 1 it does not work. I am checking to see if something else is going on.

If you dump this code in Page1 On Loaded event and Page2 On Loaded event, you can see that “ConfigurationRuntimeForm” object doesn’t exist (at the bottom of the messagebox) on Page 1, but does on Page 2.

string forms = “”;
foreach (var f in System.Windows.Forms.Application.OpenForms)
{
forms += f.ToString() + “\n”;
}
MessageBox.Show(forms);