T
T
TechNOIR2018-02-16 14:09:21
C++ / C#
TechNOIR, 2018-02-16 14:09:21

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

The code
void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
    string word = "someWord"; //какое-то слово
    if (!e.Url.ToString().Contains(word)) //если не содержит
        e.Cancel = true; //не переходим
}


But I don’t understand how to insert it, where and whether it is necessary to initiate something else in the code?
Please tell me.. Thank you in advance!
PS I do it in SharpDevelop
. I have 2 files in it:
mainform.cs
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.
            //
        }
    }
}


and
Program.cs
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 question

Ask a Question

731 491 924 answers to any question