Windows.Forms and the VO.App class

This forum is meant for questions and discussions about the X# language and tools
User avatar
Kees Bouw
Posts: 172
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Windows.Forms and the VO.App class

Post by Kees Bouw »

When a new VO MDI application is created in Visual Studio, this is the code in Start.prg:

Code: Select all

[STAThread];
FUNCTION Start() AS INT
    LOCAL oXApp AS XApp
    TRY
        oXApp := XApp{}
        oXApp:Start()
    CATCH oException AS Exception
        ErrorDialog(oException)
    END TRY
RETURN 0

CLASS XApp INHERIT App
    METHOD Start() 
        LOCAL oMainWindow AS StandardShellWindow
        oMainWindow := StandardShellWindow{SELF}
        oMainWindow:Show(SHOWCENTERED)

        SELF:Exec()
   RETURN NIL
END CLASS
I am converting an existing VO application to X# with the intent to eventually change all VO windows to Windows.Forms forms. So I started with a new Windows Forms Application, where the startup code in Program.prg is:

Code: Select all

USING System
USING System.Collections.Generic
USING System.Linq
USING System.Text
USING System.Windows.Forms

USING WindowsFormsApplication

[STAThread] ;
FUNCTION Start() AS VOID

Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault( FALSE )
Application.Run( Form1{} )

RETURN
Then in the Form1 Load event, I execute the code from Start.prg in the first listing. Is this the best way to do this? Is it really necessary to use the VO.App object to be able to use VO windows? It does seem possible to create VO windows right there in the Form1 Load event, without creating a VO.App object.
The reason I ask is that when using a VO.App object created from a Windows.Forms form, contextmenus (ContextMenuStrip) on controls (for example a DataGridView) in a Windows.Forms form no longer automatically disappear when clicking outside of the menu, which is the usual behaviour. It is a very strange problem I have been trying to fix. The problem can be reproduced in a small sample Visual Studio solution, if anyone is interested.

Kees.
User avatar
Chris
Posts: 5468
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Windows.Forms and the VO.App class

Post by Chris »

Hi Kees,

Due to the different design between VOGUI and Windows Forms, if you use the WindowsForms way to start a message loop (Application.Run()), some stuff in VOGUI windows will not properly, vice versa, if you use the VOGUI way with App:Exec(), some things in Windows Forms windows will not work properly.

Did you try to start the other way? Keep your app as a VOGUI app as it is, and start adding new or replace old VOGUI windows with Windows.Forms windows. When it's all complete, you can completely get rid of the VOGUI code. I've found this approach to usually work better.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 4017
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Windows.Forms and the VO.App class

Post by wriedmann »

Hi Chris, hi Kees,
to work with a mix of VOGui and Windows Forms you need special classes (that are inside the VOGui classes).
You can find samples in my session material here:
https://www.riedmann.it/download/GUI_Ch ... terial.zip
(more precisely Password.Mixed.viaef for a Windows Forms form inside a VOGUI application, and Password.WFShell.viaef and Password.WFShellX.viaef for a Windows Forms application with VO windows). All samples are in the XIDE export format, so you will need XIDE to try them out.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Kees Bouw
Posts: 172
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Windows.Forms and the VO.App class

Post by Kees Bouw »

Chris wrote: Fri Sep 05, 2025 1:37 pm Hi Kees,
Did you try to start the other way? Keep your app as a VOGUI app as it is, and start adding new or replace old VOGUI windows with Windows.Forms windows. When it's all complete, you can completely get rid of the VOGUI code. I've found this approach to usually work better.
Hi Chris,

My idea a few years back was to start with a Windows.Forms app because that would be the end result eventually, then integrate the VO code and gradually change all VO windows to Forms windows. I actually have a working application having done it this way, where everything works until recently when I encountered that strange contextmenu problem. If you think the other way around is better then I am willing to give that a try, but... I am not going to start over again. Is there a way to "transform" my working Windows.Forms app (with both Forms and VO windows) in a VO MDI app without changing too much, for example just in the startup code or libraries etc.?

Kees.
User avatar
Kees Bouw
Posts: 172
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Windows.Forms and the VO.App class

Post by Kees Bouw »

wriedmann wrote: Fri Sep 05, 2025 2:32 pm Hi Chris, hi Kees,
to work with a mix of VOGui and Windows Forms you need special classes (that are inside the VOGui classes).
You can find samples in my session material here:
https://www.riedmann.it/download/GUI_Ch ... terial.zip
(more precisely Password.Mixed.viaef for a Windows Forms form inside a VOGUI application, and Password.WFShell.viaef and Password.WFShellX.viaef for a Windows Forms application with VO windows). All samples are in the XIDE export format, so you will need XIDE to try them out.
Wolfgang
Hi Wolfgang,

Thank you for your reply. I have read the powerpoint that was included and I think it is very interesting. I am not familiar with XIDE but I do have it installed, so I tried the Import button on the "Select Project" window. It tries to open a *.vipef file and such a file is not present in your zip file, only *.viaef files and one AEF. I am not sure how can open the *.viaef files in XIDE.

Kees.
User avatar
wriedmann
Posts: 4017
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Windows.Forms and the VO.App class

Post by wriedmann »

Hi Kees,
to import a viaef file you need to make a right click in the project explorer and select "Import application".
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Kees Bouw
Posts: 172
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Windows.Forms and the VO.App class

Post by Kees Bouw »

wriedmann wrote: Fri Sep 05, 2025 4:07 pm Hi Kees,
to import a viaef file you need to make a right click in the project explorer and select "Import application".
Wolfgang
Hi Wolfgang,

For me, the right click menu does not have the option "Import application". It does have the option "Import" but that only accepts *.xipef or *.vipef files, not *.viaef files.

Kees.
User avatar
wriedmann
Posts: 4017
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Windows.Forms and the VO.App class

Post by wriedmann »

Hi Kees,
only Chris can help you here, I think.
Or do you have the "Default Project" in XIDE as active project?
In this case no application can be imported, only single prg files.
If this is the case you should select "New project" and create a new normal project.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Kees Bouw
Posts: 172
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Windows.Forms and the VO.App class

Post by Kees Bouw »

wriedmann wrote: Mon Sep 08, 2025 7:29 am Hi Kees,
only Chris can help you here, I think.
Or do you have the "Default Project" in XIDE as active project?
In this case no application can be imported, only single prg files.
If this is the case you should select "New project" and create a new normal project.
Wolfgang
Hi Wolfgang,

I have created a new project in Xide and selected it. Then I have the menu option "Import Application". So I imported all 7 *.viaef files. There is quite a lot of code, so maybe you can suggest a specific example to look at. A summary of the situation: My application started as a X# Windows.Forms application and I want to use VO windows as well. I am now using a VO.App object to start the VO windows and that has worked fine until I encountered a strange problem with context menu's.

Kees.
User avatar
wriedmann
Posts: 4017
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Windows.Forms and the VO.App class

Post by wriedmann »

Hi Kees,
I had written that in my first message, and the Powerpoint Presentation explains it even better.
unfortunately both the Windows Forms classes and the VOGUI classes are using the same message system, so conflicts between them are obvious.
With some changes and the help of support classes that are inside the VOGUI classes you can mix them, but one of them needs to be the controlling part.
If you like to have a Windows Forms application with VOGUI, then you should look at Password.WFShell and Password.WFShellX samples.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Post Reply