Creating a web browser...

Hi everyone! I'm making a web browser but I don't want 'webbrowser2' to be created on the form untill I click a button...

I tryed:

private void button5_Click(object sender, EventArgs e)

{

WebBrowser webbrowser2 = new WebBrowser();

webbrowser2.Height = 250;

webbrowser2.Width = 279;

}

But it dosn't seem to be working (and i don't know how to set the location). Can someone please help me out!

THANKS!



Answer this question

Creating a web browser...

  • Petr Melichar

    Thanks for the help!
  • GarbageCollector

    I'm not sure. the best way to find out is to create one in the forms designer, and then look at hte code in InitializeComponent which creates the item. If you copy this code, you can't go wrong.



  • pvphuc

    Yeah... I noticed that when I looked at the 'Form1.designer' file... but I'm lazy so I just copied the code from there...
  • Roberto Jiménez

    I just made a webbrowser in the forms designer... where is the InitialiseComponent code
  • Roman Uvarov

    Yeah, in VC#2005 you can define a class across multiple .cs files, and the designer does this to seperate your code from the code it generates.

    Good luck !!



  • Upender R. Sandadi

    There's also left and top properties you need to set. An easier way would be to let it be created, but set it as not Visible ( visible = false ) and then make it visible when you want to see it.



  • RafOv

    The only thing I could find that has the text InitialiseComponent is in the code for form1:

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Text;

    using System.Windows.Forms;

    using fixmistakes;

    namespace WindowsApplication1

    {

    public partial class Form1 : Form

    {

    public Form1()

    {

    InitializeComponent(); //OVER HERE!

    }


  • Arthur_Saprykin

    I think I found it (it was hiding)...

    It is in the 'Form1.designer' file.


  • Pushkar Modi

    hi,

    you forgot to add the component on the fly to the form controls so it will not be displaied,

    private void button5_Click(object sender, EventArgs e)

    {

    WebBrowser webbrowser2 = new WebBrowser();

    webbrowser2.Height = 250;

    webbrowser2.Width = 279;

    //you have forgot to add those 2 lines

    webbrowser2.Location = new Point(20, 20);

    this.Controls.Add(webbrowser2);

    }

    also you can add the control to the form and to hide it by useing visible property and when you click on the button to show it

    in the form load event handler

    webbrowser2.visible = False;

    and in button click event handler

    webbrowser2.visible = true;

     

    hope that helps



  • shakey slidewell

    Right click on that and choose 'jump to definition' and it will take you to the code in another partial class.



  • Chester D. Tester

    Search your project, it's hidden in a 'compiler generated code' block, or something like that. If you're using VS2005, it's in a different file from the one you generally edit.



  • SKK*

    Can the left and top properties be used instead of location

    I can't just make it not visible because i'm trying to stop the 'Connect to...' box from coming up (if they are offline) untill the user wants to access the web through my web browser (by pressing the button).


  • Creating a web browser...