Results 1 to 9 of 9

Thread: Using html front end vs winform

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2018
    Posts
    160

    Using html front end vs winform

    Hi

    Asking for a bit of general advice here: I've only ever coded in using winforms before, but I've been asked for a form to be made dynamic in layout, so it will re-size itself and show nicely on multiple PCs with different screen resolutions.

    I've been told to make my form 'act like a webpage' in terms of layout sizing - I'm just wondering what the best way to approach this would be.

    I expect there are ways to make layout dynamic, but I suspect the person asking this may want to take this further and have some an internal IP web page they can open in a browser.

    Is it possible/practical to create an html front-end which passes some sort of command string to a vb.net backend (for the main program to then to go ahead and do it's stuff)?

    Is this the way to think about this? - maybe I'm not thinking along the right lines? - I'm afraid I've VERY limited html experience so I don't really have much of an idea of how to approach this, so suggestions would be very welcome.

    Thanks for reading.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Using html front end vs winform

    This is done using a mix of Anchor and Docked properties, along with probably either a FlowTableLayout, and FlowLayout (I think I have those names right) ...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Using html front end vs winform

    I’d use something similar to what tg suggested, except Anchoring and Docking with a TableLayoutPanel…

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Using html front end vs winform

    XAML in WPF is more like HTML, but if the person asking for this wants an application that appears to be desktop or web, it brings to mind Cordova, which was found in VS 2015 and 2017, but was then dropped after 2017. Cordova was HTML, but ran on the desktop. I think it can still be found, just not as a part of Visual Studio anymore. Of course, you could go back to VS 2017, but that's not a good idea.
    My usual boring signature: Nothing

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Using html front end vs winform

    Quote Originally Posted by Shaggy Hiker View Post
    XAML in WPF is more like HTML, but if the person asking for this wants an application that appears to be desktop or web, it brings to mind Cordova, which was found in VS 2015 and 2017, but was then dropped after 2017. Cordova was HTML, but ran on the desktop. I think it can still be found, just not as a part of Visual Studio anymore. Of course, you could go back to VS 2017, but that's not a good idea.
    I think the OP is just looking for ways to make their app responsive…

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Using html front end vs winform

    Yes, but exactly how responsive to different screen sizes is not clear. Anchoring and docking take you a long ways, but not as far as what HTML does, where elements can be made to vanish, turn into different elements, turn into pop outs, and so forth, as the screen size changes sufficiently. XAML would allow that, which would mean WPF or Xamarin, and Cordova certainly did that.

    It just depends on how much things need to be able to change size.
    My usual boring signature: Nothing

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Using html front end vs winform

    Start here:

    https://www.vbforums.com/showthread....matic-Resizing

    That will give you an idea of what you can do with WinForms. You can use multiple nested TableLayoutPanels and/or FlowLayoutPanels for more complex layouts but performance can start to suffer and things get complex pretty quickly. If you have a layout that is too complex for WinForms then WPF would be the way to go, but that would mean building a whole new UI and possibly making other changes too.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2018
    Posts
    160

    Re: Using html front end vs winform

    Thanks for all the response guys. I'll look into all of these and see what works best for me.

  9. #9
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,370

    Re: Using html front end vs winform

    I have been building a concept out where my UI is built in HTML, CSS, and JavaScript but my business logic is built in Visual Basic .NET using a WebView2.

    The way that this works is that when I need my UI to talk to my VB.NET application, I call chrome.webview.postMessage, e.g.
    Code:
    const message = {
    	Endpoint: '/api/my-entity/create',
        Body: JSON.stringify(model)
    };
    chrome.webview.postMessage(message);
    Then my WebView2 in my VB.NET application has the WebMessageReceived event where I monitor the requests:
    Code:
    Dim webViewSender = DirectCast(sender, WebView2)
    Dim json As String = e.WebMessageAsJson()
    Dim request As WebMessageRequest
    Dim response = New WebMessageResponse()
    
    Try
        Try
            request = JsonConvert.DeserializeObject(Of WebMessageRequest)(json)
        Catch ex As Exception
            Throw New Exception("Invalid WebMessageRequest", ex)
        End Try
        Dim endpointParts = request.Endpoint.Split("/"c)
        If (endpointParts.Length < 4) Then
            Throw New Exception("Invalid WebMessageRequest: invalid endpoint")
        End If
    
        ' endpointParts(0) will always be '/'
        Dim area = endpointParts(1) ' this should always be 'api'
        Dim entity = endpointParts(2)
        Dim action = endpointParts(3)
    
        Dim invalidEndpoint = False
        Select Case entity
            Case "my-entity"
                ' do something
            Case Else
                invalidEndpoint = True
        End Select
        If (invalidEndpoint) Then
            Throw New Exception("Invalid WebMessageRequest endpoint")
        End If
    Catch ex As Exception
        Dim largeLog = New With {request, ex.Message}
        My.Application.Logger.Log(JsonConvert.SerializeObject(largeLog), ex.InnerException)
        webViewSender.ExecuteScriptAsync("app.visualBasic.reject();").Wait()
        Return
    End Try
    
    webViewSender.ExecuteScriptAsync($"app.visualBasic.resolve(`{JsonConvert.SerializeObject(response)}`);").Wait()
    This has been beautiful, although I'm still working out the kinks. Mainly that it appears as though async/await in JavaScript doesn't play well with the WebView2.WebMessageReceived event (or at least that is what it seems).
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width