C# webbrower automatically clicking a menu button - c#

I have seen a few of these questions on here but, none of them answered my question. I am looking to automatically click a button on the google fusion table page. I want to run this is in a windows form in visual studio 2015. I need to navigate to the file-geocode... button. I right clicked and hit the inspect button and this is the ID for the button I want
<td class="gwt-MenuItem" id="gwt-uid-209" role="menuitem" colspan="2">Geocode...</td>
is it possible to use a method similar to this?:
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Document
.GetElementById("gwt-uid-209")
.InvokeMember("Click");
}
Thank you for your help.

i used the same code that you mentioned in the question but be careful because the webBrowser may invoke more than 1 events while the document is completing.
i usually set a timer with 1000ms interval;
try this, it will take 1 second more but it will do the job.
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
webBrowser1.Document.GetElementById("gwt-uid-209").InvokeMember("Click");
}

If I use the geckobrowser how do I get it to autoclick? this is what I have now.
Xpcom.Initialize("Firefox");
var geckoWebBrowser = new GeckoWebBrowser { Dock = DockStyle.Fill };
Form f = new Form();
f.Controls.Add(geckoWebBrowser);
geckoWebBrowser.Navigate("https://www.google.com/fusiontables/data?docid=1FdRUOJ9YIXT81QdfS71qXWV3m7qmzF_4TLRrKh5r#rows:id=1");
Application.Run(f);

Related

C# Form - MouseClick will click the actual control after losing form focus

If you ever remove focus from any professional application like Chrome/FireFox/Visual Studio, and then reclick a button/menu item, it will actually click it as if you never lost focus.
How can I apply the same concept in C# WinForm? I tried many things like
private void form1_MouseClick(object sender, MouseEventArgs e)
{
BringToFront();
Activate();
}
Activate/focus/select/etc... nothing worked to react the same way, it always takes 3-4 clicks to actually click on a menu!
I thought about making a click event for every single control, but that seemed rather redundant.
Check this for example (Yellow Clicks)
You are right about Menues taking an extra click to get focus.
Which is extra annoying since the menue get highlighted anyway but doesn't react to the 1st click..
You can avoid that by coding the MouseEnter event:
private void menuStrip1_MouseEnter(object sender, EventArgs e)
{
// either
menuStrip1.Focus();
// or
this.Focus();
}
The downside of this is, that it is stealing focus from other applications, which is not something a well-behaved application should do..
So I think it is better to wait for a definitive user action; code the MouseDown event in a similar way..:
private void menuStrip1_MouseDown(object sender, MouseEventArgs e)
{
menuStrip1.Focus();
}
Or use the event that was made for the occasion:
private void menuStrip1_MenuActivate(object sender, EventArgs e)
{
menuStrip1.Focus();
}
I can't confirm a similar problem with Buttons or any other controls, though.
I have find trick to solve your problem. it work for me 100%
See this code:
dynamic elem1;
private void menuStrip1_MouseEnter(object sender, EventArgs e)
{
elem1 = sender;
}
private void menuStrip1_MouseLeave(object sender, EventArgs e)
{
elem1 = null;
}
private void Form1_Activated(object sender, EventArgs e)
{
if(elem1 != null){
elem1.PerformClick();
if (elem1.GetType().ToString() == "System.Windows.Forms.ToolStripMenuItem") elem1.ShowDropDown();
}
elem1 = null;
}
Here what happend.
When mouse enter button/menu item elem1 = this button/menu, and when mouse leave it set back to null.
so when form Activated we can call elem1.PerformClick() to click the button/menu item.

C# richBox1 text disable

I have problem with richBox1 text disabling.
I've tryed richTextBox1.readonly = true; and richTextBox1.Enabled = false;
My code:
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
richTextBox1.ReadOnly = !richTextBox1.ReadOnly;
}
Its disabling after one letter.
EDIT: And if disable I can still copy text but cant write there.
Honestly, disabling expected functionality is not something you should be doing. It is not good UI design.
The event TextChanged is fired every time the text changes (including writing or removing one letter). You can use Form's Load event (by double clicking the form on design time) :
private void Form1_Load(object sender, EventArgs e)
{
richTextBox1.ReadOnly = true;
richTextBox1.Enabled = false;
}

c# Web page Radio Button Checked Auto

WebBrowser web = new WebBrowser();
private void button1_Click(object sender, EventArgs e)
{
web.Document.GetElementById("youtubeURL").SetAttribute("value", textUrl.Text);
web.Document.GetElementById("ftype").InvokeMember("checked");
web.Document.GetElementById("submit").InvokeMember("click");
}
web.Document.GetElementById("ftype").InvokeMember("checked");
I need to make the radio button "checked". How can I do this? Thanks
I'm not sure I understood your question, but if its simply checking the radiobutton, I would suggest
radioButton1.Checked = true;

block a popup visual studio

I am using the below code in visual studio to make an auto login software . The software is working fine, But the page that is displayed after login has a popup script. This forces the opening of popup url in internet explorer. I want to block the internet explorer getting opened. Can i solve this ?
private void webBrowser1_DocumentCompleted_1(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser1.Navigate("https://mwcp-ekm-04.adlkerala.com:8001/");
webBrowser1.Document.GetElementById("name").InnerText = "name";
webBrowser1.Document.GetElementById("id").InnerText = "66491";
webBrowser1.Document.GetElementById("accept").InvokeMember("click");
}
You can prevent the opening of a new window (popup) by subscribing to the NewWindow event and then cancel the event itself:
private void webBrowser1_NewWindow(object sender, CancelEventArgs e)
{
e.Cancel = true;
}

How to hide WinForm after it run? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Single Form Hide on Startup
I want to hide my WinForm after it run (Not minimizing).
I used:
this.Load += new System.EventHandler(this.Form1_Load);
private void Form1_Load(object sender, EventArgs e)
{
Hide();
}
But it's not working. Can you help me do it?
In the form Load override you can use one of the following tricks:
Make the form completely transparent:
private void OnFormLoad(object sender, EventArgs e)
{
Form form = (Form)sender;
form.ShowInTaskbar = false;
form.Opacity = 0;
}
Move the form way off the screen:
private void OnFormLoad(object sender, EventArgs e)
{
Form form = (Form)sender;
form.ShowInTaskbar = false;
form.Location = new Point(-10000, -10000);
}
Try to hide the form after it has been shown and not after it has been loaded, use the Shown event instead of the Load event
You can't easily hide the form but what you can do is set the Opacity to 0, for example:
this.Opacity = 0;
If you Don't want the user to be able to see the app at all set this:
this.ShowInTaskbar = false;
Then they won't be able to see the form in the task bar and it will be invisible.
I believe this solved your "no use minimized" requirement??

Categories