Hi i want to do like this. i'm writing a webbrowser application in c# and i will set as default browser.but i have one problem if i set it won't open clicked link from other program or html file on desktop.
how can i do that ?
it should be like this photos.
i hope you understand my english.sorry for my english. :)
private void Form1_Load(object sender, EventArgs e)
{
panel3.BackColor = Doga_Rhodonit.Properties.Settings.Default.themebg;
((WebKitBrowser)tabControl1.SelectedTab.Controls[0]).Navigate(what should i write or what event should i write??);
If your browser is set to the default when a link is pressed the OS will send the URL as a argument
string URL = null;
public static void Main(string[] args)
{
Console.WriteLine(args[0]);
URL = args[0];
}
private void Form1_Load(object sender, EventArgs e)
{
panel3.BackColor = Doga_Rhodonit.Properties.Settings.Default.themebg;
((WebKitBrowser)tabControl1.SelectedTab.Controls[0]).Navigate(URL);
Related
I am new to ASP.NET and C#. In a Web App, I know I can create a button that opens a webpage:
private void button1_Click(object sender, EventArgs e)
{
//Launch browser
System.Diagnostics.Process.Start("https://www.nhl.com/jets");
}
But if the landing page has a search bar, how can I send a keyword to that search bar upon clicking the button? For clarity, say that my code-behind declares that keyword like this:
string keyword = Keyword.Text. How can I make sure that this keyword is automatically sent to the search bar, so that users can see the results without having to type the keyword?
Try this, you should use webBrowser automation. i adapted this methods i wrote before to your website, just add your little adjustments:
... string keyboard = Keyword.Text
public String GetKeyboardValueForSearch() {
return keyboard;
}
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.DocumentCompleted += new
WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
webBrowser1.Navigate("https://www.nhl.com/jets");
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlElement search = webBrowser1.Document.GetElementById("top-nav__search-
autocomplete__input");
if(search != null)
{
search.SetAttribute("value", GetKeyboardValueForSearch());
foreach(HtmlElement ele in search.Parent.Children)
{
if (ele.TagName.ToLower() == "input" && ele.Name.ToLower() == "go")
{
ele.InvokeMember("click");
break;
}
}
}
}
I want to make a windows form using C# to check if a file exist.
I've tried this one:
private void test_Click(object sender, EventArgs e)
{
var app1 = (#"C:\Users\frangon\Desktop\Spectrum-Check.EXE");
test.Text = File.Exists(app1).ToString();
}
If possible, I don't want to click it. I just want it to show as "True" if the file exist, or "False" if the file doesn't exist.
You can add an event to trigger when the form loads:
And then in your code behind:
private void Form1_Load(object sender, EventArgs e)
{
string app1 = #"C:\Users\frangon\Desktop\Spectrum-Check.EXE";
test.Text = File.Exists(app1).ToString();
}
Was creating a browser and was testing how different websites load and noticed on some website the C# web browser will not fully load specific websites. Seems to default to mobile maybe?
For example, Apartmentbutler.com
Compared to full browser
Another example, cleancloudapp, gets stuck here.
For sake of details - very basic.
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load_1(object sender, EventArgs e)
{
webBrowser1.ScriptErrorsSuppressed = true;
}
private void button1_Click(object sender, EventArgs e)
{
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
string webPage = textBox1.Text.Trim();
webBrowser1.Navigate(webPage);
}
}
}
Is this something because of the webdeveloper? If it's because mobile, why not loading properly? Can I use useragent to force to desktop?
Would appreciate any help, thank you.
By default, the WebBrowser control runs in compatibility view mode. Compatibility view mode is basically document mode 7. That most likely caused the rendering issue.
You can change the IE version for webbrowser control by adding HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\yourapp.exe and set its DWord value to e.g. 11001 (IE 11)
For 32 bits machine add under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION\
Details at https://msdn.microsoft.com/library/ee330730(v=vs.85).aspx#browser_emulation
I cannot figure this out
i'm making a windows form application with visual basic in c#
i have a scan button and it scans everything in the folder and lists all of the files in the listbox
if you click it another time the list of files appear again
how can you make it so you can only press the scan button once, and then you can press it again if you click the browse button?
the browse button is to select the folder you want to scan
thanks
This is pretty trivial
private void ScanButtonClick(object sender, EventArgs e)
{
// do something
(sender as Button).Enabled = false;
}
private void BrowseButtonClick(object sender, EventArgs e)
{
ScanButton.Enabled = true;
}
Its a bit unclear if you're writing in C# or vb.net, but since the question is tagged as C#...
private void btnScan_Click(object sender, EventArgs e) {
btnScan.Enabled = false;
// other code here
}
private void btnBrowse_Click(object sender, EventArgs e) {
btnScan.Enabled = true;
//other code here
}
I tried this in my windows form application in C# and it works fine!
private void button3_Click_1(object sender, EventArgs e)
{
int count = 0;
count++;
//add your code here
if (count == 1) {
button3.Enabled = false;
//only one click allowed
}
}
I am using the Gekofx browser because my html files don't work with the default webbrowser control.
So far I was using ObjectForScripting to call javascript code from my C# project. But I was not able to call anything with the Gekofx browser.
I just want to send some data to my html file and display it with the Gekofx browser. Is it possible at all?
For contemplation here is my code:
GeckoWebBrowser myBrowser;
public Form1()
{
InitializeComponent();
String path = #"C:\tools\xulrunner\xulrunner-sdk\bin";
Console.WriteLine("Path: " + path);
Skybound.Gecko.Xpcom.Initialize(path);
myBrowser = new GeckoWebBrowser();
myBrowser.Parent = this;
myBrowser.Dock = DockStyle.Fill;
}
private void btn_go_Click(object sender, EventArgs e)
{
// like the normal browsers
myBrowser.Navigate(tbx_link.Text);
}
private void btn_test_Click(object sender, EventArgs e)
{
// getting the link to my own html file
String path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Webpage");
path += "\\Webpage.html";myBrowser.Navigate(path);
}
I hope you understand what I mean. Thank you!
You can always invoke javascript like this:
mybrowser.Navigate("javascript:YourJavascriptFunction('yourArgument1', 'youArgument2')");
Building on #jordy's answer above, call:
mybrowser.Navigate("javascript:YourJavascriptFunction('yourArgument1', 'youArgument2')");
prefferably in the Document complete event handler to allow for the page to first load.
void myBrowser_DocumentCompleted(object sender, Gecko.Events.GeckoDocumentCompletedEventArgs e)
{
myBrowser.Navigate("javascript:YourJavascriptFunction('yourArgument1', 'youArgument2')");
}