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.
Related
At the moment I am using this here in my WPF App which works as it should.
private void buttonPresentations_Click(object sender, EventArgs e)
{
openFileDialogPresentations.ShowDialog();
}
It remembers the last path I was in but I want to change it to a set path now.
I have 3 Radiobuttons and each Radiobutton should lead to a different path so I thought about doing it with a variable I give to the openFileDialog but I am not sure on how to go with that. Has anyone done this and can give me a lead on it ?
You can set IntitialDirectory to the folder you want in code where you show the dialog.
private void buttonPresentations_Click(object sender, EventArgs e)
{
openFileDialogPresentations.IntitialDirectory = youFolderPath;
openFileDialogPresentations.ShowDialog();
}
The standard file dialogs have an InitialDirectory property that determines in which folder the dialog opens.
private void buttonPresentations_Click(object sender, EventArgs e)
{
openFileDialogPresentations.InitialDirectory = #"X:\Data\Presentations";
openFileDialogPresentations.ShowDialog();
}
You can do it by using InitialDirectory property. You can set three different paths for radio buttons
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.InitialDirectory=#"D:\MyDir";
dialog.ShowDialog();
}
I have a project that reads content from web and saves it to the database.
I use Timer control to wait for ajax changes and it has been working for a long time without any problem.
But unexpectedly it is not working any more. I get the following error :
Exception thrown: 'System.Runtime.InteropServices.COMException' in
SnapshotInfo.exe
Additional information: Error HRESULT E_FAIL has been returned from a
call to a COM component.
Part of the code on this problem :
WebBrowser _browser = new WebBrowser();
private void Form1_Load(object sender, EventArgs e)
{
_browser.Dock = DockStyle.Fill;
_browser.DocumentCompleted += _browser_DocumentCompleted;
Controls.Add(_browser);
}
private void _browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (!timer1.Enabled)
{
// do any thing
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
_browser.Dispose();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (_browser.Document==null || _browser.Document.Body==null) return;
var body = _browser.Document.Body.InnerHtml; // ----> error here
if (body.Contains("word"))
{
// code when word is exist
timer1.Enabled = false;
}
}
private void button1_Click(object sender, EventArgs e)
{
_browser.Navigate(textBox1.Text);
timer1.Enabled = true;
}
I do not know where is the problem?
Thanks for any help
Make sure you are using latest version of web browser control , check below link
Use latest version of Internet Explorer in the webbrowser control
or you can replace web browser control with another web browser engine like http://www.awesomium.com/ it's free and easier to use
The problem solved by deleting the security update KB3087040!
I am making a game similar to "Make it Rain" or "Cookie Clicker." I have settings where you can purchase items to make each click of the cookie produce more cookies. I have been trying to make the game save the variable. For example, each click produces a cookie. If you have 100 cookies, you can buy a cookie cutter, so each click produces 5 cookies, and so on. I have booleans called cookiecutters, which are false. If the user buys the item, cookiecutters = true. I would like to save this variable to true so when the user closes and reopens the form, each click produces 5 cookies. This is what I have come up with, yet it doesn't work.
private void Form1_Load(object sender, EventArgs e)
{
if (cookiecutter == true)
{
cookiecutter = Convert.ToBoolean(Properties.Settings.Default.cookiecutter);
cookiecutter = Properties.Settings.Default.cookiecutter;
}
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
if (cookiecutter== true)
{
Properties.Settings.Default.cookiecutter = cookiecutter = true;
}
Properties.Settings.Default.Save();
}
Thank you all for the help in advance!
Your code looks weird. Try to make these changes and make sure your initial value in the settings for cookiecutter is false.
private void Form1_Load(object sender, EventArgs e)
{
cookiecutter = Convert.ToBoolean(Properties.Settings.Default.cookiecutter);
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Properties.Settings.Default.cookiecutter = cookiecutter;
Properties.Settings.Default.Save();
}
Almost.. you can get the value trough
Properties.Settings.Default.["cookiecutter"]
instead of
Properties.Settings.Default.cookiecutter
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");
}
I'm trying to load a specific image in my picture box if a specific radio button is checked.
The run-time error was a "_Couldn't locate file in this directory.", so I moved the images to that directory, but that just caused the picture box to load it automatically.
I've also imported all of the images I need as well.
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
pictureBox1.Load("10C.jpg");
}
}
When I run the program pictureBox1 had already loaded the image. What I want my pictureBox1 to do is remain blank until the user selects a radio button and clicks the "change image" button.
You should place pictureBox1.Visible = false; in the form load event
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Visible = false;
}
You could make it so that pictureBox1.Visible = false;
Then you could say:
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
pictureBox1.Visible = true;
pictureBox1.Load("10C.jpg");
}
}
This way the image is not seen until the button is clicked.
I would recommend you to set a default image in picture box at startup and if a radiobutton is checked and a button is clicked load the desired image (10C.jpg) into picture box instead of dealing with the visible property of the picture box.
The code will look like:
private void button1_Click(object sender, EventArgs e)
{
// pictureBox1.Visible will be always set to true
if (radioButton1.Checked)
{
pictureBox1.Load("10C.jpg");
}
else
{
pictureBox1.Load("placeholder.jpg");
}
}
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Visible = true;
pictureBox1.Load("placeholder.jpg");
}
Recommended: search google for placeholder image
Hope it helps!
EDIT
In response of:
The run-time error was a "_Couldn't locate file in this directory.",
so I moved the images to that directory, but that just caused the
picture box to load it automatically. I've also imported all of the
images I need as well.
Define a key in config file that holds an image path and use it to access your images by concatenating filename at the end. With this approach you can change image path even after deployment.