Welcome Guest Search | Active Topics | Sign In | Register

Event IsLoadingChanged dont fire Options
Rafael Lucena
Posted: Wednesday, November 5, 2014 11:43:27 AM
Rank: Newbie
Groups: Member

Joined: 11/5/2014
Posts: 8
I create the class..

teste t = new teste();

webv1_IsLoadingChanged is not triggered. What's wrong with that?


class teste
{
EO.WebBrowser.WebView webv1;
public teste()
{
webv1 = new EO.WebBrowser.WebView();
webv1.IsLoadingChanged += new EventHandler(webv1_IsLoadingChanged);
webv1.Url = "www.uol.com.br";
}

void webv1_IsLoadingChanged(object sender, EventArgs e)
{
string test = "loading";
}
}
Rafael Lucena
Posted: Wednesday, November 5, 2014 12:16:55 PM
Rank: Newbie
Groups: Member

Joined: 11/5/2014
Posts: 8
I got a solution, but is not very elegant.
Solution Class test class must inherit System.Windows.Forms.Form


Code: C#
class teste:System.Windows.Forms.Form
    {
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        EO.WebBrowser.WebView webv1;
        EO.WebBrowser.WinForm.WebControl wc = new EO.WebBrowser.WinForm.WebControl();
        public teste()
        {
            InitializeComponent();
            
        }

        void webv1_IsLoadingChanged(object sender, EventArgs e)
        {
            string test = "carregou";
            
        }

        private void InitializeComponent()
        {
            this.wc = new EO.WebBrowser.WinForm.WebControl();
            this.webv1 = new EO.WebBrowser.WebView();
            this.SuspendLayout();
            // 
            // wc
            // 
            this.wc.BackColor = System.Drawing.Color.White;
            this.wc.Location = new System.Drawing.Point(40, 31);
            this.wc.Name = "wc";
            this.wc.Size = new System.Drawing.Size(250, 250);
            this.wc.TabIndex = 0;
            this.wc.Text = "webControl1";
            this.wc.WebView = this.webv1;
            // 
            // webv1
            // 
            this.webv1.AllowDropLoad = true;
            this.webv1.IsLoadingChanged += new System.EventHandler(this.webv1_IsLoadingChanged);
            // 
            // teste
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(457, 389);
            this.Controls.Add(this.wc);
            this.Name = "teste";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.teste_Load);
            this.ResumeLayout(false);

        }

        private void teste_Load(object sender, EventArgs e)
        {
            webv1.Url = "www.uol.com.br";
            webv1.LoadUrl("www.uol.com.br");
        }
    }


Code: C#
teste t = new teste();
t.Show();
t.Visible = false;


OK. event webv1_IsLoadingChanged fired.

Is there another way to make it work? Does anyone know?
Pray
eo_support
Posted: Wednesday, November 5, 2014 12:35:21 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

The key is you need to run a message loop. You usually do not need to worry about it when you use WebView inside a Form since Windows Forms run a message loop for you. If you use WebView in a background thread, you will need to use the ThreadRunner class. The code will be something like this:

Code: C#
//Create a ThreadRunner object
ThreadRunner tr = new ThreadRunner();

//Create a WebView through the ThreadRunner
WebView webView = tr.CreateWebView();
webView.IsLoadingChanged = ....;

//Load the Url and wait for it finish
tr.Send(() =>
{
    webView.LoadUrlAndWait(your_url);
});

//Destroy the WebView and ThreadRunner
webView.Destroy();
tr.Stop();


Please keep in mind that the ThreadRunner creates a worker thread and run the WebView in the worker thread. So your event handler will be called from that thread instead of from your thread. In this case that worker thread is the thread that runs the message loop.

Hope this helps. Please feel free to let us know if you still have any more questions.

Thanks!


Rafael Lucena
Posted: Saturday, November 8, 2014 10:24:12 AM
Rank: Newbie
Groups: Member

Joined: 11/5/2014
Posts: 8
THANKS!!!!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.