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.
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
Re: Using html front end vs winform
I’d use something similar to what tg suggested, except Anchoring and Docking with a TableLayoutPanel…
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.
Re: Using html front end vs winform
Quote:
Originally Posted by
Shaggy Hiker
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…
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.
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.
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.
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).