What's wrong with that code? Webbrowser control doesn't launch

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kimiraikkonen

    #1

    What's wrong with that code? Webbrowser control doesn't launch

    Hello experts,
    That's very very simple question but i wonder if you can help:

    I have form1 and a button which brings user to form2 when button is
    clicked, and i have a web-browser (.net 2.0 component) control placed
    in form2 which is coded to run when form2 is loaded:

    Form1 has only a button brings user to second form, form1 has that
    code:

    private void button1_Click(o bject sender, EventArgs e)
    {
    Form form2 = new Form();

    form2.Show();
    }


    Form2 has that code:

    private void Form2_Load(obje ct sender, EventArgs e)
    {
    this.mybrowser. Navigate("http://www.google.com" );
    }


    But then i run the program, when i go to form2 by clicking "button" in
    form1, form 2 is shown empty as if there's no web-browser control
    such. I'm beginner for C#, and there must be something missing.

    Thanks...

  • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

    #2
    RE: What's wrong with that code? Webbrowser control doesn't launch

    Did you attach the load handler routine to the event in the form2
    constructor? You should have a line like this:

    this.Load += new EventHandler(Fo rm2_Load);

    That's the only thing that I can think of at the moment.


    "kimiraikko nen" wrote:
    Hello experts,
    That's very very simple question but i wonder if you can help:
    >
    I have form1 and a button which brings user to form2 when button is
    clicked, and i have a web-browser (.net 2.0 component) control placed
    in form2 which is coded to run when form2 is loaded:
    >
    Form1 has only a button brings user to second form, form1 has that
    code:
    >
    private void button1_Click(o bject sender, EventArgs e)
    {
    Form form2 = new Form();
    >
    form2.Show();
    }
    >
    >
    Form2 has that code:
    >
    private void Form2_Load(obje ct sender, EventArgs e)
    {
    this.mybrowser. Navigate("http://www.google.com" );
    }
    >
    >
    But then i run the program, when i go to form2 by clicking "button" in
    form1, form 2 is shown empty as if there's no web-browser control
    such. I'm beginner for C#, and there must be something missing.
    >
    Thanks...
    >
    >

    Comment

    • kimiraikkonen

      #3
      Re: What's wrong with that code? Webbrowser control doesn't launch

      On Nov 8, 1:03 am, Family Tree Mike
      <FamilyTreeM... @discussions.mi crosoft.comwrot e:
      Did you attach the load handler routine to the event in the form2
      constructor? You should have a line like this:
      >
      this.Load += new EventHandler(Fo rm2_Load);
      >
      That's the only thing that I can think of at the moment.
      >
      "kimiraikko nen" wrote:
      Hello experts,
      That's very very simple question but i wonder if you can help:
      >
      I have form1 and a button which brings user to form2 when button is
      clicked, and i have a web-browser (.net 2.0 component) control placed
      in form2 which is coded to run when form2 is loaded:
      >
      Form1 has only a button brings user to second form, form1 has that
      code:
      >
      private void button1_Click(o bject sender, EventArgs e)
      {
      Form form2 = new Form();
      >
      form2.Show();
      }
      >
      Form2 has that code:
      >
      private void Form2_Load(obje ct sender, EventArgs e)
      {
      this.mybrowser. Navigate("http://www.google.com" );
      }
      >
      But then i run the program, when i go to form2 by clicking "button" in
      form1, form 2 is shown empty as if there's no web-browser control
      such. I'm beginner for C#, and there must be something missing.
      >
      Thanks...

      put just before this.mybrowser. navigate("www.g oogle.com")

      Do you mean?

      private void Form2_Load(obje ct sender, EventArgs e)
      {
      this.Load += new EventHandler(Fo rm2_Load);
      this.mybrowser. Navigate("http://www.google.com" );
      }

      If so, that didn't help.

      Comment

      • Kalpesh

        #4
        Re: What's wrong with that code? Webbrowser control doesn't launch

        Put the following line, after InitializeCompo nent()
        this.Load += new EventHandler(Fo rm2_Load);

        You are trying to attach an event handler in the event, which will not
        get raised.

        HTH
        Kalpesh




        On Nov 7, 4:26 pm, kimiraikkonen <kimiraikkone.. .@gmail.comwrot e:
        On Nov 8, 1:03 am, Family Tree Mike
        >
        >
        >
        <FamilyTreeM... @discussions.mi crosoft.comwrot e:
        Did you attach the load handler routine to the event in the form2
        constructor? You should have a line like this:
        >
        this.Load += new EventHandler(Fo rm2_Load);
        >
        That's the only thing that I can think of at the moment.
        >
        "kimiraikko nen" wrote:
        Hello experts,
        That's very very simple question but i wonder if you can help:
        >
        I have form1 and a button which brings user to form2 when button is
        clicked, and i have a web-browser (.net 2.0 component) control placed
        in form2 which is coded to run when form2 is loaded:
        >
        Form1 has only a button brings user to second form, form1 has that
        code:
        >
        private void button1_Click(o bject sender, EventArgs e)
        {
        Form form2 = new Form();
        >
        form2.Show();
        }
        >
        Form2 has that code:
        >
        private void Form2_Load(obje ct sender, EventArgs e)
        {
        this.mybrowser. Navigate("http://www.google.com" );
        }
        >
        But then i run the program, when i go to form2 by clicking "button" in
        form1, form 2 is shown empty as if there's no web-browser control
        such. I'm beginner for C#, and there must be something missing.
        >
        Thanks...
        >
        put just before this.mybrowser. navigate("www.g oogle.com")
        >
        Do you mean?
        >
        private void Form2_Load(obje ct sender, EventArgs e)
        {
        this.Load += new EventHandler(Fo rm2_Load);
        this.mybrowser. Navigate("http://www.google.com" );
        }
        >
        If so, that didn't help.

        Comment

        • Peter Duniho

          #5
          Re: What's wrong with that code? Webbrowser control doesn't launch

          On 2007-11-07 17:01:00 -0800, Kalpesh <shahkalpesh@gm ail.comsaid:
          Put the following line, after InitializeCompo nent()
          this.Load += new EventHandler(Fo rm2_Load);
          >
          You are trying to attach an event handler in the event, which will not
          get raised.
          And if it did get raised, each time the event got raised, the handler
          would get added again, causing a geometrically increasing number of
          handler executions for each raising of the event. :)

          As far as subscribing the handler goes, IMHO in the case where the
          handler is subscribed as part of initialization and never unsubscribed,
          you might as well set the handler in the VS Designer rather than
          explicitly writing the code to do so.

          Pete

          Comment

          • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

            #6
            Re: What's wrong with that code? Webbrowser control doesn't launch

            Peter,

            I'm not following where you are suggesting the line goes. I have always put
            it in my constructor after the call to InitializeCompo nent as Kalpesh stated.
            The constructor is only called once.

            Or... I just realized this. Are you addressing where Kimiraikkonen placed
            here add handler code?


            "Peter Duniho" wrote:
            On 2007-11-07 17:01:00 -0800, Kalpesh <shahkalpesh@gm ail.comsaid:
            >
            Put the following line, after InitializeCompo nent()
            this.Load += new EventHandler(Fo rm2_Load);

            You are trying to attach an event handler in the event, which will not
            get raised.
            >
            And if it did get raised, each time the event got raised, the handler
            would get added again, causing a geometrically increasing number of
            handler executions for each raising of the event. :)
            >
            As far as subscribing the handler goes, IMHO in the case where the
            handler is subscribed as part of initialization and never unsubscribed,
            you might as well set the handler in the VS Designer rather than
            explicitly writing the code to do so.
            >
            Pete
            >
            >

            Comment

            • Peter Duniho

              #7
              Re: What's wrong with that code? Webbrowser control doesn't launch

              On 2007-11-07 19:16:00 -0800, Family Tree Mike
              <FamilyTreeMike @discussions.mi crosoft.comsaid :
              Peter,
              >
              I'm not following where you are suggesting the line goes. I have always put
              it in my constructor after the call to InitializeCompo nent as Kalpesh stated.
              The constructor is only called once.
              >
              Or... I just realized this. Are you addressing where Kimiraikkonen placed
              here add handler code?
              My post addresses two different issues:

              1) The consequence of the improperly placed statement subscribing the
              handler, as seen in kimiraikkonen's post.

              2) The question of whether one should write code to subscribe a
              handler at all. For a situation such as this one, the VS Designer
              provides a very easy way to auto-generate the needed code, so why write
              it oneself at all?

              Nothing in my post was suggesting a specific location for the line
              being suggested, other than to agree with Kalpesh's post saying that
              the OP has it in the wrong place. My preference is to avoid the
              question of where the line goes altogether, by having the Designer
              write the line of code instead.

              Pete

              Comment

              • =?Utf-8?B?RmFtaWx5IFRyZWUgTWlrZQ==?=

                #8
                Re: What's wrong with that code? Webbrowser control doesn't launch

                Thanks, now I understand!

                "Peter Duniho" wrote:
                On 2007-11-07 19:16:00 -0800, Family Tree Mike
                <FamilyTreeMike @discussions.mi crosoft.comsaid :
                >
                Peter,

                I'm not following where you are suggesting the line goes. I have always put
                it in my constructor after the call to InitializeCompo nent as Kalpesh stated.
                The constructor is only called once.

                Or... I just realized this. Are you addressing where Kimiraikkonen placed
                here add handler code?
                >
                My post addresses two different issues:
                >
                1) The consequence of the improperly placed statement subscribing the
                handler, as seen in kimiraikkonen's post.
                >
                2) The question of whether one should write code to subscribe a
                handler at all. For a situation such as this one, the VS Designer
                provides a very easy way to auto-generate the needed code, so why write
                it oneself at all?
                >
                Nothing in my post was suggesting a specific location for the line
                being suggested, other than to agree with Kalpesh's post saying that
                the OP has it in the wrong place. My preference is to avoid the
                question of where the line goes altogether, by having the Designer
                write the line of code instead.
                >
                Pete
                >
                >

                Comment

                • kimiraikkonen

                  #9
                  Re: What's wrong with that code? Webbrowser control doesn't launch

                  Hi,
                  Read all the posts but that didn't work neither:

                  public Form2()
                  {
                  InitializeCompo nent();
                  this.Load += new EventHandler(Fo rm2_Load);
                  }

                  private void Form2_Load(obje ct sender, EventArgs e)
                  {

                  this.mybrowser. Navigate("http://www.google.com" );
                  }


                  It's not required to use that code if there's no form1 / even didn't
                  work if form1 exists also.
                  this.Load += new EventHandler(Fo rm2_Load);

                  if i form2 is unique / only and starter form of the project, i mean,
                  if i delete form1, form2's webbrowser function will work but
                  couldn't understand why the problem occurs when you jump from form1 to
                  form2.

                  Comment

                  • Peter Duniho

                    #10
                    Re: What's wrong with that code? Webbrowser control doesn't launch

                    On 2007-11-08 11:55:55 -0800, kimiraikkonen <kimiraikkonen8 5@gmail.comsaid :
                    [...]
                    if i form2 is unique / only and starter form of the project, i mean,
                    if i delete form1, form2's webbrowser function will work but
                    couldn't understand why the problem occurs when you jump from form1 to
                    form2.
                    You know, the bottom line here is that you have not posted nearly a
                    good enough problem description for anyone to really answer your
                    question.

                    You should post a concise-but-complete sample of code that reliably
                    demonstrates your problem. You should also be very specific about what
                    user steps to take when running the code, what the code actually does,
                    and what you expect it to do instead.

                    Pete

                    Comment

                    Working...