I've been using ChildWinForm to host WinForms in my VO-converted application.
Is it possible to add a QueryClose event for ChildWinForm and get it to access a property of the WinForm?
(ie If the user clicks the X of the ChildWinForm header can I stop the form closing?)
In VO I coud just subclass and add a QueryClose method but can't work out how to do that in XSharp.
Thanks
Leigh
ChildWinForm and QueryClose
ChildWinForm and QueryClose
Leigh,
The ChildWinForm class is a normal subclass of ChildAppWindow
See: https://www.xsharp.eu/runtimehelp/html/ ... inForm.htm
So you can create your own subclass of ChildWinForm and add a QueryClose() method.
In that method you can access the Windows Forms object (The WinForm property gives you access to the form).
The source to the ChildWinForm class can be seen here:
https://github.com/X-Sharp/XSharpPublic ... inForm.prg
Robert
The ChildWinForm class is a normal subclass of ChildAppWindow
See: https://www.xsharp.eu/runtimehelp/html/ ... inForm.htm
So you can create your own subclass of ChildWinForm and add a QueryClose() method.
In that method you can access the Windows Forms object (The WinForm property gives you access to the form).
The source to the ChildWinForm class can be seen here:
https://github.com/X-Sharp/XSharpPublic ... inForm.prg
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
-
- Posts: 60
- Joined: Tue Oct 11, 2016 8:56 pm
- Location: UK
ChildWinForm and QueryClose
Hi Robert
OK thanks - I think when I tried earlier I ended up trying to subclass the Windows Form rather than ChildWinForm!
I have my QueryClose now - something like this:
Only remaining question is can I make it more generic?
i.e. if all the forms I'm testing have the AllowClose() method can I call it without casting SELF:WinForm to the specific form?
Leigh
OK thanks - I think when I tried earlier I ended up trying to subclass the Windows Form rather than ChildWinForm!
I have my QueryClose now - something like this:
Code: Select all
CLASS MyCWF INHERIT XSharp.ChildWinForm
METHOD QueryClose(oEvent) AS USUAL CLIPPER
LOCAL lAllowClose AS LOGIC
LOCAL oWF AS Form1
lAllowClose := SUPER:QueryClose(oEvent)
//Put your changes here
oWF:=(Form1)SELF:WinForm
lAllowClose := oWF:AllowClose()
RETURN lAllowClose
END CLASS
i.e. if all the forms I'm testing have the AllowClose() method can I call it without casting SELF:WinForm to the specific form?
Leigh
ChildWinForm and QueryClose
Hi Leigh,
If all your forms have this method, then you can create a base form class, inheriting from Form (and having all the other forms inheriting from this base form) and declare the AllowClose() method also in this class, so you can cast the object to that base form.
Or, if you want to do it in a more "neat" way, you can use an interface instead of a base class: Declare one as:
INTERFACE IAllowsClose
METHOD AllowClose() AS LOGIC STRICT
END INTERFACE
and then simply have all your forms implement this interface with using an "IMPLEMENTS IAllowsClose" clause in your class declarations. This way, you can simply cast the object to this IAllowsClose interface.
If all your forms have this method, then you can create a base form class, inheriting from Form (and having all the other forms inheriting from this base form) and declare the AllowClose() method also in this class, so you can cast the object to that base form.
Or, if you want to do it in a more "neat" way, you can use an interface instead of a base class: Declare one as:
INTERFACE IAllowsClose
METHOD AllowClose() AS LOGIC STRICT
END INTERFACE
and then simply have all your forms implement this interface with using an "IMPLEMENTS IAllowsClose" clause in your class declarations. This way, you can simply cast the object to this IAllowsClose interface.
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
-
- Posts: 60
- Joined: Tue Oct 11, 2016 8:56 pm
- Location: UK
ChildWinForm and QueryClose
Hi Chris
I went for the "neat" option and I have it all working now.
Thanks again for your help.
Leigh
I went for the "neat" option and I have it all working now.
Thanks again for your help.
Leigh
ChildWinForm and QueryClose
Hi Leigh,
Thanks, that would be my favorite way as well, as it also makes sure that you do not forget to implement the method in one of your new form classes, otherwise the compiler will complain. One of those nice side effects on moving to a more modern language like X#
Thanks, that would be my favorite way as well, as it also makes sure that you do not forget to implement the method in one of your new form classes, otherwise the compiler will complain. One of those nice side effects on moving to a more modern language like X#
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu