C# How to update IE7 to new version - c#

Iam very new to coding so please pardon my lack of knowledge.
I made a program "Music player" that uses webBrowser to play video from youtube but from what i understood from other posts it cant work due to webBrowser being IE7. I dont neccessarily have to use webBrowser but it seemed like the best way.
Is there a way to "update" IE or do i need to use different method?
code:
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace MusicPlayer_V4._1
{
public partial class Form1 : Form
{
string _ytUrl;
public Form1()
{
InitializeComponent();
}
public string VideoId
{
get
{
var ytMatch = new Regex(#"youtu(?:\.be|be\.com) / (?:.*v(?:.*/|=)|(?:.*/)?)([a-zA-Z0-_]+)").Match(_ytUrl);
return ytMatch.Success ? ytMatch.Groups[1].Value : string.Empty;
}
}
//user input (URL)
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
//play button
private void button1_Click(object sender, EventArgs e)
{
_ytUrl = txtUrl.Text;
webBrowser.Navigate($"http://youtube.com/v/{VideoId}?version=3");
}
//help button
private void button2_Click(object sender, EventArgs e)
{
}
//browser
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}

The way moving forward is to use WebView2 which is basically the same thing as a WebView but based on the chromium-based edge. It will be always up to date on windows 10/11 machines and it works down to Windows 7.
https://developer.microsoft.com/en-us/microsoft-edge/webview2/

Related

"while" loop in windows forms apllication - no window is opened (c#)

I am new to C# and I want to create a windows forms application, which shows (it must be visible!) one window with some information and buttons and also it loads a page from internet (with selenium and phantom.js - though it is deprecated) every minute. I've written something like this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using OpenQA.Selenium;
using OpenQA.Selenium.PhantomJS;
namespace WindowsFormsApplication1
{
public partial class Someclass : Form
{
private void label1_Click(object sender, EventArgs e)
{
}
private void Someclass_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
// Shows some text "Hello friend"
MessageBox.Show("Hello friend!");
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello again", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public Someclass()
{
InitializeComponent();
while (!IsDisposed)
{
MessageBox.Show("Now the page will be downloaded");
var driverService = PhantomJSDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
using (var driver = new PhantomJSDriver(driverService))
{
driver.Navigate().GoToUrl("http://stackoverflow.com/");
MessageBox.Show("Here we are going to open StackOverflow");
var questions = driver.FindElements(By.ClassName("fs-display2"));
foreach (var question in questions)
{
// This will display some text from stackoverflow main page.
Console.WriteLine(question.Text);
question.Click();
MessageBox.Show("This is stackoverflow: " + question.Text);
}
MessageBox.Show("Here we go");
}
System.Threading.Thread.Sleep(60000); // delay in microseconds
}
}
}
My problem is that if I use "while", my window does not appear (but the page from internet loads correctly - every 1 minute), and if I use "if" instead of "while", my window appears well, but, of cource, the page loading goes only one time. What can solve my problem?
It's a quite simple solution: your while loop is preventing your UI from Update. You have to bring your loop in an extra Thread, or just use a backgroundworker
Yes, friends, you were right. I have put (using panel of instruments-> Background Worker):
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
while (!IsDisposed)
{
......................
}
System.Threading.Thread.Sleep(60000); // delay in microseconds
}
inside my public partial class someClass : Form after public Someclass()
and also added:
backgroundWorker1.RunWorkerAsync(2000);
inside my public Someclass()
So now the code looks like:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using OpenQA.Selenium;
using OpenQA.Selenium.PhantomJS;
namespace WindowsFormsApplication1
{
public partial class Someclass : Form
{
private void label1_Click(object sender, EventArgs e)
{
}
private void Someclass_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
// Shows some text "Hello friend"
MessageBox.Show("Hello friend!");
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello again", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public Someclass()
{
InitializeComponent();
backgroundWorker1.RunWorkerAsync(2000);
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
while (!IsDisposed)
{
MessageBox.Show("Now the page will be downloaded");
var driverService = PhantomJSDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
using (var driver = new PhantomJSDriver(driverService))
{
driver.Navigate().GoToUrl("http://stackoverflow.com/");
MessageBox.Show("Here we are going to open StackOverflow");
var questions = driver.FindElements(By.ClassName("fs-display2"));
foreach (var question in questions)
{
// This will display some text from stackoverflow main page.
Console.WriteLine(question.Text);
question.Click();
MessageBox.Show("This is stackoverflow: " + question.Text);
}
MessageBox.Show("Here we go");
}
System.Threading.Thread.Sleep(60000); // delay in microseconds
}
}
}
and works fine.

Clicking a Link on a Web page by using Keywords

I want to be able to open supreme's website, (www.supremenewyork.com), go to any of the tabs (shirts, jackets, etc.) and be able to input the keywords of the shirt I want to click on, and then have my program click on it.
I figured out how to get it to automatically click onto checkout and fill out the fields. Here is the html for a random shirt that we will use for example.
https://www.supremenewyork.com/shop/all/shirts
I want to click on the Houndstooth Flannel Zip Up Shirt in the color Red
I have read that you need to use HTMLAgilityPack to be able to type in those inner text's for the keywords. But I think you guys can send me the right way.
Here is the HTML
<article><div class="inner-article"><a style="height:150px;" href="/shop/shirts/gsfge9btl/mkza7miyc"><img width="150" height="150" src="//assets.supremenewyork.com/160974/vi/eYFAEBVxJT0.jpg" alt="Eyfaebvxjt0"></a><h1><a class="name-link" href="/shop/shirts/gsfge9btl/mkza7miyc">Houndstooth Flannel Zip Up Shirt</a></h1><p><a class="name-link" href="/shop/shirts/gsfge9btl/mkza7miyc">Red</a></p></div></article>
Here is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HtmlAgilityPack;
namespace Supreme
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("https://supremenewyork.com/shop");
}
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("https://www.supremenewyork.com/shop/accessories");
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
foreach (HtmlElement btn in
webBrowser1.Document.GetElementsByTagName("input"))
{
if (btn.GetAttribute("className") == "button")
{
btn.InvokeMember("Click");
}
}
}
private void button2_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("https://supremenewyork.com/shop/all/shirts");
}
private void button3_Click(object sender, EventArgs e)
{
webBrowser1.GoBack();
}
private void button4_Click(object sender, EventArgs e)
{
foreach (HtmlElement btn in
webBrowser1.Document.GetElementsByTagName("a"))
{
if (btn.GetAttribute("className") == "button checkout")
{
btn.InvokeMember("Click");
}
}
}
}
THANK YOU!

Updating to recent version of IE on webbrowser control to run local jQuery

I have studied the several questions relating to this topic(Cannot force WebBrowser Control to render using current version of IE ,Use latest version of Internet Explorer in the webbrowser control) but my C# knowledge is too basic to find out where I should be placing this 'fix' in my code.
I am using visual studio 2015 and writing a winforms application in C#. The application consists of a web browser that displays local HTML files, some of which are using jquery and javascript. I know I have to edit the registry but I have no clue on how to go about this safely. The code provided in the second link seems good, but I don't know what to change in it so it applies to my project and where to place it in my code.
my Form1.cs so far.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Web_Browser
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button4_Click(object sender, EventArgs e)
{
string curDir = Directory.GetCurrentDirectory();
this.webBrowser1.Url = new Uri(String.Format("file:///{0}/post-op/index.html", curDir));
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
private void navigateToPage()
{
var filemapping = new Dictionary<string, string>
{
{ "www.xy.com", "file:///{0}/XY/index.html" },
{ "www.post-op.com", "file:///{0}/post-op/index.html" },
{ "www.free-mail.com", "file:///{0}/mail/index.html"},
{ "test", "file:///{0}/index.html" },
};
var textEntered = textBox1.Text;
string filename;
if (filemapping.TryGetValue(textEntered, out filename))
{
string curDir = Directory.GetCurrentDirectory();
var uri = new Uri(String.Format(filename, curDir));
webBrowser1.Navigate(uri);
}
}
private void button3_Click(object sender, EventArgs e)
{
navigateToPage();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)ConsoleKey.Enter)
{
navigateToPage();
}
}
private void backButton_Click(object sender, EventArgs e)
{
webBrowser1.GoBack();
}
private void forwardButton_Click(object sender, EventArgs e)
{
webBrowser1.GoForward();
}
private void button6_Click(object sender, EventArgs e)
{
string curDir = Directory.GetCurrentDirectory();
this.webBrowser1.Url = new Uri(String.Format("file:///{0}/mail/index.html", curDir));
}
}
}
Sorry if this seems stupid. I have really tried to solve this issue on my own with the answers already given on the several questions on SO, but i'm a bit lost atm.

saving information in a database/displaying them in a GUI window. (Visual Studios)

I am trying to make a room request program and have two windows that I need to connect to the database (which I know how to do). The two windows are called EMERGENCY and JANITOR. My issue is I don't know how to store information in a database. Like let's say someone logs in as EMERGENCY and sends a request, the information needs to be stored and once the JANITOR logs in, he can see the requests. So far I have the database but not sure about storing information in it without manually adding them. If anyone has any guides or links on how to do this, I'd appreciate it!
EMERGENCY window code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace LOGINPAGE
{
public partial class EMERGENCY : Form
{
public EMERGENCY()
{
InitializeComponent();
}
void Fillcombo()
{
}
private void EMERGENCY_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'roomInfoDataSet6.Table' table. You can move, or remove it, as needed.
}
private void xButton1_Click(object sender, EventArgs e)
{
this.Close();
Application.Exit();
}
private void xButton2_Click(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Search_Click(object sender, EventArgs e)
{
}
}
}
JANITOR code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LOGINPAGE
{
public partial class JANITOR : Form
{
public JANITOR()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void JANITOR_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'roomInfoDataSet3.Table' table. You can move, or remove it, as needed.
this.tableTableAdapter.Fill(this.roomInfoDataSet3.Table);
}
private void xButton4_Click(object sender, EventArgs e)
{
}
private void xButton2_Click(object sender, EventArgs e)
{
this.Close();
Application.Exit();
}
}
}
EMERGENCY
JANITOR
You can use Ms access db
You will find connecting to acess from c# to really easy with lots of YouTube video tutorials
I can have a table in it database that is updated by a "save emergency" button and a load emergency button by the janitor will just populate a datagridview with items from the same table filled with the first button

SendKeys clashing with Windows Forms Application buttons

I've recently made this small Windows Forms Application:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace Spammer
{
public partial class Form1 : Form
{
Thread t1;
int delay, y = 1;
public Form1()
{
t1 = new Thread(send);
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
delay = int.Parse(textBox2.Text);
t1.Start();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
y = 0;
}
private void send()
{
while (y == 1)
{
String textt = textBox1.Text;
Thread.Sleep(delay);
SendKeys.SendWait(textt);
}
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
}
}
Now, it looks like this:
It has a Delay textbox, a Text to Send textbox, and 2 buttons: Start and Stop.
Now, I've tried running it and setting the delay to 1000ms.
When I press the "Stop" button, it perfectly stops and no more messages are sent.
But when I input in the delay very small delays like 100ms, for example, pressing "Stop" doesn't do anything.
It's even kind of hard to click it, and even when I click it doesn't stop sending the messages.
Why is this? And can I solve it somehow?
OK, Thank you, everyone, for helping!
I'm now using the GUI timer and it works flawlessly.

Categories