|
Ok, I figured out why the event doesn't fire. If I put
webBrowser1.Navigate(url); it will fire, but if I put
webBrowser1.Navigate(url, true); it will not fire. The problem with that is if I use just
webBrowser1.Navigate(url); then the browser does not open and nothing occurs visibly? Any ideas?
|
|
|
|
|
Yes; add the webbrowser-control to your form and it will simply work. If the url is navigated to in an external browser, then it is no longer part of your application and will not receive any events.
Below code should work and show the basic idea;
class Program
{
static WebBrowser _wb;
[STAThread()]
static void Main(string[] args)
{
using (Form f = new Form())
{
_wb = new WebBrowser() { Dock = DockStyle.Fill };
f.Controls.Add(_wb);
_wb.Navigate(@"http://www.gmail.com");
_wb.DocumentCompleted += wb_DocumentCompleted;
f.ShowDialog();
}
}
static void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
_wb.Document.GetElementById("Email").SetAttribute("value", "s.jobs@msdn.com");
}
}
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you, this did work as far as logging me in. This is similar to something I had working yesterday with one of my attempts, it used a mshtml reference I believe.
What steered me away from this yesterday is that it is the webbrowser control and not IE. I have to create a browser helper and not a stand alone browser.
Is there any way to load the page into memory, login and then spawn the logged in page in IE and at that point disconnecting it from any application control? Am I trying to do something that cannot be done?
|
|
|
|
|
turbosupramk3 wrote: I have to create a browser helper and not a stand alone browser.
Well, that is a different story then. Google for "Browser Helper Object", and try some of those examples.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The easiest way would be to use Selenium WebDriver.If you are using Visual Studio you could add it via Nuget Package Manager.
Though its generally used for other purposes you can surely (ab)use it
|
|
|
|
|
Thanks. I tried the Selenium web driver and didn't want to have an extra 5mb (or two) dll packaged in with my executable if I didn't have to. It did work however I was hoping to use the small portion of code they use to do that, within my own project and within the .net framework instead. If the driver can do it, I can do it natively. The question is how?
|
|
|
|
|
I'm working on some client that collects information from testing station and inserts it to DB. Now i'm building a setup and i'm placing near the setup.msi some client.exe.config file with modified configurations. So the question is - is it possible somehow replace/update app.config file from external configuration file during the installation.
Thanks in advance.
|
|
|
|
|
It is. You will need to add a custom step to your installer that does this, but it's certainly possible.
|
|
|
|
|
I´m writing a communication library and have a threaded method listening for incoming data:
public partial class MCSerialPort
{
(SerialPort)port.DataReceived += DataReceivedHandler;
private async void DataReceivedHandler(object sender, SerialDataReceivedEventArgs args)
{
await ReadData();
}
private async Task ReadData()
{
await Task.Run(() =>
{
...
PackageReceived(this, new PackageReceivedEventArgs(package));
});
}
}
(MCSerialPort)port.PackageReceived += PackageReceivedHandler;
private void PackageReceivedHandler(object sender, PackageReceivedEventArgs args)
{
Package p = args.Package;
receivedRtb.Invoke((Action)delegate{receivedRtb.Text += p.ToString();} );
}
The thing is that when using this library in a "client" project the PackageReceived event handler method in the client (here the PackageReceivedHandler()) seems to be running on the same thread as the librarys ReadData() method, because I have to call Invoke() in this example in order to get the info into the receivedRtb RichTextBox. This complicates things slightly for the average library user, who might not think of having to write threadsafe code in the handler method. Is there any convenient way to make PackageReceivedHandler() run on the "main" thread?
|
|
|
|
|
TMattC wrote: the PackageReceivedHandler()) seems to be running on the same thread as the
librarys ReadData() method
Correct.
I think it's fine the way it is; the library should neither know nor care about the concerns of the calling application.
|
|
|
|
|
TMattC wrote: ... the PackageReceived event handler method in the client (here the PackageReceivedHandler()) seems to be running on the same thread as the librarys ReadData() method, because I have to call Invoke() ...
No, you have to call Invoke() because the PackageReceivedHandler isn't running on the UI thread.
There are various ways to raise the event on the UI thread - for example, using the SynchronizationContext class[^]. (It's All About the SynchronizationContext - MSDN Magazine[^])
However, since most libraries don't both doing this, most UI developers should be used to having to marshal the event handler code to the UI thread.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Label Clicked_Picture = new Label();
Random rnd = new Random();
List icons = new List()
{
"!", "!", "N", "N", ",", ",", "k", "k",
"b", "b", "v", "v", "w", "w", "z", "z"
};
private void Form1_Load(object sender, EventArgs e)
{
Random rnd = new Random();
int i = rnd.Next(icons.Count);
for (i = 0; i < icons.Count; i++)
{
Clicked_Picture.Tag = icons[i];
}
}
modified 11-Feb-15 7:59am.
|
|
|
|
|
You'd need to "Create" labels, and add them to the controls-collection of the form in order to get some labels on the form.
for (i = 0; i < icons.Count; i++)
{
Label l = new Label () { Dock = DockStyle.Top };
this.Controls.Add(l);
l.Text = icons[i];
} I've changed it from "tag" to "text", so you can see what character from the list is being loaded into the label. The "tag" property itself does not change the appearance of a label. Take note that "l" is a local variable; it won't be used outside the constructor, limits the scope and is preferable over a member-variable in this scenario.
Further, you'd only need a single random; at the moment you're creating a rnd-object in two separate places. Lastly; if you want pictures, then a PictureBox control may be preferable over a Label.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for answering. I do have 16 labels already on the form and What I'm doing is a picture matching game with wingding symbols on the text AND the tag properties. So when i click on the label it shows the tag property. Everything works except loading random wingdings in the tag properties. This code handles the clicked picture:
private void Picture_Click(object sender, EventArgs e)
{
if (tmr_Delay.Enabled == true)
return;
Clicked_Picture = (Label)sender;
Clicked_Picture.Enabled = false;
Number_of_Images++;
if (Number_of_Images < 3)
{
Clicked_Picture.Text = Clicked_Picture.Tag.ToString();
if (Number_of_Images == 1)
{
Temp_Tag = Clicked_Picture.Tag.ToString();
Temp_Pic = Clicked_Picture;
}
else
{
if (Temp_Tag != Clicked_Picture.Tag.ToString())
{
tmr_Delay.Enabled = true;
}
else
{
Num_Correct++;
lbl_Matches.Text = Num_Correct.ToString();
if (Num_Correct == 8)
{
timer1.Stop();
MessageBox.Show("Congratulations, all matches complete! \nYou completed the game in " + mins + "m " + secs + "s");
txtUsername.Visible = true;
button1.Visible = true;
lblusername.Visible = true;
lblprompt.Visible = true;
}
}
Number_of_Images = 0;
}
}
}
|
|
|
|
|
Ah, that's because it is not assigning the values it reads correctly. If you use my version, it'll put it in the tags of the controls that are created in that method - but won't hook up the clicked method.
It is below line that assigns the content of the list;
Clicked_Picture.Tag = icons[i];
It is assigned to a "New Label" in the original code. It should point to one of the existing labels. Try looking for one of the existing labels in the constructor, before assigning the value to the tag-property.
Clicked_Picture = this.Controls.Find(string.Format("Label{0}", i), true).FirstOrDefault() as Label;
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for your help. What i did in the end was put the labels into a groupbox and assign random locations
List points = new List();
private void Form1_Load(object sender, EventArgs e)
{
foreach (Label label in groupBox1.Controls)
{
points.Add(label.Location);
}
foreach (Label label in groupBox1.Controls)
{
int next = rnd.Next(points.Count);
Point p = points[next];
label.Location = p;
points.Remove(p);
}
modified 11-Feb-15 7:59am.
|
|
|
|
|
|
I use below code to reach the autocomplete in a textbox. But the chance is once, it cannot keep in autocomplete status. When I finish an autocomplete work, and then I cannot key in another autocomplete word. Does somebody know how to let textbox always keep in autocomplete?
private void Form1_Load(object sender, EventArgs e)
{
var source = new AutoCompleteStringCollection();
source.AddRange(new string[]
{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
});
var textBox = new TextBox
{
AutoCompleteCustomSource = source,
AutoCompleteMode =
AutoCompleteMode.SuggestAppend,
AutoCompleteSource =
AutoCompleteSource.CustomSource,
Location = new Point(20, 20),
Width = ClientRectangle.Width - 40,
Visible = true
};
Controls.Add(textBox);
}
modified 10-Feb-15 8:18am.
|
|
|
|
|
I think your problem is that the text isn't highlighted when you go back into the textbox, so any characters you start to type are appended to what is already there - hence auto-complete does not work.
The solution is to highlight all of the text as you enter the textbox: Add this line just before you add textbox to the Controls collection
textBox.Enter += new System.EventHandler(this.textBox_GotFocus);
and add this method to the form
private void textBox_GotFocus(object sender, EventArgs e)
{
((TextBox)sender).SelectAll();
}
Unfortunately when you use the mouse to enter the field the caret is positioned wherever the mouse pointer is so the MouseEnter method doesn't work in quite the same way as we'd like.
To get over that you can use the MouseClick event:
textBox.MouseClick += new System.Windows.Forms.MouseEventHandler(this.textBox_MouseClick); and add this method
private void textBox_MouseClick(object sender, MouseEventArgs e)
{
((TextBox)sender).SelectAll();
}
|
|
|
|
|
Hello CHill60! Thanks your answer. But my problem is that I cannot input the second word with Autocomplete list item. For example, when I input "May Apr", it should be disapeear "May April" for me to select "April". Now it just can work in frist word "May".
|
|
|
|
|
That's because May April is not part of the autocomplete list - you'll either have to ensure that all combinations are in the autocomplete list, or write a user control to do that - I'll have another look
|
|
|
|
|
I am working on repeater I use the check box control in header and tbody i want when i check the header check box the all check boxes which is in body checked some body help me how is possible.
|
|
|
|
|
You just asked the same question yesterday - got some answers too...If those answers are not good for you than add details and ask for more info, but asking the same question over and over again is not a good way to getting answers...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Hi!
I have defined an event in a certain class:
public class BrokenPackageReceivedEventArgs : EventArgs
{
private readonly byte[] package;
public byte[] Package { get { return package; } }
public BrokenPackageReceivedEventArgs(byte[] _package) { package = _package; }
}
public event EventHandler<BrokenPackageReceivedEventArgs> BrokenPackageReceived;
BrokenPackageReceived(this, new BrokenPackageReceivedEventArgs(dataLst.ToArray()));
It seems that if no method is added to the event, it throws a NullReferenceException. I dont want that exception to occur, in fact I am baffled it actually does occur. Is this really the way events always do if no method is attached? Should I just use a try-catch with an empty catch to get rid of it, or am I missing something?
|
|
|
|
|
I just realized I can do like this:
if(BrokenPackageReceived != null)
BrokenPackageReceived(this, new BrokenPackageReceivedEventArgs(dataLst.ToArray()));
Is this the common way to do it?
|
|
|
|