The WinForms.Adapter class is used as a base class for an AddIn's Form. It provides a Restore() method, but its purpose is not documented.
WinForms.Adapter
Form
Restore()
I already wrote my own Restore() method whose purpose is to show a minimised Window in its previous state...
/// Restore this Form from minimised to maximised. public void MyForm.Restore() { if (WindowState.HasFlag(System.Windows.Forms.FormWindowState.Minimized)) { WindowState = System.Windows.Forms.FormWindowState.Normal; } }
However, WinForms.Adapter.Restore() doesn't do that. What does it do?
WinForms.Adapter.Restore()
[Edit] The Restore() method works when MyForm inherits from Bentley.MstnPlatformNET.WinForms.Adapter...
Bentley.MstnPlatformNET.WinForms.Adapter
MyForm : Bentley.MstnPlatformNET.WinForms.Adapter
See this article about a TopLevelForm base class for more detail.
Hi Jon,
Jon Summers said:What does it do?
it's clear when you will check how this method is implemented. Internally, it calls mdlNativeWindow_restore function.
Jon Summers said:However, WinForms.Adapter.Restore() doesn't do that.
Just a guess: is you form attached to MicroStation?
Unfortunately, native function returns StatusInt, but managed wrapper swallows this information.
With regards,
Jan
P.S. What is the reason to use obsolete WinForms technology, when MicroStation CE is WPF based (and WPF offers far more features)?
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Jan Šlegr said: Is your form attached to MicroStation?
public partial class MyForm : Bentley.MstnPlatformNET.WinForms.Adapter
I had assumed that inheriting from WinForms.Adapter would attach automatically. Have I missed a step?
Regards, Jon Summers LA Solutions
Jon Summers said:I had assumed that inheriting from WinForms.Adapter would attach automatically.
I think this assumption is wrong. At least: How Adapter class can know how the from will be used and to what parent it should be attached?
Jon Summers said:Have I missed a step?
It's my guess only, but I think AttachAsTopLevelForm establish MicroStation application window as a context for the form, so it is able to behave as MicroStation dialog and not as general WinForm.
Jan Šlegr said: I think AttachAsTopLevelForm establish MicroStation application window as a context for the form, so it is able to behave as MicroStation dialog and not as general WinForm
public virtual void AttachAsTopLevelForm( IMatchLifetime addIn, bool useMicroStationPositioning, string name )
All the AttachXxx methods take a parameter IMatchLifetime, which is not documented anywhere. SDK example WPFSample shows how to attach...
AttachXxx
IMatchLifetime
this.Attach (WPFSampleApp.Instance, "WPFSampleDock", new SD.Size (100, 100));
That is, an Bentley.MstnPlatformNET.AddIn implements that interface.
Bentley.MstnPlatformNET.AddIn
Answer Verified By: Jon Summers
Jon Summers said:which is not documented anywhere.
Well, it's not, but API documentation provides enough information: IMatchLifetime addIn.
Jon Summers said:How does one obtain an IMatchLifetime object to pass to an AttachXxx method?
When you will check why the parameter is named addIn and will check how Addin class is implemented, it implements IMatchLifetime interface:
So, where IMatchLifetime object is required, just pass your Addin instance.
Regards,
I've summarised the outcome of this thread in a TopLevelForm base class. It's described here.
TopLevelForm
TopLevelForm handles the interface with MicroStation, so it's easy to minimize/restore your form. It also integrates with Viz Studio at design time, as suggested by Maury elsewhere.
Thanks for your help!
If I remember correctly, the minimize/maximize implemented by Bentley was a little wonky... Especially when working on a second monitor.Adding these lines allows the dialog to behave more so like a traditional windows dialog.
public override void Maximize() { WindowState = FormWindowState.Maximized; } public override void Restore() { WindowState = FormWindowState.Normal; } public override void Minimize() { WindowState = FormWindowState.Minimized; } #if DESIGN #else protected override void WndProc(ref Message m) { if (274 == m.Msg) { uint num1 = (uint)(m.WParam.ToInt32() & 65520); if (61488 == (int)num1) { Maximize(); IntPtr num2 = new IntPtr(0); m.Result = num2; return; } if (61728 == (int)num1 && WindowState == FormWindowState.Maximized) { Restore(); IntPtr num2 = new IntPtr(0); m.Result = num2; return; } } base.WndProc(ref m); } #endif
We've travelled in time to the 20th century Win32 world of magic numbers and message crackers!
Jon Summers said:We've travelled in time to the 20th century Win32 world of magic numbers and message crackers!
Yes, because WinForms are exactly that: obsolete technology behind the zenit, in the case of MicroStation with extra portion of bugs caused by the weak implementation of Adapter class.
Not only because of discussed weirdness and bugs, I do not see a single reason why to use WinForms over WPF in MicroStation CE.