top of page
Search

Open windows in the right place in Eplan Electric P8 scripts (C#)

Writer: Justin Walz
Justin Walz
Nov 14
3 min read

A window that opens on the wrong monitor, or behind Eplan Electric P8, is a small annoyance that makes a good tool feel unfinished. This post shows a short helper that opens your windows centered on Eplan, in front of it (to help it stay there), and fully visible on a screen. It is useful as soon as you build more than one window.

Screenshot of the example dialog

What you will build

A demo window that is centered on the Eplan main window, owned by Eplan to help it stay in front, hidden from the taskbar, and kept fully on a screen, even if Eplan is half off a monitor. The window also tells you where Eplan is on the desktop and which screen it is on, so you can see the logic working.

What you will learn

  • Why StartPosition CenterScreen is not enough inside Eplan

  • What a window owner is, and how to give a dialog one

  • How to find the Eplan window from inside a script

  • Working with multiple monitors and the working area (the screen minus the taskbar)

  • A first look at P/Invoke, which means calling a Windows function from C#

Before you start

  • Eplan Electric P8 with scripting available (the example was run in 2026.0.3)

  • Basic C# is helpful; the P/Invoke lines are there to copy, not to memorize

  • The windows are built with Windows Forms, a .NET window toolkit that Eplan scripts can use

How it works

The reusable part is the EplanWindowHelper class, included in the example file. One line shows any window using the helper's placement rules:

EplanWindowHelper.ShowDialogCentered(myForm);

The helper finds the Eplan window, reads where it is, works out which screen it is on, and sets the position in the form's Load event. By then Windows has applied display scaling, so the size is final and the centering is accurate. If Eplan is minimized or cannot be found, the window is centered on the main (primary) screen instead, so it always opens.

Common mistakes

  • Setting the position too early, before the final size is known

  • Centering on the screen instead of on Eplan

  • Letting a placement problem stop the script; placement is cosmetic, so the helper never throws an error

Try it yourself

Ideas to extend

  • Challenge: size the window as a fraction of Eplan's window

  • Remember where the user drags the window (a later example in this series does this)

  • Reuse the helper in every window you build

Key takeaways

  • Own your windows to Eplan to help them stay in front

  • Always check the result against the screens that exist now

  • Put placement in one helper and reuse it

Community spotlight

  • Who or what: EPLAN Scripting Mastery, Part 1: What Scripting Is and the Perfect Setup, by EPLAN with Chris on YouTube: https://www.youtube.com/watch?v=YmdmBk6I-54

  • Why it is worth a look: A short video on what Eplan scripting is and how to set up your tools, a friendly companion if you are just starting to build windows like this one.

  • Good to know: It is from an independent creator. It suits beginners well.

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


bottom of page