我怎样才能调用Eventhandler [英] How Can I Call Eventhandler

查看:194
本文介绍了我怎样才能调用Eventhandler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有一个eventHandlar我将从If条件中调用它



if a have an eventHandlar shall i call it from If condition

if (instance.NavigateError += new SHDocVw.DWebBrowserEvents2_NavigateErrorEventHandler(instance_NavigateError))





但是它无法正常工作,实际上我是否需要得到回复是否接听?



如果你有帮助请帮忙任何其他想法。









but its not working, actually i need to get response whether its calling or not?

please help if u have any other idea.



private void button6_Click(object sender, EventArgs e)
        {

            

            SHDocVw.WebBrowser instance = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;
            webBrowser1.Navigate("http://www.g4ogle.com/");
            

            instance.NavigateError += new SHDocVw.DWebBrowserEvents2_NavigateErrorEventHandler(instance_NavigateError);
            string asj = instance.StatusBar.GetType().ToString();
         
           
            
            
        }
        void instance_NavigateError(object pDisp, ref object URL, ref object Frame, ref object StatusCode, ref bool Cancel)
        {

            string filename = textBox1.Text;

            string fileName = filename.Substring(0, filename.LastIndexOf((".")));
            fileName += ".txt";
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            //  string asg = Ret[0].ToString();
            int name = Convert.ToInt32(StatusCode);
            //ret1.Add("----" + "The URL '" + url + "' is Not valid.");
            // MessageBox.Show("error on page");

            Ret.Add("----" + "The URL '" + URL + "' is Not valid.");
            //File.AppendAllLines(fileName, Ret);
            MessageBox.Show("Completed......", "Info Box", MessageBoxButtons.OK, MessageBoxIcon.Information);



        }

推荐答案

不,你不这样做。



测试事件处理程序添加的值没有意义:它永远不会是假的,因为它不返回bool值。它没有返回任何价值!所以你得到的是一个关于无法将void转换为bool的编译器错误...



并且你没有调用事件处理程序 - 你举起事件来回应一些刺激,通常是某种用户输入,系统调用为你注册的所有事件处理方法。



我认为你对什么事件感到有点困惑 - 也许最好回顾一下你的讲义并在尝试跳入代码之前多想一想!
No, you don't do that.

There is no point in testing the value of a event handler addition: it will never be false because it does not return a bool value. It doesn't return any value! So all you will get is a compiler error about not being able to convert a void to a bool...

And you don't "call" event handlers - you raise the event in response to some stimuli, usually a user input of some kind, and the system calls all the event handler methods that are registered for that event for you.

I think that you are a little confused as to what events are - perhaps it would be a good idea to read back through your lecture notes and think about it a little more before you try leaping into code!


如果在调用事件处理程序时需要发生某些事情,请将其包含在事件处理程序中。



如果要调用事件处理程序关于相关事件是否被提出的问题,你可以这样做,就像你会调用其他方法一样。
If you need something to happen whenever the event handler is called, then include it in the event handler.

If you want to call the event handler regardles of whether the related event is raised or not, you can do that like you would call every other method.


这篇关于我怎样才能调用Eventhandler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆