load a webpage in a webview vb - vb.net

Public NotInheritable Class MainPage
Inherits Page
Private Sub WebView_NavigationCompleted()
Dim uri As New Uri("google.com")
webView1.Navigate(uri)
End Sub
End Class
I have a webview on my designer and I clicked on the webview to get the private sub above. However, when the app loads, it won't display the webpage. What am I doing wrong?
I wanted this app to view a single web page as soon as the app loads.
I have tried to look this up on google, but nothing is seeming to work.

A Uri like that would, under normal circumstances, cause a System.UriFormatException (Check here). Try something like "http://www.google.com" instead.

Related

CefSharp SetZoomLevel not working

I am using in a WinForm an object of type:
CefSharp.WinForms.ChromiumWebBrowser
Everything is working fine but I am having an issue when I try to change the ZoomLevel with SetZoomLevel method:
If oBrowser.IsBrowserInitialized Then
oBrowser.SetZoomLevel(-2.0)
Dim frame As CefSharp.IFrame = oBrowser.GetMainFrame
Dim request As CefSharp.IRequest = frame.CreateRequest()
request.Url = url
request.Method = "POST"
request.InitializePostData()
Dim element = request.PostData.CreatePostDataElement()
element.Bytes = postDataBytes
request.PostData.AddElement(element)
request.Headers = headers
frame.LoadRequest(request)
End If
The first time I open the WinForm the Zoom level doesn't change, while it works correctly from the 2nd refresh.
Am I missing some initialization and/or method call... Or do I have to call this method in another position?
Note: the CEFSharp DLL version is 63.0.3.0.
The .NET Framework is 4.5.2
EDITED 01.06.2018: I've found a solution (see below) but now there's another problem: the zoom change is made when the browser is already visible, so it's not nice for the final user to see the page size changing during the form load.
Has anyone a suggestion to freeze the layout during zoom change? Please note that .SuspendLayout() and .ResumeLayout() are not working.
I've found a way to answer my own question. I post it here as it could be useful to other users.
You must add a LoadingStateChanged handler to the ChromiumWebBrowser object:
AddHandler oBrowser.LoadingStateChanged, AddressOf WebBrowserOnLoadingStateChanged
The method would be then something like:
Private Sub WebBrowserOnLoadingStateChanged(ByVal sender As Object, ByVal loadingStateChangedEventArgs As LoadingStateChangedEventArgs)
Dim oBrowser As WinForms.ChromiumWebBrowser = CType(sender, WinForms.ChromiumWebBrowser)
If Not oBrowser.IsLoading Then
oBrowser.SetZoomLevel(-2.0)
End If
End Sub
This solution works good in my environment but now there's another problem: the zoom change is made when the browser is already visible, so it's not nice for the final user to see the Zoom Level changing during the form load.

Splash screen is still using background image How to release vb.net

I am copying all the images from the server to the local workstation so that one cannot tamper with them and when the application closes I want to delete those files.
currently I just tested with the splash screens background image. I copied the file to temp folder in workstation and it worked well.
But when I tried to delete it I am not able to do so as it is still used by splash screen.
How to release it from splash screen?
I tried to delete the directory
I am using the image on splash screen load method with the following code:
My.Computer.FileSystem.CopyDirectory("\\bwingssrv01\NRSRoot$\NRS_img", "c:\windows\temp\NRS_img", True)
Me.BackgroundImage = Image.FromFile("c:\windows\temp\NRS_img\splash.jpg")
I have tried to delete the directory on MyApplication_Shutdown
I was able to solve this by using delegate in SplashScreen:
I just tried to dispose the background image in the function called from My MDI form at the end of my code and was successful.
I used following code to solve the issue:
A delegate in my SplashScreen as:
Public Delegate Sub unload()
and following function in my SplashScreen as:
Public Sub unload1()
If Me.InvokeRequired Then
Me.Invoke(New unload(AddressOf unload1))
Else
Me.Visible = False 'to avoid showing the error image in background
Me.BackgroundImage.Dispose()
End If
End Sub
At the end of my MDI form I used following:
SplashScreen1.unload1()
Threading.Thread.Sleep(100)

Visual Basic PictureBox Panel Flicker

I am making a simple game that (for the main part) consists of a Panel with a grid of 32 PictureBoxes inside, each with a BackgroundImage. You click on a "tile" and it flips revealing a picture. My problem is that when the Form Loads, I can see it drawing. I see the Panel .. then empty PictureBoxes, then finally it fills in the PictureBoxes with the BackgroundImages.
I've turned DoubleBuffer to True for the Form, and I've also added the following:
Private Sub UseDoubleBuffer()
Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)
Me.UpdateStyles()
End Sub
Which I call when the Form Loads. I'm not sure what else I can do? I want it to just 'pop' onto the screen. Why isn't the DoubleBuffer working? Do I need to code the panel manually? I was trying to avoid that as it's obviously easier to just drag and drop into the Form, but if I need to, I will.
I can't post screenshots apparently, as my rep isn't high enough yet, but believe me, it looks hideous, and I do want to make this as sleek as I possible can. Any ideas?
Try creating flicker free custom panel controls:
Here are the steps to use this control:
1. Add new class "NonFlickerPanel" to your C# application.
2. Replace autogenerated class code with C# code shown below.
3. Use NonFlickerPanel object instead of Panel object in your application.
public partial class NonFlickerPanel : Panel
{
public NonFlickerPanel() : base()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint,
ControlStyles.UserPaint
ControlStyles.OptimizedDoubleBuffer,
true);
}
}
Try making the picture boxes invisible (.visible = false) until they're all loaded, then set visible to true for all of them.

How to set 5 second timing of a splash screen in VB.NET

I have used this code to set 5 second time of my vb.net's project's splash screen.
Imports System.Collections.ObjectModel
Namespace My
Partial Friend Class MyApplication
Protected Overrides Function OnInitialize(ByVal commandLineArgs As ReadOnlyCollection(Of String)) As Boolean
Me.MinimumSplashScreenDisplayTime = 5000
Return MyBase.OnInitialize(commandLineArgs)
End Function
End Class
End Namespace
This code is fully working but as my project takes no time to load so as soon the splashscreen is getting loaded the 1st form is also getting loaded, and it is hiding the splash screen.
I want that the 1st form will load after the splash screen gets closed. Can any one help me out in this?
You could try setting your application to use a 'Sub Main' as its startup object rather then either form. In the 'Sub Main' you can show your splash screen as a modaless form while you do your initialization, then hide it when you you are ready to show your main form. Something like:
Sub Main
Dim slash as new SpashScreenForm
slash.Show()
<do the initialization for several seconds>
slash.Hide()
Dim mainForm as new TheMainForm
mainForm.ShowDialow()
End Sub
You may need to throw in a few Application.DoEvents() calls to get the splash screen to refresh.

How to Block Right Click on Flash Player in VB.NET

I have embedded the flash player(Shockwave Flash Object) into my application Form. and then I want to block right click from user. The question is that can I block right click from user?
thanks in advance..
You could embedd your Flash content using the WebBrowser control and set the IsWebBrowserContextMenuEnabled to False but I admit that this solution would be the proverbial sledgehammer to crack the nut.
If you want to use System.Windows.Forms.WebBrowser, just specify the desired Flash content as the Navigate target:
Public Class Form1 Inherits Form
Public Sub New()
webBrowser1.IsWebBrowserContextMenuEnabled = False
webBrowser1.Navigate(New Uri(string_variable_path_to_flash))
End Sub
End Class