I am currently using a simple button to open a webpage.
void ReportingClick(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://www.google.ca");
}
What I want to do is get it to open 3 pages at once with the one click and I am having a hard time getting it to work. I have tried multiple Process.start lines
void ReportingClick(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://www.google.ca");
System.Diagnostics.Process.Start("http://www.gmail.com");
System.Diagnostics.Process.Start("http://www.stackoverflow.com");
}
and even adding multiple pages into the handler.
void ReportingClick(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://www.google.ca","http://www.gmail.com","http://www.s tackoverflow.com")
}
It will only open the last page in the list in both cases. Any ideas?
If IE is open, your code works fine and opens each link in a new tab, if not, I was able to make it work by making the app wait for 1 sec before calling the second page to open:
void ReportingClick(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://www.google.ca");
System.Threading.Thread.Sleep(1000);
System.Diagnostics.Process.Start("http://www.gmail.com");
System.Threading.Thread.Sleep(1000);
System.Diagnostics.Process.Start("http://www.stackoverflow.com");
}
Related
New to C# and learning as i go. I've tried Googling, but havent found what im looking for (still looking).
I have a simple C# App that so far is working fine. The next part i want to figure out is how to invoke a series of tasks/methods.
Say i have 4 individual tasks (Tasks 1-4). Each one of them does something different...
Button 1 - Shows a Messagebox
Button 2 - Changes a label text color
Button 3 - Writes something to console.
etc
etc.
Each one of these works fine when you press its associated button. But now lets say i have a Checkbox next to each of these that you can check/uncheck. Plus a button that says "run selected".
My question is how do i program that button to run ALL the tasks in sequential order AND only run the tasks that are selected?
Checkbox 1 - OFF
Checkbox 2 - ON
Checkbox 3 - OFF
Checkbox 4 - ON
So when i press the "Run Selected" Button - Only Tasks 2 and 4 run.
Again, im new, and my lingo may not be correct - but hopefully you get the idea.
Thanks,
Mike
First of all, I would isolate each task outside the click handlers of the buttons, into its own methods:
private void Task1()
{
MessageBox.Show("Task 1");
}
private void Task2()
{
MessageBox.Show("Task 2");
}
private void Task3()
{
MessageBox.Show("Task 3");
}
private void Task4()
{
MessageBox.Show("Task 4");
}
I just used simple message boxes for the sake of simplicity, but any code will work actually.
Then make each click handler just call each method:
private void button1_Click(object sender, EventArgs e)
{
this.Task1();
}
private void button2_Click(object sender, EventArgs e)
{
this.Task2();
}
private void button3_Click(object sender, EventArgs e)
{
this.Task3();
}
private void button4_Click(object sender, EventArgs e)
{
this.Task4();
}
Now the important part, when the "do all checked" button is clicked, you check each checkbox state and launch the appropriate method in sequence:
private void button5_Click(object sender, EventArgs e)
{
if (this.checkBox1.Checked) this.Task1();
if (this.checkBox2.Checked) this.Task2();
if (this.checkBox3.Checked) this.Task3();
if (this.checkBox4.Checked) this.Task4();
}
I'm working with C# ASP.NET Web Application. There is a problem that is difficult to track in the code.
Let's say I have two buttons: Upload (which uploads some data from DataTable to Database) and Cancel (which cancels the uploading process). The problem is that uploading process runs in the BackgroundWorker. When user clicks Upload and uploading starts and then he clicks Cancel the Cancel_Button_Click event does not fire until BackgroundWorker is uploading data.
I have code like this:
protected void Page_Load(object sender, EventArgs e)
{
backgroundWorker1.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);
}
protected void Upload_Button_Click(object sender, EventArgs e)
{ backgroundWorker1.RunWorkerAsync(); }
protected void Cancel_Button_Click(object sender, EventArgs e)
{ backgroundWorker1.CancelAsync(); }
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{ };
So what really happens is when you click Upload and Cancel is method private void backgroundWorker1_ProgressChanged runs many times (one time for every row of data, I suppose) and ONLY THEN method Cancel_Button_Click runs.
What to do, if I want to stop data uploading right after Cancel button is clicked?
Thaaaanks! :)
P.S. I tried searching on the net but I don't even know how to describe my problem in one sentence.
I have a very simple program that has 4 buttons each button opens a url.
What i would like is to get each button to use Firefox as the default browser.
I know i can set it as the default browser and then it will work however if a user sets internet explorer as the defualt it will open in that instead.
These url only work in Firefox as it has certificate issues.
So essentially my question is how can i change my code to make sure that if you click on any of the 4 buttons, that it will open up in firefox and not internet explorer.
Here is my code
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://192.168.2.56/dummy.htm?settings=save&user_active1=on");
BtnOff.BackColor = Color.Red;
Bnton.BackColor = Color.Chartreuse;
}
private void button2_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://192.168.2.56/dummy.htm?settings=save&user_active1=off");
Bnton.BackColor = Color.Red;
BtnOff.BackColor = Color.Chartreuse;
}
private void button3_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://217.20.xxx.xxx/api/agent/pause.json?active_host=217.20.xxx.xxx&active_user=3012532&username=buildstore&password=cha9pU7U&client=snom");
BtnDND.BackColor = Color.Chartreuse;
BtnQue.BackColor = Color.Red;
}
private void button4_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://217.20.xxx.xxx/api/agent/unpause.json?active_host=217.20.xxx.xxx&active_user=3012532&username=buildstore&password=cha9pU7U&client=snom");
BtnQue.BackColor = Color.Chartreuse;
BtnDND.BackColor = Color.Red;
}
Thanks for taking the time to look appreciate it.
you can use
System.Diagnostics.Process.Start(#"C:\Program Files (x86)\Mozilla Firefox\firefox.exe", "http://yoursite.com/dummy.htm");
you can keep the path of firefox.exe in config file instead of hard coding. Alternatively set the PATH environment variable.
I have a program that I wrote for sending messages to some of my friends through a website. It works fine, but for some reason I can't get it to work correctly with just one button click event. If I don't have a second button click for the SEND data method (whichs POSTs the data), it will always just keep sending the message to the same person, eventhough the new URL is loaded into the webBrowser URL*, but if I have that second click event all works fine. What am I missing?
*Using the debugger I see a new URL load with every iteration, but I do see on the HTTP debugger that the program is sending to the same URL each time
private void button1_Click(object sender, EventArgs e)
{
ListBox();
}
private void ListBox()
{
//gets name from ListBox
GetData();
}
private void GetData()
{
webBrowser1.Navigate(inputURLID);
//SendData (); Always sends to the same person if I call from here, so I made a second button click and it works fine
}
private void button2_Click(object sender, EventArgs e)// works fine like this
{
webBrowser1.Document.GetElementById("subject").SetAttribute("value", textBox2.Text);//To (username)
webBrowser1.Document.GetElementById("message").SetAttribute("value", richTextBox1.Text);//Subject
webBrowser1.Document.GetElementById("Submit").InvokeMember("click");//Message
}
....
private void SendData()// always sends to the same person if I just do it like this
{
webBrowser1.Document.GetElementById("subject").SetAttribute("value", textBox2.Text);//To (username)
webBrowser1.Document.GetElementById("message").SetAttribute("value", richTextBox1.Text);//Subject
webBrowser1.Document.GetElementById("Submit").InvokeMember("click");//Message
}
Try to populate your fields only when the url has been loaded (when DocumentCompleted event is fired):
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document.GetElementById("subject").SetAttribute("value", textBox2.Text);//To (username)
webBrowser1.Document.GetElementById("message").SetAttribute("value", richTextBox1.Text);//Subject
webBrowser1.Document.GetElementById("Submit").InvokeMember("click");//Message
}
I created a winForm application which fills the fields of a web site :
private void Form1_Load(object sender, EventArgs e)
{
this.webBrowser1.Navigate(new Uri("http://www.site.com”));
this.textBox1.Text = this.webBrowser1.Version.ToString();
}
private void button1_Click (object sender, EventArgs e)
{
System.Windows.Forms.HtmlDocument document =
this.webBrowser1.Document;
document.GetElementById("login").SetAttribute("Value","user");
}
It works perfectly when the web site page is loaded in application control but when I want to open it in a new browser using webBrowser1.Navigate(new Uri("http://www.site.com”),true); the page fields are undetectable.
Is there a solution for this problem? Thanks in advance