I'm programming an algorithm in C# to download an image from a website and my software automatically fills all the required fields and presses the download button. The problem is that I'm not able to load the image. The dialog box to download image on Internet Explorer is appearing, so I need to get the url of the picture after clicking the button "generate" and load it into the picture box. My code:
private void simpleButton6_Click(object sender, EventArgs e)
{
string i = "0";
HtmlElement hu = webBrowser3.Document.GetElementById("data-text");
hu.Focus();
hu.SetAttribute("Value", txtEncodeData.Text);
HtmlElement hu1 = webBrowser3.Document.GetElementById("color");
hu1.Focus();
Color c = customColorBlender1.SelectedColor;
string hex = c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");
hu1.SetAttribute("Value", hex);
HtmlElement hu2 = webBrowser3.Document.GetElementById("effect");
hu2.Focus();
if (comboBoxEdit1.SelectedIndex == 1)
{
i = "1";
}
hu2.SetAttribute("Value", i);
webBrowser3.Document.GetElementById("generate").InvokeMember("click");
t.Interval = 1000;
t.Start();
t.Tick += new EventHandler(t_Tick);
}
void t_Tick(object sender, EventArgs e)
{
t.Stop();
String url = Convert.ToString(webBrowser3.Document.GetElementById("download").InvokeMember("click"));
MessageBox.Show(url);
pictureBox15.ImageLocation = Convert.ToString((Uri)webBrowser3.Document.GetElementById("download").InvokeMember("click"));
}
Related
Okay. So, I'm making my own internet browser and I have tabs. But, I'm trying to make it a real time url updater while if you click on any link it will show up in the textbox of the url.
It will not work.
Here is the tab button.
private void button8_Click(object sender, EventArgs e)
{
WebBrowser Browser = new WebBrowser();
tabControl1.TabPages.Add("New Page");
tabControl1.SelectTab(tabControl1.TabPages.Count - 1);
Browser.Name = "Web Browser";
Browser.Dock = DockStyle.Fill;
tabControl1.SelectedTab.Controls.Add(Browser);
((WebBrowser)(tabControl1.SelectedTab.Controls[0])).GoHome();
And here is where my textbox isn't getting the right url.
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
button1.Enabled = true;
textBox1.Enabled = true;
//textBox1.Text = Browser.Url.ToString();
((WebBrowser) (this.tabControl1.SelectedTab.Controls[0])).Url.ToString();
}
In order for this to work, you need to get all link elements of the web page you've just loaded and assign a custom function to the HtmlElement.Click event of that element.
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
button1.Enabled = true;
textBox1.Enabled = true;
var linkElements = Browser.Document.GetElementsByTagName("a");
foreach(HtmlElement link in linkElements)
{
link.Click += (s, args) =>
{
// a link is being clicked
// get the url the link is pointing to using the href attribute of the element
textBox1.Text = link.GetAttribute("href");
}
}
}
I use a LabelLink contorl in a WinForm.
On form load I set the desired link:
LinkLabel.Link link = new LinkLabel.Link();
link.LinkData = "http://stackoverflow.com/questions/ask";
linkLabel1.Links.Add(link);
On click :
void LinkLabel1LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(e.Link.LinkData as string);
}
The link is gray and nothing happens when I click on it.
What is missing?
Try this
LinkLabel.Link link = new LinkLabel.Link();
link.LinkData = "http://stackoverflow.com/questions/ask";
linkLabel1.Links.Add(link);
this.linkLabel1.Links[0].LinkData = "Ask a question";
linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.LinkLabel1LinkClicked);
and
void LinkLabel1LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string url;
url = e.Link.LinkData.ToString();
if (!url.Contains("://"))
url = "http://" + url;
var myLink = new ProcessStartInfo(url);
Process.Start(myLink);
linkLabel1.LinkVisited = true;
}
i am programming in Visual Studio 2013, c# winform. Is it posible to choose click event for each button in FLP? Im trying to do something like Steam Library, I already did a lot of things and it now looks like i want to.
This is how it looks (adding)
This is how it looks (library)
(sorry, im not able to add images)
But i don't know how to open choosed game when you click on a button in FLP (in library).
This is how my code looks:
private void btnTest_Click_1(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
if (textBox2.Text != "")
{
Button btn = sender as Button;
Button btnNew = new Button();
btnNew.Text = "";
btnNew.Height = 108;
btnNew.Width = 230;
btnNew.Image = new Bitmap(textBox1.Text);
btnNew.FlatStyle = FlatStyle.Flat;
flpContainer.Controls.Add(btnNew);
btnNew.Click += btnNew_Click;
counter1++;
label1.Text = counter1.ToString(); //label1 is that "Number of games in library:"
System.Windows.Forms.MessageBox.Show("Game was succesfully added to library!");
}
else if (textBox2.Text == "")
{
System.Windows.Forms.MessageBox.Show("You didn't choosed exe file!");
}
}
if (textBox1.Text =="")
{
System.Windows.Forms.MessageBox.Show("You didn't choosed image!");
}
}
private void btnNew_Click(object sender, EventArgs e)
{
Process.Start(textBox2.Text); //textbox2 is the path to exe file, but it change when you want to add another game to library
}
But how to do different click event for each button in FlowLayoutPanel?
Thank you for answers.
EDIT: I want to do that, when you click on a button in library it will open that game (program).
Thank you a lot!
Store the required information in Tag property for future use and get the job done.
Button btnNew = new Button();
btnNew.Text = "";
btnNew.Height = 108;
btnNew.Width = 230;
btnNew.Image = new Bitmap(textBox1.Text);
btnNew.FlatStyle = FlatStyle.Flat;
flpContainer.Controls.Add(btnNew);
btnNew.Click += btnNew_Click;
btnNew.Tag = textBox2.Text;// <--Store it in Tag
Then use it in Click event
private void btnNew_Click(object sender, EventArgs e)
{
Button clickedButton = (Button)sender;
Process.Start((string)clickedButton.Tag);
}
I have a situation which occurs in WebBrowser with C#.
I am trying to do downloader through a site However , when i click first time, it doesn't work but if I click second times it works.
How can i solve this problem .
Sincerely.
Codes :
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Document.GetElementById("youtube-url").SetAttribute("value", textBox1.Text);
webBrowser1.Document.GetElementById("submit").InvokeMember("click");
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
label3.Text = "Video Alındı , indirme işleminin hazır olması bekleniyor";
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlElementCollection col = webBrowser1.Document.GetElementsByTagName("a");
String link = "";
foreach (HtmlElement el in col)
{
if (el.InnerText == "Download")
{
link = el.GetAttribute("href");
Download(link);
label3.Text = "Video indiriliyor";
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.ScriptErrorsSuppressed = true;
webBrowser1.Navigate("http://www.youtube-mp3.org/tr");
}
void Download(String link)
{
WebClient downloader = new WebClient();
downloader.DownloadFileAsync(new Uri(link),#"D:\a.mp3");
downloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged);
}
void downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
label3.Text = "Video İndiriliyor : " + progressBar1.Value + "%";
if (progressBar1.Value == 100)
label3.Text = "Video İndirildi";
}
You're blocking yourself from investigating what the problem is. It's never a good idea to disable script errors for WebBrowser control (as you do with ScriptErrorsSuppressed = true), unless you handle them internally in your host app. Do the following:
enable script errors (ScriptErrorsSuppressed = false);
enable script debugging for all applications;
implement WebBrowser Feature Control (FEATURE_BROWSER_EMULATION), so the web page is getting the same (or close) experience and HTML features as with full-featured IE browser.
Then, hopefully, you can find out what's going wrong when you're simulating a button click, and debug it.
I'm programming a WebBrowser in C# and I have the following problem:
When a button is clicked a new tabPage is generated in tabControl1 with the WebBrowser.
private void button3_Click(object sender, EventArgs e)
{
WebBrowser browser = new WebBrowser();
browser.Dock = DockStyle.Fill;
browser.Url = new System.Uri("http://google.com");
tabControl1.TabPages.Add(new TabPage("Aba "+ (tabControl1.TabCount + 1).ToString()));
tabControl1.TabPages[tabControl1.TabCount - 1].Controls.Add(browser);
}
I need to know how to make the progress bar work with the webbrowser that belongs to the current active tabPage.
How and where do I insert the following code:
toolStripProgressBar1.Maximum = (int) e.MaximumProgress;
toolStripProgressBar1.Value = (int)e.CurrentProgress;
You can use an Anonymous Function:
WebBrowser browser = new WebBrowser();
browser.Dock = DockStyle.Fill;
browser.Url = new System.Uri("http://google.com");
tabControl1.TabPages.Add(new TabPage("Aba " + (tabControl1.TabCount + 1).ToString()));
tabControl1.TabPages[tabControl1.TabCount - 1].Controls.Add(browser);
browser.ProgressChanged += new WebBrowserProgressChangedEventHandler( delegate (object sender, WebBrowserProgressChangedEventArgs events)
{
if ((int)events.CurrentProgress > 0)
{
toolStripProgressBar1.Maximum = (int)events.MaximumProgress;
toolStripProgressBar1.Value = (int)events.CurrentProgress;
}
});
I had a problem with crushing cause the progressbar was all ready full, so here's this problem solved.
private void webBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
{
if ((int)e.CurrentProgress > 0)
{
ProgressBar.Maximum = (int)e.MaximumProgress;
if (ProgressBar.Maximum == (int)e.MaximumProgress)
ProgressBar.Value = 0;
ProgressBar.Value = (int)e.CurrentProgress;
}
}