'
' File name: MainWindow.xaml.vb
' Location: See Matrox Example Launcher in the MIL Control Center
' 
'
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Navigation
Imports System.Windows.Shapes

'********************************************************************************
' Copyright (C) Matrox Electronic Systems Ltd., 1992-2020.
' All Rights Reserved
'********************************************************************************

Class MainWindow
   Public Sub New(Optional url As String = Nothing)
      InitializeComponent()
      URLBox.Text = url
      Title = "MdispWebForm"
   End Sub

   Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
      NavigateToWebPage(URLBox.Text)
   End Sub

   Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
      NavigateToWebPage(URLBox.Text)
   End Sub

   Private Sub NavigateToWebPage(url As String)
      If (Uri.IsWellFormedUriString(URLBox.Text, UriKind.Absolute)) Then
         Dim uri As Uri = New Uri(URLBox.Text)
         MainBrowser.Navigate(Uri)
         StatusBarTextBlock.Foreground = Brushes.Black
         StatusBarTextBlock.Text = ""
      ElseIf (String.IsNullOrEmpty(URLBox.Text)) Then
         StatusBarTextBlock.Foreground = Brushes.Black
         StatusBarTextBlock.Text = "Please enter a valid URL"
      Else
         StatusBarTextBlock.Foreground = Brushes.Red
         StatusBarTextBlock.Text = "Error: Please enter valid URL"
      End If
   End Sub

   Private Sub MainBrowser_Navigated(sender As Object, e As NavigationEventArgs)
      If (URLBox.Text <> e.Uri.AbsoluteUri) Then
         URLBox.Text = e.Uri.AbsoluteUri
      End If

   End Sub

   Private Sub URLBox_KeyDown(sender As Object, e As KeyEventArgs)
      If (e.Key = Key.Enter) Then
         NavigateToWebPage(URLBox.Text)
      End If
   End Sub
End Class