WebView Stop Navigation - c#

I'm currently just goofing around, programming an Web Browser.
i wonder how to Stop Navigation from WebView just with a button click?
if there's any bool/void's involved in the solution, explain it please.
Appreciate it!

If you are using WebView from WinRT, you can call WebView.Stop().
If you are using WebBrowser from WP Silverlight, you can subscribe Navigating event and set NavigatingEventArgs.Cancel as true.
Reference:
WebView.Stop Method
NavigatingEventArgs

You can do only using javascript,as below
private void Button_Click(object sender, RoutedEventArgs e)
{
Browser1.InvokeScript("eval", "document.execCommand('Stop');");
}

Related

C# - Event when closing WebBrowser

I have a .NET Control with an WebBrowser in it.
This Control is used in my Application in a Form.
So if I close this Form or the whole Application or if I do anything that my WebBrowser is going to be closed I need to fire an event.
Ive tried it like this, but the if function does not works in the way I want it:
private void webBrowser1_VisibleChanged(object sender, EventArgs e)
{
if (!webBrowser1.Visible)
{
MessageBox.Show("Hi");
}
}
Any ideas?
Thanks
this code for after you closed the form....
private void webBrowser1_FormClosed(object sender, FormClosedEventArgs e)
{
MessageBox.Show("WebBrowser Closed");
}
this code for asking permission to do something while closing...
private void frmReader_FormClosing(object sender, FormClosingEventArgs e)
{
MessageBox.Show("Are you sure want to close the WebBrowser?");
}
Only the form knows when it's being closed. A way to accomplish this is to have your control find its containing form using Control.FindForm(), register handlers for the form's closing events (e.g. during initialization), and raise new events from the control.

C# about sending simulated keyboard events to another APP

private void button3_Click(object sender, EventArgs e)
{
SetForegroundWindow(wndHandle);
SendKeys.SendWait("123");
}
I use WIN32 API ,use the Sendkey to achieve my target,but using the Sendkey has a disadvantage that "I have to SetForegroundWindow() before I use sendkey",it doesn't match my wish.
I want to click a button in the GUI which C# created, and then it will simulate the keyboard event to another app, and most important of all, I wish I don't have to set the window of app to be the ground window.
Does anyone have idea how to do it? I appreciate your help very much.
Does the target application must be currently active?

Clear/delete & refresh button wpf

I have made a delete/clear button that works, but after using it I cannot make a new search...I also have a refresh button that doesn't work at all. I want to be able to make a ned search and I thought I could use the refresh button for this.
Can you help me? If you can, please explain it for me with an example.
private void Button_Click(object sender, RoutedEventArgs e)
{
dataGridTest.ItemsSource = null;
}
private void Refresh_Click(object sender, RoutedEventArgs e)
{
dataGridTest.Items.Refresh();
}
There's some part of your code that we need to see so that we can able to help. But if you are working with WPF, WPF is awesome with MVVM Design pattern.
You can check some start up here.
Josh Smith's tutorial is the best tutorial about MVVM.

WPF WebBrowser OnTitleChanged Event

i am using System.Windows.Controls.Webbrowser class in my C# app.
I want to recognize if the document title changes.
Therefore i listen on the LoadComplete Event and getting the title
public void webBrowser_LoadCompleted(object sender, NavigationEventArgs e)
{
dynamic doc = browser.Document;
setTitle(doc.Title);
}
The problem now is, that the title could change during loading. In this case the LoadCompleted event would not fire.
Next problem is. I have a html application inside which navigates through javascript functions in the application. In case of using these javascript links, the event would not fire, too.
I am looking for an event like OnTitleChange from CHtmlView (c++)
Is there a possibilty to solve my issue?
Thanks for help.
Not supported by the WPF webbrowser.
You can use windows forms interop to show a windows forms webbrowser control then subscribe to the DocumentTitleChanged event.
This is the working code for me:
System.Windows.Forms.WebBrowser browser = new System.Windows.Forms.WebBrowser();
browser.Navigate(URL);
browser.DocumentTitleChanged += new EventHandler(browser_DocumentTitleChanged);
WindowsFormsHost winFormsHost = new WindowsFormsHost();
winFormsHost.Child = browser;
AddChild(winFormsHost);
public void browser_DocumentTitleChanged(object sender, EventArgs e)
{
setTitle(browser.DocumentTitle);
}

How to get a button to open a web page?

I've looked everywhere, including the MSDN forums, but no one has even mentioned this or ways to do it. The basic idea is that once a Button is dragged from the toolkit, how do you then link that button to a web page, ie I have a 'Facebook' button, how do I then make it so that when the button is clicked, Facebook opens in a new browser window?
Once you've dragged the button onto the designer, you can double-click on it to open up the Button's Click event handler. This is the code that will get run when the user clicks. You can then add the required logic, ie:
private void button1_Click(object sender, EventArgs e)
{
// Launch browser to facebook...
System.Diagnostics.Process.Start("http://www.facebook.com");
}
You can use Process.Start with the desired URL to open the default browser and navigate to the page:
using system.Diagnostics;
private void button1_Click(object sender, EventArgs e)
{
Process.Start("http://www.YouTube.com");
}
Since you said open in a new browser window, I was thinking the context was an web application you were developing, so this would apply in that case:
Add an HTML button with the window.open JavaScript method. You don't need or want code-behind here because it's all happening on the client. Here's a snippet, and there are a few other options you can pass to window.open to control behavior.
<input id="Button2" type="button" value="Facebook" onclick="window.open('http://facebook.com')"/></p>
You have to use Process class under System.dll which is be default added to the solution. But you should refer the namespace at the top of your class this way:
using System;
namespace MyApplication
{
public class MyProgram
{
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://www.facebook.com");
}
}
}

Categories