我几乎没有使用C#设置数据库的经验。因此,我希望存储列表的预定义内容,还可以在表单运行时添加值并删除会话中的值。从列表中,根据内容,URL在WebBrowser控件中被阻止。我将在下面添加片段。
private List<string> BlockList = new List<string>() { "http://www.google.com", "http://www.google.co.uk", "http://www.bing.com" };
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
string[] BlockArray = BlockList.ToArray();
for (int i = 0; i < BlockArray.Length; i++)
{
if (e.Url.Equals(BlockList[i]))
{
e.Cancel = true;
MessageBox.Show("Booyaa Says No!", "NO NO NO", MessageBoxButtons.OK, MessageBoxIcon.Hand); // Block List Error Message
}
}
}
private void button6_Click_1(object sender, EventArgs e)
{
string url = textBox2.Text;
// Get if the user entered the right password
GetPass pass = new GetPass(password);
// Check this with a dialog result
DialogResult result = pass.ShowDialog();
if (result == DialogResult.OK)
{
BlockList.Add(url);
MessageBox.Show("Added " + url + " to blocklist.");
textBox2.Clear();
}
else
{
MessageBox.Show("Booyaa Says Wrong Password", "Wrong Password", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
private void button7_Click_1(object sender, EventArgs e)
{
string url = textBox2.Text;
// Get if the user entered the right password
GetPass pass = new GetPass(password);
// Check this with a dialog result
DialogResult result = pass.ShowDialog();
if (result == DialogResult.OK)
{
BlockList.Remove(url);
MessageBox.Show("Removed " + url + " from blocklist.");
textBox2.Clear();
}
else
{
MessageBox.Show("Booyaa Says Wrong Password", "Wrong Password", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}