Just recently began tinkering with Awesomium, it's very cool and much better than the stock webBrowser for WinForms.
However, when I use the _LoadingFrameComplete method to determine if the page has loaded, it seems to be firing 10+ times (when used on Facebook, 2 times when navigating to google.com)
I am trying to get the comparable method of webBrowser1_DocumentCompleted (which only fires one time, after the document has completed).
Is this a 'me' problem, or am I using the wrong methods to check whether the website has finished loading completely.
I'm using Visual C# 2010 Edition
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Debugging_Problems
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string searchURL = textBox1.Text;
webControl1.Source = new Uri(searchURL);
}
private void Awesomium_Windows_Forms_WebControl_LoadingFrameComplete(object sender, Awesomium.Core.FrameEventArgs e)
{
richTextBox1.AppendText("Completed.\n");
}
}
}
You need to use IsMainFrame
private void Awesomium_Windows_Forms_WebControl_LoadingFrameComplete(object sender, Awesomium.Core.FrameEventArgs e)
{
if (e.IsMainFrame)
{
richTextBox1.AppendText("Completed.\n");
}
}
Try putting if(e.IsMainFrame) { .... } inside your LoadingFrameComplete event handler and only put your code in there. – Jon
That was the answer. Thank you.
Related
This question already has answers here:
Process.Start to open an URL, getting an Exception?
(4 answers)
Closed 1 year ago.
I am very interested in C# winforms. I decided to make it open a browser window once I click on a link label with the default browser. I searched on the internet and found the following code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GUI
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
try
{
VisitLink();
}
catch (Exception ex)
{
MessageBox.Show("Unable to open link that was clicked.");
}
}
private void VisitLink()
{
// Change the color of the link text by setting LinkVisited
// to true.
linkLabel1.LinkVisited = true;
//Call the Process.Start method to open the default browser
//with a URL:
System.Diagnostics.Process.Start("http://www.microsoft.com");
}
}
}
When I tried it in my code, I clicked on the link but nothing shows up. Not even an exception pops up, which made me confused. Can anyone help me? Thanks!
The link is correctly marked as visited after the click ? If not, the event is probably not even got fired. Check if you correctly add the callback on the click event
I want to create a simple database viewer using Microsoft Visual Studio and GMaps.NET which can (1) do a specific search and update the list, (2) export the list as KML, and (3) upload the KML file to be viewed in the embedded gmap. Step 1 is already resolved but I cannot find reference to proceed with steps 2 and 3. Any help will be highly appreciated!
Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GMap.NET;
using GMap.NET.WindowsForms;
using GMap.NET.WindowsForms.Markers;
using GMap.NET.MapProviders;
//if these GMap statements are not enabled, these will have to be typed with the namespaces e.g. GMap.Net.MapProviders.GoogleMap
namespace KDMI_DBViewer_v1._0
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void existingPermitsBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.existingPermitsBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.permits_2016DataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'permits_2016DataSet.ExistingPermits' table. You can move, or remove it, as needed.
this.existingPermitsTableAdapter.Fill(this.permits_2016DataSet.ExistingPermits);
}
private void gMapControl1_Load(object sender, EventArgs e)
{
gMapControl1.MapProvider = GMapProviders.GoogleTerrainMap;
//gMapControl1.ShowCenter = false; if enabled, this will remove the red cross
gMapControl1.Position = new PointLatLng(12.0725555, 122.895494);
gMapControl1.DragButton = MouseButtons.Left;
gMapControl1.Zoom = 5;
gMapControl1.MinZoom = 5;
gMapControl1.MaxZoom = 12;
}
private void specificSearchToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.existingPermitsTableAdapter.SpecificSearch(this.permits_2016DataSet.ExistingPermits, provinceToolStripTextBox.Text, municipalityToolStripTextBox.Text, typeToolStripTextBox.Text);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
Unfortunetly, no KML parser yet implemented as the creator of GMap.Net said gmap.net issues.
But instead you can create the import \ export KML\KMZ methods yourself using a library called SharpKML
SharpKML is an implementation of the Open Geospatial Consortium (OGC)
KML 2.2 standard developed in C#, able to read/write both KML files
and KMZ files.
Getting Started:
The easiest way to use the library is to install the SharpKml.Core
NuGet package, however, you can also download the binaries/source code
from this project page.
I created a form with just 2 textboxes and a button. In the first one I type a temperature in Fahrenheit and when I press the button "Convert", the program calculates and puts the temperature in Celsius in the other TextBox. It's working fine.
Now I want the program to clear the second TextBox when I start typing in the first TextBox. Below I show just a part of the code, which didn't work. Can anybody help me?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Conv_Temp
{
public partial class Frm_Principal : Form
{
public Frm_Principal()
{
InitializeComponent();
}
public event EventHandler Leave;
private void Tb_Temp_Leave(object sender, EventArgs e)
{
MessageBox.Show("Leaving TB Tb_Temp");
Tb_Result.Text="";
}
}
}
I think you are almost there.
Try adding this under InitializeComponent();
this.Tb_Temp.TextChanged += new System.EventHandler(this.Tb_Temp_Leave);
Add new Event handler in your form designer code.
this.textBox1.TextChanged += new System.EventHandler(this.ModifyTextBox1);
and implement this event in above form.cs file(Form_Principal )
private void ModifyTextBox1(object sender, EventArgs e)
{
textBox2.Text = String.Empty;
}
Please follow good convention for writing codes this is just a demo.
I am currently trying to make my mp3 player for a project.
I have written this code by following a guide:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string[] files, path;
[STAThread]
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
files = openFileDialog1.SafeFileNames;
path = openFileDialog1.FileNames;
for (int i = 0; i < files.Length; i++)
{
listBox1.Items.Add(files[i]);
}
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = path[listBox1.SelectedIndex];
}
}
}
And heres a screen of my form:
For some reason when I click the OPEN button, nothing happens. First when I used this code I got an error about "Form1_load", but since I wasn't using this, I just deleted the error line and then there was no errors found.
I am very clueless, so anyone with ANY idea what is wrong?
I followed this guide completely:
http://www.c-sharpcorner.com/UploadFile/8ea152/mp3-media-player-in-C-Sharp-4-0/
Thanks
First of all make sure that you have assigned click event for your button for that just double click on your button from design window if it redirects you to the buttonclick method then everything is fine and if it does not then assign it first. For that
public Form1()
{
InitializeComponent();
button1.Click += button1_Click;
}
And
Why do you require [STAThread] here? I mean just remove the attribute and try again because [STAThread] is used for below reson:-
The STAThreadAttribute marks a thread to use the Single-Threaded COM
Apartment if COM is needed. By default, .NET won't initialize COM at
all. It's only when COM is needed, like when a COM object or COM
Control is created or when drag 'n' drop is needed, that COM is
initialized. When that happens, .NET calls the underlying
CoInitializeEx function, which takes a flag indicating whether to join
the thread to a multi-threaded or single-threaded apartment.
For more information :-
http://blogs.msdn.com/b/jfoscoding/archive/2005/04/07/406341.aspx
New to C# from vb.net and I am just making some mock bound applications for now. I have problems with the following code. If I pic an image and exit the application, there is no change. Even if I move a row. However if I upload an image, move to another row, then add another image. After exiting the application the first image will be there but not the second.
In short I have to attempt to upload to another record before the record I actually want updating will do so.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace DBUserManagement
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'dsUsers.Users' table. You can move, or remove it, as needed.
this.usersTableAdapter.Fill(this.dsUsers.Users);
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (DialogResult.OK == ofd.ShowDialog())
{
imgUser.SizeMode = PictureBoxSizeMode.StretchImage;
imgUser.Image = new Bitmap(ofd.OpenFile());
//update bound field.
usersTableAdapter.Update(dsUsers);
}
}
}
}
Any ideas on what I am missing or not understand correctly? Any help appreciated.
/P
The answer was I needed to call the BindingSource's .EndEdit(); method.
So I am guessing it was down to the binding source still having hold of something.
Seems like I'm on the right track anyhow, I looked up the details on MSDN :)