How to Block Right Click on Flash Player in VB.NET - 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

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.

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.

load a webpage in a webview vb

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.

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.

Showing Login form before main form in vb.net

I'm sure I'm doing my login process for my app in a not so perfect way, but as with lots of things, it works. The issue is to make it work I have to use the very unpopular DoEvents thing.
I would like my application to show a login screen before loading my main form. Currently I have a login dialog box with a FormOpen boolean property and an authenticated boolean property. If a user logs in successfully, I hide the login form, set formopen to false, and authenticated to true. If they cancel out, then I do the same and just set the authenticated property to false. If authenticated=false then I end the app, else I show the main form via application.run(MainForm)
Shared Sub Main()
Using frmLogin1 As New LoginForm
frmLogin1.Show()
Do While frmLogin1.FormOpen = True
Application.DoEvents()
Loop
If frmLogin1.Authenticated = False Then End
End Using
ModuleRegistration.Register()
Application.Run(MainForm)
End Sub
Is there a more preferred way of doing this?
You could just set the startup form to the login form. Then when the user hits "OK" and is verified, you just load the main form and close the login form.
Alternatively you can use the "ShowDialog" method to show the form modally. In your login form code, you can set DialogResult when closing the form, which becomes the return value from the ShowDialog method. That way you can detect that, say, "Cancel" was pressed and quit.
UPDATE: Perhaps if you change your Sub Main to just:
Application.Run(YourLoginForm)
Along with whatever other startup code your require. Then handle showing the main form in your login form (if I remember correctly, your application will not exit until the last form closes... You can use that to your advantage).
I think your approach is fine, except for one thing: the loop. Instead, display the login form using ShowDialog.
Shared Sub Main()
Dim authenticated As Boolean
Using frmLogin1 As New LoginForm
frmLogin1.ShowDialog()
authenticated = frmLogin1.Authenticated
End Using
If authenticated Then
ModuleRegistration.Register()
Application.Run(MainForm)
End If
End Sub
Or instead of waiting for your login form to close, raise an event in the login form.
You'll need to declare your login form withevents.
Then when the login form's new event fires, check the value of the authenticated property.