Remember window size and position in Eplan Electric P8 scripts (C#)

A tool feels much nicer when its window opens exactly where you left it. This post shows how an Eplan Electric P8 script can remember its window's size and position between runs, and what to do when the saved spot is no longer on any screen.

What you will build
A resizable demo window. Move it, resize it, maximize it, then close it. The next time you run the script it opens where you left it. A Forget saved position button clears the memory. If the saved position is no longer on any screen, for example after unplugging a monitor, the window opens in the center of the screen instead. The example restores size and position; remembering the maximized state itself is left as a challenge below.
What you will learn
Saving small per-user settings in the Windows registry, without administrator rights
Reacting to the form's FormClosed event
Why a maximized window must save RestoreBounds, not Bounds
Checking the saved spot against all the screens that exist now
Writing code that fails without interrupting the user, because remembering a position is only a convenience
Before you start
Eplan Electric P8 with scripting available (the example was run in 2026.0.3)
Some C# experience helps; this is an intermediate example
The window is built with Windows Forms, a .NET window toolkit that Eplan scripts can use
How it works
The reusable part is a WindowMemory class, included in the example file. One line after you set a form up does the job:
WindowMemory.Attach(myForm, "MyWindowName");Values are stored under the current user's registry key, so no administrator rights are needed. Give each of your windows its own name. The position is saved when the window is closed in the usual way, and nothing is saved if Eplan crashes.
Common mistakes
Saving the window's Bounds when it is maximized, which stores the wrong size
Trusting a saved position without checking that a screen still exists there
Letting a failed save stop your script
Try it yourself
Download the example: https://github.com/justin-walzengineering/Eplan-Scripting-GUI-Examples/tree/main/examples/06-remember-window
In Eplan: File > Extras > Interfaces > Run, then select RememberWindow.cs.
Tested with Eplan Electric P8 2026.0.3 (run in Eplan: saved, restored, off-screen fallback, a maximized window reopening at its normal size and position, and a window moved to a monitor on the right and on the left and reopened at the same spot). A first version saved the position again when the window was closed after Forget saved position; the script was changed to skip that save, and a second run in Eplan showed nothing saved after Forget and Close, with the next run opening in the center. No monitor was unplugged in the test.
If you would like to experiment, try it in a test project first.
Ideas to extend
Challenge: remember whether the window was maximized
Remember a splitter position or a column width too
Store the values in a JSON settings file instead of the registry
Key takeaways
Save RestoreBounds for maximized windows
Always check a saved position against the current screens
Remembering is a convenience, so fail without interrupting the user
Community spotlight
Who or what: EPLAN Scripting: Run Your First Script Today, by EPLAN with Chris on YouTube: https://www.youtube.com/watch?v=TLcPWcNcXMA
Why it is worth a look: A short video about the attributes that control how a script behaves in Eplan, useful background for the examples in this series.
Good to know: About 6 minutes, from an independent creator. It suits beginners.
Repository with all examples: https://github.com/justin-walzengineering/Eplan-Scripting-GUI-Examples
Maintained by Justin Walz, Walz Engineering. Questions and ideas for future examples are always welcome, and if you would like help with a script of your own, feel free to get in touch.



Comments