Remove FileDownload Dialog in WebBrowser VB.NET - vb.net

I just need to remove/block this FileDownload Dialog:
(I don't have enough reputation to post images, so here is a link):
http://i60.tinypic.com/9bbwig.jpg
How can I do it?
Because I want to download file without this dialog, but when I use WebClient is starts up either. When I use My.Computer.Network.DownloadFile it freezes the WebBrowser (dialog doesn't show) and then if I use Background Worker (not to freeze the WebBrowser) the dialog shows...
I have no ideas what to do next :(

To download the logo of CNN you can use the following code
Imports System.Net
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Down_NewProp.DownloadFileAsync(New Uri("http://edition.cnn.com/.a/1.97.4/assets/" & "logo_cnn_badge_3up.png"), Application.StartupPath & "\" & "logo_cnn.png")
End Sub
End Class

It's a security device, to prevent the user download a file without realising. I doubt you would be able to remove it.

Related

Application Auto-closes after dialog box

New to VB.NET but pretty stumpped at the moment.
My Windows Form application launches 'Form1' which then starts a dialog box using:
Dim dialogResult As Boolean = configWizard.ShowDialog()
The ConfigWizard then writes some data to the registry, pops up with the new registry values and closes at which point the rest for Form1 loads.
This all works fine.. When debugging from Visual Studio 2015.
The problem I'm facing is when I build an installer for this program using the in-built InstallShield. The installer set the registry values on install (which works perfectly) then the dialog box opens, sets new values and pops up with the new values it's written. This all works fine. However, the Form1 closes straight away as soon as I press 'OK' on the dialog box.
It's supposed to pop up with a message box saying 'True' but the entire program closes.
Upon constant running of the program it did appear that the Form1 did flash up for milliseconds before disappearing. Does seem like the program is just closing for some unknown reason. I'm pretty stumped as to how to stop the Form1 from closing. Any light of questions to help out would be must appreciated.
I've omitted some code that is irrelivent.
I managed to quick take a screenshot when the Form1 did flash up (verifying both Form1 and the messagebox saying 'True' ARE loading after the dialogbox is closing.. albeit only for a split second)
Code:
Dialog Box:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
myValue1= Me.myValue1.Text
myValue2= Me.myValue2.Text
Dim regKey As RegistryKey
regKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\removedSoftware", True)
regKey.SetValue("value1", myValue1)
regKey.SetValue("value2", myValue2)
MsgBox(myValue1 & " + " & myValue2)
MsgBox("Registry: " & regKey.GetValue("value1") & " data: " & regKey.GetValue("value2"))
regKey.Close()
Me.Close()
End Sub
Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dialogResult As Boolean = configWizard.ShowDialog()
Try
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
MsgBox(dialogResult)
End Sub
Use OnShown event (Form1_Shown) instead of OnLoad to display the dialog box.

Nothing happen when the button is clicked

I have in my VB.NET form, two textBoxes and I want return its values on a messageBox when I click on the button, but I still have no result and nothing is happen.
Public Class Form3
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(Textnom.Text.ToString & " " & Textplace.Text.ToString)
End Sub
End Class
What is wrong with Click event?
I am not an expert so please backup the file before trying this
Vb.net sometimes used to freeze like this when we used to code.
So just (Backup first) and go to the Visual studio 2010 folder, goto Projects folder, go inside the folder of your project, go into the obj folder and delete the x86 file.
Retry to run and it should
In short delete the x86 file in the obj folder and run. It will work

How to detect mouse clicking in vb.net?

I want this program for when user click on something either in application or outside of that, make a screen shot and save it as jpeg to a folder
This is the code that I want put those option in it:
Imports System.Net.Mail
Public Class Form1
Private Function TakeImage()
Return TakeImage(0, 0, Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height)
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.Image = CType(TakeImage(), Image)
End Sub
End Class
by the way I'm beginner in VB.NET
I guess it is a desktop application and that TakeImage(,,,) works.
In your form, add a button, double click it and just call TakeImage from there.
Then there is saving as jpeg - just google on how to convert the bitmap(?) format from TakeImage to jpeg and google how to save it. In VB.Net it should be rather easy to handle files.
But first set a return type on your TakeImage function. Probably like as Image. It doesn't change your program but is good practice and will aid you in your learning as the editor will continuously give you helping feedback.
Happy hacking!

How do I discover the user's Desktop folder?

I'm making a little application in visual studio which loads a ROM in an emulator.
I have two emulators and 20 ROMs.
I made a form and added a few buttons. When you click the Button it opens a new form and closes the old one. Then on the new form I have four buttons: each one loads a different ROM in an emulator. So when you press Button1 this code is triggered:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles yellow.Click
Shell("C:\Users\shifty\Desktop\pokemon games\Emulator\VBA\VisualBoyAdvance.exe ""C:\Users\shifty\Desktop\pokemon games\Roms\Yellow\Pokemon Yellow.gb""", vbNormalFocus)
End Sub
It works fine - I click it and it loads the game in the emulator. The bit im having trouble with is the file paths. If I send this application to a friend, it would still look for "C:\Users\shifty\Desktop\" - but that's on my computer, not his.
Is there a way to make the application look for the file on his computer (without changing the file path to (C:\Users\""his user name""\Desktop))
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
This will resolve to be the desktop folder for the current user.
It will even work between XP, vista and Windows 7 properly.
Old post but I have to side with Mc Shifty. You can't assume that everyone is a coding expert. If they were then they wouldn't be here asking questions like that.
None of the answers given above were complete
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)) <<< includes and extra )
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)); <<< extra ) and the ; is C or java not VB which he is obviously using by his example code.
Both of those only give you half of the required code to generate something usable.
Dim s As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
The above code will give you the result needed, c:\users\shifty\desktop
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles yellow.Click
Dim s As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Shell(s & "\Desktop\pokemon games\Emulator\VBA\VisualBoyAdvance.exe " & s & "\pokemon games\Roms\Yellow\Pokemon Yellow.gb""", vbNormalFocus)
End Sub
There's a mechanism to get the current user's Desktop directory, using Environment.SpecialFolder.
Usage:
Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
I had problems using the Environment.GetFolderPath method from previous answers.
The following works in VB 2012, My.Computer.FileSystem.SpecialDirectories.Desktop
So, if you have a file on a users desktop named "contacts.txt", the following will display the full path,
' Desktop path
Dim desktopPath = My.Computer.FileSystem.SpecialDirectories.Desktop
' Concatenate desktop path and file name
filePath = desktopPath & "/contacts.txt"
MsgBox(filePath)
Documentation
Really old post at this point, but hey, found what I was looking for.
MC SH1FTY, I assume you have figured this out already, but to do what you are trying to do:
1) Call in that code that Spence wrote as a variable (I'd declare it Globally, but that's my preference. To do that:
Public userDesktopLoc As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
2) Either use this DIRECTLY in your code, or make another string to concatenate a directory:
Option A)
Public emulatorPath As String = userDesktopLoc & "pokemon games\Emulator\VBA\VisualBoyAdvance.exe "
Public romPath As String = userDesktopLoc & "pokemon games\Roms\Yellow\Pokemon Yellow.gb"
Then, within your Subroutine, replace your current Shell statement with:
Shell(emulatorPath & romPath, vbNormalFocus)
Or, Option B, which is thedsz's answer:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles yellow.Click
Dim s As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Shell(s & "\Desktop\pokemon games\Emulator\VBA\VisualBoyAdvance.exe " & s & "\pokemon games\Roms\Yellow\Pokemon Yellow.gb""", vbNormalFocus)
End Sub
By using that you guarantee that the emulator is on the users desktop. This is not always the case. I know I move things around that I download or a friend sends to me. It's better to use App.Path and make sure your emulator.exe is in the directory with your little front end program (usually the case).
the answer is simple.
put this at the top of the form
"Public thepath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)"
that ensures that the file is on their desktop!
then" click on your button or whatever you used to open the emu and type
"Process.Start(thepath + "the emulator.exe "+ "the rom you want")
You need to use a file open dialog to choose your path for the two files. Here is an example.
You then use the two paths in your code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles yellow.Click
Shell(emulatorPath + "\"" + romPath + "\"", vbNormalFocus)
End Sub

VB app not ending

I am using Visual Basic 2010 and I am makeing a simple login app it prompts you for a username and password if it gets it right I want to open a form then close the previus one but when I do me.close it ends the program and I can't go on
I am positive its working because I get the right password and username ut I can't close the first windows
I tried to hide it but when I do I cant close it and the program goes on without quiting and with a hidden form
I heard rumers that there is Sub that can control the x in the corner
if there is one that would probably solve my problem but I can't find it heres the code for the login form
Public Class Main_Login
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "My Name" And TextBox2.Text = "mypassword" Then
Contentsish.Show()
Me.Hide()
Label3.Hide()
Else
Label3.Show()
End If
End Sub
End Class
Then the Form if you enter the right login info
Public Class Contentsish
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Hide()
Timer1.Stop()
End Sub
End Class
how can I fix this problem?
Go into your project settings and set the application to close when the last form closes and not when the startup form closes.
edit: I just checked some of my VB.Net 2k8 code. What I do is create a new instance of the "child" form, do any initialization that I need, call .Show() on it, and then call .Close() on the current form (Me.Close()). Probably not the best way to do things, but it works for me. This is with the project setting I described earlier set. This allows me to exit from the child form or "logout" if needed.
Two other ways you can do this, in addition to Crags:
Load the main form first, then load the password from the main form.
You can use a separate vb module and use the Sub Main for the startup (you specify this in Project Properties, Application, Startup Object), then load the two forms from Sub Main.
So what happens if the login is incorrect? Sounds like you might want to show the login form using ShowDialog, maybe in your Main() before calling Application.Run(new FormMain());