fbpx
Welcome, Guest
Username: Password: Remember me
Visual Objects

Please use this forum to post questions about Visual Objects and Vulcan.NET

TOPIC: SystemMenuClose etc

SystemMenuClose etc 14 Mar 2019 00:16 #7725

  • lumberjack's Avatar

  • lumberjack


  • Posts: 683
  • BiggyRat wrote: I think people are missing my point. please see the attached files. It should make it very clear (I hope). The code as I said above was written in VO as you will see in the attached screenshots

    Jeff, nope remember we are now talking merging two different environments, you totally confused me, I thought from your post you want to emulate the VO behaviour with WinForms. You should basically be able to just take the code as is and recompile with language syntax VO selected...
    What version of VO is this code coming from? Have you used the transporter to get the code converted... etc. There are a lot of things to consider... If you have done all of these.... send the DevTeam a zipped file with your application, I am sure it can be resolved quickly...
    ______________________
    Johan Nel
    George, South Africa

    Please Log in or Create an account to join the conversation.

    SystemMenuClose etc 14 Mar 2019 06:05 #7726

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2279
  • Hi Jeff,
    as I wrote: even if you are using the VO GUI classes in X#, the correct place is the QueryClose() event.

    Please remember: you can move your VO applications to X#, but as long as they use the VO compatible GUI classes library, they look like the VO applications. But under the hood you can use all the .NET classes, and with some helper classes you are even able to add a WinForms window to the application.
    If you are asking why you should do this: your application will not only become more stable, but you can use all the new language features, and all the .NET framework classes, and a lot of additional libraries from other sources.
    Most vendors distribute their APIs as C# libraries, and with an X# application you can use them without any limitation.

    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    SystemMenuClose etc 14 Mar 2019 07:08 #7727

  • Chris's Avatar

  • Chris


  • Posts: 1945
  • BiggyRat wrote: I think people are missing my point. please see the attached files. It should make it very clear (I hope). The code as I said above was written in VO as you will see in the attached screenshots


    Jeff, please do answer the questions we are making, to help us understand what you are doing. X# is mainly a compiler, it can be used to create anything. You can do web apps with it, you can do WPF apps, you can do WinForms apps, you can do services and you can do apps that use the VOGUI classes, like VO does. We need to understand what of all you are trying to do.

    If you are writing an X# app that uses the VOSDK/VOGUI, then the equivalent of QueryClose is the same method, you can use the exact same code that you used in VO. It is the exact same GUI.

    If you are writing an app that uses the Windows Forms GUI that comes with .Net, then the equivalent of QueryClose is the FormClosing event, to find it please go to the Properties window of XIDE while you have your form in the designer, go to the ExEvents page and you will find it there. Double click on it to create it and press the button with the "..." to open it in the editor. In order to tell windows not to close the window, you need to type e:Cancel := TRUE in the method that will get generated:

    METHOD Form1Closing(sender AS System.Object , e AS System.ComponentModel.CancelEventArgs) AS VOID
    e:Cancel := TRUE

    I could go in more detail, but since I do not know what you are trying to do, I might be just saying irrelevant things. Maybe you can zip the project you have created and post it here so we can see what you are doing?
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    SystemMenuClose etc 14 Mar 2019 13:18 #7728

  • BiggyRat's Avatar

  • BiggyRat

  • Topic Author

    Here is some X# code, built MOSTLY by the XIDE, except for the VAR and IF statements.:Is it any wonder I'm confused???

    METHOD Form1Closing(sender AS System.Object , e AS System.ComponentModel.CancelEventArgs) AS VOID

    VAR result = System.Windows.Forms.MessageBox.Show("Business Manager 2.0", "Do you really want to quit?", System.Windows.Forms.MessageBoxButtons.YesNo);

    IF (result == System.Windows.Forms.DialogResult.Yes) <== This says CLEARLY to me, if you press the YES button, close. Correct? Apparently not. Click Yes, nothing happens. Click NO, and the window ends... WTH?

    // Closes the parent form.

    self.close()
    ENDIF

    RETURN

    What happens if NO is clicked? Surely the MerssageBox should disappear. No, it stays right there!I just want the same result I used to get in the VO code above, in X#. Shouldn't be hard I wouldn't have thought. I've now been on this about 10 hours, googling EVERYTHING I can find. NOTHING Helps.

    Please Log in or Create an account to join the conversation.

    SystemMenuClose etc 14 Mar 2019 13:42 #7729

  • robert's Avatar

  • robert


  • Posts: 1735
  • Jeff,

    If you want to prevent the form to close, then you need so set the Cancel property of the e argument to TRUE. If you do nothing , and simply return then the form will close.

    You should NOT call self:Close() from this method because that will bring the code in an endless loop (remember your form is already closing when this event happens).

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    SystemMenuClose etc 15 Mar 2019 00:25 #7739

  • BiggyRat's Avatar

  • BiggyRat

  • Topic Author

    Thanks Johan, but your code here:

    using System.Windows.Forms
    FUNCTION Start() AS VOID
    LOCAL oForm AS Form
    oForm := MyForm{}
    Application.Run(oForm)
    RETURN
    CLASS MyForm INHERIT Form
    CONSTRUCTOR()
    SUPER()
    SELF:InitializeForm()
    RETURN
    METHOD InitializeForm() AS VOID
    // Inside here you might probably have a Close button, menu with with Close option.
    // Both work the same they have a click event.
    LOCAL oCtrl AS Control
    oCtrl := Button{}
    oCtrl:Click := CloseClickEvent
    oCtrl := ToolStripMenuItem{}
    oCtrl:Click := CloseClickEvent
    RETURN
    METHOD CloseClickEvent(o AS OBJECT, e AS EventArgs) AS VOID
    IF MessageBox.Show(;
    "Are you really wanting to close the form?", "Question", ;
    MessageBoxButtons.YesNo, MessageBoxIcon.Question;
    ) == DialogResult.Yes
    SELF:Close()
    ENDIF
    RETURN
    END CLASS


    Does EXACTLY what I'm experiencing. Hit YES, and it DOESN'T close the window (or the Messagebox itself for that matter) Hitting NO closes everything. It's ass about.

    Please Log in or Create an account to join the conversation.

    SystemMenuClose etc 15 Mar 2019 02:32 #7740

  • ngpollarolo's Avatar

  • ngpollarolo


  • Posts: 8
  • METHOD ExitButtonClick(sender AS OBJECT , e AS System.EventArgs) AS VOID
    SELF:CLOSE()

    RETURN


    METHOD BasicFormClosing(sender AS System.Object , e AS System.ComponentModel.CancelEventArgs) AS VOID
    IF messagebox.Show("Are you really wanting to close the form?", "Question", ;
    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.yes

    e:Cancel:=.f.
    ELSE
    e:Cancel:=.t.

    ENDIF
    RETURN

    Please Log in or Create an account to join the conversation.

    SystemMenuClose etc 15 Mar 2019 03:33 #7741

  • BiggyRat's Avatar

  • BiggyRat

  • Topic Author

    OK, I concede defeat. I think I'll stick with the "Devil I know" in VO, rather than annoy you guys and continue my endless frustration with X#. Clearly I'm doing something wrong, but I have no idea what, and cannot find any clues online anywhere. No examples I've found online, or here even compile. Not one. It makes it extremely hard to learn, when the examples won't even compile...

    Here's the entirety of this current problem, including ngpollarolo's code, which looked extremely straight forward, but again, won't compile without errors.

    // Application : MdiApp1
    // Form1.prg , Created : 10/3/2019 12:06 PM
    // User : Jeff

    PARTIAL CLASS Form1 INHERIT System.Windows.Forms.Form


    CONSTRUCTOR()

    SUPER()

    SELF:InitializeForm()

    RETURN

    METHOD GroupBox1Paint(sender AS System.Object , e AS System.Windows.Forms.PaintEventArgs) AS VOID
    RETURN


    METHOD ToolStripSplitButton1Click(sender AS System.Object , e AS System.EventArgs) AS VOID
    RETURN


    METHOD Form1ContextMenuStripChanged(sender AS System.Object , e AS System.EventArgs) AS VOID
    RETURN


    //METHOD Form1Closing(sender AS System.Object, e AS FormClosingEventArgs) AS VOID

    METHOD ExitButtonClick(sender AS OBJECT , e AS System.EventArgs) AS VOID
    SELF:CLOSE()

    RETURN


    METHOD Form1Closing(sender AS System.Object , e AS System.ComponentModel.CancelEventArgs) AS VOID
    IF messagebox.Show("Are you really wanting to close the form?", "Question", ;
    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.yes

    e:Cancel:=.f.
    ELSE
    e:Cancel:=.t.

    ENDIF
    RETURN


    METHOD Form1Closed(sender AS System.Object , e AS System.EventArgs) AS VOID
    RETURN


    METHOD Form1FormClosing(sender AS System.Object , e AS System.Windows.Forms.FormClosingEventArgs) AS VOID

    RETURN


    METHOD MenuItem1Click(sender AS System.Object , e AS System.EventArgs) AS VOID
    RETURN SELF

    RETURN
    METHOD QueryClose(oEvent) CLASS Form1

    RETURN SELF


    METHOD ToolStripMenuItem1Click(sender AS System.Object , e AS System.EventArgs) AS VOID
    RETURN


    END CLASS
    GLOBAL cAppVersion := "Test BM 2.0"

    The errors are (this time....)

    error XS0103: The name 'MessageBoxButtons' does not exist in the current context 37,1 Form1.prg MdiApp1
    error XS0103: The name 'MessageBoxIcon' does not exist in the current context 37,1 Form1.prg MdiApp1
    error XS0246: The type or namespace name 'messagebox' could not be found (are you missing a using directive or an assembly reference?) 37,1 Form1.prg MdiApp1
    error XS0246: The type or namespace name 'DialogResult' could not be found (are you missing a using directive or an assembly reference?) 37,1 Form1.prg MdiApp1
    Compilation failed (4 errors)


    So thanks very much one and all, but I'll stay with VO for a while yet I think.

    Please Log in or Create an account to join the conversation.

    SystemMenuClose etc 15 Mar 2019 03:39 #7742

  • lumberjack's Avatar

  • lumberjack


  • Posts: 683
  • Hi Jeff,
    The first paradigm .NET opens up the world so to speak. So it is not anymore a question "How do I do XYZ in VO/X#. Google to the rescue... Search : "How do I prompt a user if he wants to close a window when a button is pressed c# .NET DOTNET"
    Remember, DOTNET is language agnostic, at the Intermediate Level (IL) all compiled code looks the same. Hence why a product like ILSpy can take a DOTNET.dll and decompile it to c#/vb/X#. You just need to supply it the language plug-in.
    You will find thousands of examples in c# this way. The beauty of X#, you can line for line, less the {} translate every statement of c# into X#.
    If you find your c# code example via your search, and there is something you don't understand about a method etc. MSDN have the whole .NET "Help file" it is huge there are so many classes, it is almost impossible to think you will have to write your own, except business classes. Good luck, I know it might feel we not helping you, but once you get the hang of it you should enjoy it.

    Just read a bit about the concepts of DOTNET. Assemblies, Namespaces, Static methods, METHODS, Singleton classes, Reflection, WFP, Entity Framework. It is like starting school again, but in a month or two you will speak the lingo...

    Good luck.
    ______________________
    Johan Nel
    George, South Africa

    Please Log in or Create an account to join the conversation.

    SystemMenuClose etc 15 Mar 2019 03:54 #7743

  • lumberjack's Avatar

  • lumberjack


  • Posts: 683
  • BiggyRat wrote: OK, I concede defeat.[/code]
    No! Don't do that, you so close. As I said you need to understand namespaces. Look at your designer code. System.Windows.Forms.Form

    // Application : MdiApp1
    // Form1.prg , Created : 10/3/2019   12:06 PM
    // User : Jeff
    USING System.Windows.Forms // See NAMESPACE
    PARTIAL CLASS Form1 INHERIT System.Windows.Forms.Form  
    
    METHOD Form1Closing(sender AS System.Object , e AS System.ComponentModel.CancelEventArgs) AS VOID
    IF messagebox.Show("Are you really wanting to close the form?", "Question", ;
    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.yes

    The errors are (this time....)

    error XS0103: The name 'XXXXX' does not exist in the current context	37,1	Form1.prg	MdiApp1
    error XS0246: The type or namespace name 'YYYYYY' could not be found (are you missing a using directive or an assembly reference?)	37,1	Form1.prg	MdiApp1
    I have said over and over, namespace assembly, get the concepts.

    If you have said USING System.Windows.Forms at the top of the file then you can MessageBox.Show(), otherwise you need to fully qualify the Class with its namespace System.Windows.Forms.MessageBox.Show(), same for all the other errors. The USING should take all errors away.

    ______________________
    Johan Nel
    George, South Africa

    Please Log in or Create an account to join the conversation.

    SystemMenuClose etc 15 Mar 2019 04:05 #7744

  • BiggyRat's Avatar

  • BiggyRat

  • Topic Author

    Hi Johan, OK, I had tried to use the USING statement at the top of the file, but what I assumed to be the top, seems not to be the case. Again not documented anywhere on the net that I could find.

    Originally I tried this:
    // Application : MdiApp1
    // Form1.prg , Created : 10/3/2019 12:06 PM
    // User : Jeff
    USING System.Windows.Forms

    that DID NOT work surely the first 3 lines of code are just a header/notation then the "top of the file" would be next. Basically just as it did in Clipper. But this DID work:

    USING System.Windows.Forms
    // Application : MdiApp1
    // Form1.prg , Created : 10/3/2019 12:06 PM
    // User : Jeff

    be that as it may, the MessageBox still doesn't display...

    Please Log in or Create an account to join the conversation.

    SystemMenuClose etc 15 Mar 2019 05:33 #7745

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2279
  • Hi Jeff,
    ok, please look here:
    docs.xsharp.it/doku.php?id=namespace_assembly_reference
    Do you had added the System.Windows.Forms library to your references?
    Wolfgang
    P.S. if it does not work, please export yur application and attach the viaef file zipped to your message. We'll give it a look
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    SystemMenuClose etc 15 Mar 2019 06:42 #7746

  • Chris's Avatar

  • Chris


  • Posts: 1945
  • Jeff,

    All this conversation would had taken just one post, if you had simply zipped and posted your project folder. Or do it a different way, select Project->Export Project and then send only the one file that will be created. Then it will be just a very simple thing for somebody to have a look and tell you exactly what the problem is.

    Right now we are going in the dark, so our suggestions is just speculation really. It could be a using statement missing, it could be references missing, it could be something else, but if you give us the exact project you are working on, it will not take more than 5 minutes to give you a solution and explain to you exactly what is going on an why.
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    SystemMenuClose etc 15 Mar 2019 07:37 #7747

  • BiggyRat's Avatar

  • BiggyRat

  • Topic Author

    OK, here it is. Bear in mind it's a crap app. Designed purely for my testing purposes...
    Attachments:

    Please Log in or Create an account to join the conversation.

    SystemMenuClose etc 15 Mar 2019 08:17 #7748

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2279
  • Hi Jeff,
    first error:
    e:Cancel = true
    must be
    e:Cancel := true
    The same is in the line before:
    var result = MessageBox.Show("Business Manager 2.0", "Do you really want to quit?", MessageBoxButtons.YesNo, MessageBoxIcon.Hand)
    should be
    var result := MessageBox.Show("Business Manager 2.0", "Do you really want to quit?", MessageBoxButtons.YesNo, MessageBoxIcon.Hand)
    But the main problem is another one: you are mixing VO GUI ( the App class) and WinForms.
    The VO GUI classes don't know nothing about the WinForms classes - it is entirely another world.
    In a WinForms application the Start() function needs this code:
    oWin := Form1{}
    Application.Run(oWin)
    And to understand why your application does not runs, you should add a basic error handling:
    try
    oWin := Form1{}
    Application.Run(oWin)
    
    catch oEx as Exception
    MessageBox.Show( oEx:Message + CRLF + oEx:StackTrace, "Runtime error" )
    end try
    or look in the event viewer what is going wrong.
    And the please use not the "run", but the "Debug" function.
    On my system, I had to remove all the VO compatibility libraries, and remove and add again the X# runtime.
    And then it runs:

    Please find your changed application attached.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it
    Attachments:

    Please Log in or Create an account to join the conversation.

    SystemMenuClose etc 15 Mar 2019 08:22 #7749

  • wriedmann's Avatar

  • wriedmann


  • Posts: 2279
  • Hi Jeff,
    after posting my message I have tried the code that closed the window.
    This is your code:
    method Form1FormClosing(sender as System.Object , e as System.Windows.Forms.FormClosingEventArgs) as void
    var result := MessageBox.Show("Business Manager 2.0", "Do you really want to quit?", MessageBoxButtons.YesNo, MessageBoxIcon.Hand)
    if result == DialogResult.Yes
      e:Cancel := true
    endif
    return
    but it should be:
    method Form1FormClosing(sender as System.Object , e as System.Windows.Forms.FormClosingEventArgs) as void
    var result := MessageBox.Show("Business Manager 2.0", "Do you really want to quit?", MessageBoxButtons.YesNo, MessageBoxIcon.Hand)
    if result != DialogResult.Yes
      e:Cancel := true
    endif
    return
    Please find the app attached to this message.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it
    Attachments:

    Please Log in or Create an account to join the conversation.

    SystemMenuClose etc 15 Mar 2019 16:26 #7753

  • Chris's Avatar

  • Chris


  • Posts: 1945
  • Thanks for sending the project, it's a fine app, do not worry, I have created plenty such test apps myself that are still laying in my XIDE projects and yours is way prettier than most of mine :)

    To further expand on what Wolfgang said: Since you are taking the .Net way of WInForms, rather than the way of using the VOGUI, then you need to use WinForms classes and do not mix them with VOGUI. You must not use the "App" class anymore, this is a VOGUI thing. Instead, use this:

    System.Windows.Forms.Application.Run(oWin)

    which is the equivalent of oApp:Exec(), it just tells .Net that you want to start your app by displaying oWin and terminate the app when oWin closes. You could also do this instead, the code is self describable:

    oWin:ShowDialog() // and remove Application.Run()

    Seeing your code, it now explains also why you were getting an error when compiling your code for the second time. It is because you were using two GUIs together (WinFOrms and VOGUI) and even when the one got shutdown when you closed the form, the VOGUI was stil running, because you had used and instantiated the App class. Just completely remove the oApp LOCAL and its uses from your code and this problem will go away.

    Wofgang has covered the rest about the code in the closing event, hope you feel more confident now to further explore the .Net framework classes!
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Last edit: by Chris.

    SystemMenuClose etc 16 Mar 2019 00:46 #7765

  • BiggyRat's Avatar

  • BiggyRat

  • Topic Author

    Brilliant. Thanks very much Wolfgang and Chris. I really appreciate your help.

    Here is an example of how I get confused/led astray... Everyone says "look at Microsoft MSDN", google it etc. Heres the syntax from the Microsoft .Net Docs. notice the difference?

    // Display message box parented to the main form.
    // The Help button opens the Mspaint.chm Help file,
    // and the "mspaint.chm::/paint_brush.htm" Help keyword shows the
    // associated topic.
    DialogResult r8 = MessageBox.Show (this, "Message with Help file and keyword.",
    "Help Caption", MessageBoxButtons.OK,
    MessageBoxIcon.Question,
    MessageBoxDefaultButton.Button1, 0,
    "mspaint.chm",
    "mspaint.chm::/paint_brush.htm");

    They say use = NOT := so, I did as they say, assuming they are correct... seems not. Also, their examples of "e" show e.cancel not e:cancel as you've used, and which I first noticed in ngpolarolo's post. As I say, it makes it damn hard to learn:

    // If the no button was pressed ...
    if (result == DialogResult.No) <======= Exact opposite of how it should be done it seems? (== not !=)
    {
    // cancel the closure of the form.
    e.Cancel = true;

    Please Log in or Create an account to join the conversation.

    Last edit: by BiggyRat.

    SystemMenuClose etc 16 Mar 2019 01:08 #7766

  • lumberjack's Avatar

  • lumberjack


  • Posts: 683
  • Hi Jeff,
    Remember those are c# examples. X# is the XBase version of c#.
    You will soon get the hang of it. Again, and I will say it again. Get yourself ILSpy 3.2 and add the XSharp Language plug-in...
    Variable declarion
    LOCAL i AS INT
    C#: int i;
    Assignment
    i := 1
    C#: i = 1;
    Comparison:
    if i = 0
    if "X#" == "X"
    if "X#" = "X" // c# don't have this behavior IF "X#" begins with "X"
    C#: if (i = 0)
          if ("C#" == "X")
          if ("C#".StartWith("X")) // The X# if "X#" = "X"
    Method calls
    LOCAL s AS STRING
    s := "x# rules"
    s := s:ToUpper() // Method call
    C#:
    string s;
    s = "c# sucks"
    s = s.ToUpper()
    Static method
    VAR s := String.ToUpper("x# rules")
    C#:
    var s = String.ToUpper("c# sucks")
    ______________________
    Johan Nel
    George, South Africa

    Please Log in or Create an account to join the conversation.

    Last edit: by lumberjack.

    SystemMenuClose etc 16 Mar 2019 01:23 #7767

  • lumberjack's Avatar

  • lumberjack


  • Posts: 683
  • Hi Jeff,
    You confusing yourself.... :lol:

    BiggyRat wrote:

    // If the no button was pressed ...
    if (result == DialogResult.No)     <======= Exact opposite of how it should be done it seems? (== not !=)
    {
      // cancel the closure of the form.
      e.Cancel = true;

    Well it depends what the Question was that was asked in the MessageBox example: Do you really want to close. OR Do you want to stay on this form?
    // If the no button was pressed ...
    if (result != DialogResult.Yes)
    {
      // cancel the closure of the form.
      e.Cancel = true;
    Just hang in, we will ride the storm with you. You will slowly learn to read c# code, if that is a problem, most examples on MSDN also have the VB.NET code, get used to understand it. All your examples are going to be one of those languages. Look at both ways, get to understand it, it is the way you operate in .NET.

    PS: By the way, how is the ILSpy 3.2 download going?
    ______________________
    Johan Nel
    George, South Africa

    Please Log in or Create an account to join the conversation.

    Last edit: by lumberjack.