Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Winforms questions 19 Jan 2022 13:47 #21175

  • ic2


  • Posts: 1351
  • So far my .Net programs were all WPF. Because of some simple functionality not implemented or working in WPF I added a Winforms page in a project where this all worked far easier.

    However, Winforms seems to have other issues. Contrary to WPF I can not show the form/design view and code in 2 different tabs. I need F7 or right mouse View code/Design to switch. Or did I miss something here?

    Another issue is this: when I notice some obsolete code and remove it, I can not open the Design mode anymore when this code is called from a button for example. So I need to undo my code changes first, then go to design, remove the button, go to code, remove the code.

    I can hardly believe it works like that even in VS. Do I miss something here as well?

    Dick

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

    Winforms questions 19 Jan 2022 14:24 #21183

    • Fabrice
    • Fabrice's Avatar


  • Posts: 219
  • Hi Dick,

    first, don't forget that WinForms will do a lot of things for you, so if you remove/change some code, the generated code is not aware of that, and still rely of the previous version...

    That said, you can:
    Double click on a Form definition, this will open the designer. The designer rely on the InitializeComponent that (most of the times) is inside the .designer.prg file. My advice it to NOT touch this file, but.. you can if you know what you are doing.
    If you want to look at your code, just Right-Click on the file in the Solution Explorer, and select View Code.

    Now, let say that you inadvertently click on a button, the Designer will generate code to "link" the ClickEvent of this button to a piece of code, and that piece of code will appear in the UserCode prg (the main Form prg file)
    Now, if YOU remove this piece ot the code, the designer is not aware of that and the link persist; and this will break the designer

    So, to achieve that task, the best way is to NOT remove that code manually, but let the designer do it.
    For that, go back to the Designer; Single-Click on the Button; Then look at the Properties area (usually down right in the VS area), there change from Properties view to Events view (by one of the buttons), and search the event that you selected. Then Right-Click on it, and select Reset. You're done !! The Designer will remove the link (and remove the generated code if you did not touched it)

    The other way, to achieve that, is to open the .designer.prg file, search the button initialization code, and remove the line with the definition of the Click Event with the EventHandler. But again, be aware that you may break things if you remove the wrong line.

    HTH,
    Fab

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

    Last edit: by Fabrice.

    Winforms questions 19 Jan 2022 20:50 #21188

    • ic2


  • Posts: 1351
  • Hello Fabrice,

    Thanks for your extensive explanation. I'll keep it in mind if I want to remove more code in the future.

    I do however think it's all poorly implemented. For example if VS can not show the form anymore because the method is deleted, VS could also ask if it should delete the method (and show the form again). In VO you can always open the editor regardless the presence or absence of code, with drawback that code remains in your program if not used at all. In WPF it's the same although the compiler detects if a click event is no longer present.

    I think most VS users who have tried to post requests or issues with VS (like I would do for this if it were an X# issue) have given up. Almost all request end with "Not enough info" "Not a bug" "No priority" and a feedback bot closing your issue without any result. That's the big difference with the X# development.

    Dick

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

    Winforms questions 19 Jan 2022 20:56 #21189

    • Chris
    • Chris's Avatar


  • Posts: 3256
  • Dick,

    In this particular case, the answer you will hear from MS is "it's a feature, not a bug!" :)

    But regarding the other problem, designing different tab pages, this should work and it is actually a lot better and easier doing that in VS (and XIDE), compared to the very clumsy way of VO. Maybe I did not understand the problem enough?
    XSharp Development Team
    chris(at)xsharp.eu

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

    Winforms questions 19 Jan 2022 22:35 #21195

    • FFF


  • Posts: 1311
  • Chris,
    i think he talks about working in VS with two tabs, one showing the "graphics", one the code - not about implementing tabforms in his app ;-)
    Regards
    Karl (X# 2.7; Xide 1.27; W8.1/64 German)

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

    Winforms questions 19 Jan 2022 22:51 #21196

    • ic2


  • Posts: 1351
  • Hello Chris,

    No, I meant the VS tabs each holding the program code or form. But I did miss something I just found out. Once I select View Code or View Form or press F7, the code and form are opened in 2 different tabs.

    I think I overlooked it because it is different from WPF, where the xaml & xaml.prg or xaml.cs are both visible in the Solution Explorer so it feels more natural to open one of each or both, just like any other .prg/.cs.

    In Winforms you only see the code and a resx file. To be consistent the solution explorer should have shown the form indenting from the .prg/.cs like it does in WPF or like it does with the .resx.

    Dick

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

    Last edit: by ic2.

    Winforms questions 20 Jan 2022 10:55 #21198

    • Fabrice
    • Fabrice's Avatar


  • Posts: 219
  • Hi Dick,
    as .NET doesn't allow "Late Binding" (mostly), the designer rely on the fact that all the Form definition code is based on existing members; so a missing/wrong method call/name will crash the designer, as it would crash the compiler.
    That said, WPF is a different story : XAML defines the look&feel of the window, and the code-behind will manage some stuffs, so... no need of code to render the window; where WinForms is pure-code definition, that why you don't have a separate item in the solution explorer : And if you have a designer crash when opening the Form, look at the first paragraph of this message... ;)

    Fab

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

    Last edit: by Fabrice.
    • Page:
    • 1