From 07fd6644859abc8af1416023dd155754b7620d04 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 11 Jun 2021 01:39:24 +1000 Subject: [PATCH] Set FormBase.Text in its ctor (fixes #2759) --- src/BizHawk.Client.EmuHawk/FormBase.cs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/FormBase.cs b/src/BizHawk.Client.EmuHawk/FormBase.cs index 8add78e0df..be58841137 100644 --- a/src/BizHawk.Client.EmuHawk/FormBase.cs +++ b/src/BizHawk.Client.EmuHawk/FormBase.cs @@ -13,6 +13,8 @@ namespace BizHawk.Client.EmuHawk { public class FormBase : Form { + private const string PLACEHOLDER_TITLE = "(will take value from WindowTitle/WindowTitleStatic)"; + /// /// Under Mono, SystemColors.Control returns an ugly beige.
/// This method recursively replaces the of the given (can be a ) with @@ -39,15 +41,26 @@ namespace BizHawk.Client.EmuHawk public override string Text { get => base.Text; - set => throw new InvalidOperationException("window title can only be changed by calling " + nameof(UpdateWindowTitle) + " (which calls " + nameof(WindowTitle) + " getter)"); + set + { + if (DesignMode) return; + throw new InvalidOperationException("window title can only be changed by calling " + nameof(UpdateWindowTitle) + " (which calls " + nameof(WindowTitle) + " getter)"); + } } protected virtual string WindowTitle => WindowTitleStatic; /// To enforce the "static title" semantics for implementations, this getter will be called once and cached. - protected virtual string WindowTitleStatic => DesignMode - ? "(will take value from WindowTitle/WindowTitleStatic)" - : throw new NotImplementedException("you have to implement this; the Designer prevents this from being an abstract method"); + protected virtual string WindowTitleStatic + { + get + { + if (DesignMode) return PLACEHOLDER_TITLE; + throw new NotImplementedException("you have to implement this; the Designer prevents this from being an abstract method"); + } + } + + public FormBase() => base.Text = PLACEHOLDER_TITLE; protected override void OnLoad(EventArgs e) {