Answer the question
In order to leave comments, you need to log in
C#. How to implement this code into the program?
Good afternoon!
I'm new to C#, trying to write a little program.
On the form so far only WebBrowser1, which will load the site.
WebBrowser needs a Navigatng event handler. So that you can only follow links containing a specific domain
The processing code is an example
void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
string word = "someWord"; //какое-то слово
if (!e.Url.ToString().Contains(word)) //если не содержит
e.Cancel = true; //не переходим
}
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace Casdasd
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
}
}
using System;
using System.Windows.Forms;
namespace Casdasd
{
/// <summary>
/// Class with program entry point.
/// </summary>
internal sealed class Program
{
/// <summary>
/// Program entry point.
/// </summary>
[STAThread]
private static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question