Preferences Dialog in C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Im creating a Web Browser in Visual C# and I have a preferences dialog. The
current homepage is yahoo.com. The code for the homepage is:

// Go Home - go to the default home page.
WebBrowser thiswebpage = GetCurrentWebBrowser();
thiswebpage.Navigate("http://www.yahoo.com");

On the preferences dialog I have a section to change the homepage. In that
section I have a text box and a button. The Preferences Dialog is a seperate
window. What code should I add to the button so that the homepage changes to
the website I typed in the text box when the button is clicked?

Thank You,

Matt
 
when you create the preferences dialog, pass in a reference to the browser
object where you have the URL property.
WHen the user clicks the button, assign the new URL to this browser object.



--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
Hello,

Thanks for the help but Im just starting and learning to program in Visual
C#. Can you please repeat the instructions in more detail?

Thank You,

Matt
 
huh?

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
Matt,

I think you are after this piece of code

AxWebBrowser.Navigate("about:<html><body
onload=javascript:window.external.addFavorite('" + textbox1.Text +
"')></body></html>")

I hope this helps?

Cor
 
Hi Cor,

No, it's not that. Visual C# underlines many parts of the code red. And it
doesn't work.

Thanks anyways,

Matt
 
OK.

In your main form, create a public method. The idea is that any other part
of the system can call your main form and provide a URL, and your main form
will respond by bringing up that URL in the window.

Also, I've included the code needed to pass the reference to the preferences
form.

public class MainForm : System.Windows.Forms.Form
{
private Form m_preferences = null;

public void SetURL(string myURL)
{
// put code here to cause your browser app to visit the URL and
render

}

public void DisplayPreferencesDialog()
{
m_preferences = new frmPreferences(); // create the preferences
object
m_preferences.BrowserWindow = this;
m_preferences.Show();

}

}

Your preferences window gets one new property and a new method.

public class frmPreferences : System.Windows.Forms.Form
{
private MainForm _browserwindow = null;

public MainForm BrowserWindow
{
set { _browserwindow = value; }
}

// now, call this little method from within your form code to set the
URL on the browser window
private void SetBrowserWindowURL(string URL)
{
_browserwindow.SetURL(URL);
}
}

I hope this helps.
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
Matt,

A little bit copied to fast from VBNet
this.axWebBrowser1.Navigate(@"about:<html><body
onload=javascript:window.external.addFavorite('http://www.Google.com')></body></html>");

I this goes better?

Cor
 
Hi Cor,

Thanks, but just on problem:

Now C# only underlines: axWebBrowser1 with the color blue.

When I build it the error output says:

'WEB.Preferences' does not contain a definition for 'axWebBrowser1'
C:\Documents and Settings\Administrator\Desktop\Web Browser\Preferences.cs.

We're getting closer :)

Thanks,

Matt
 
Hi Cor,

Thanks, but just on problem:

Now C# only underlines: axWebBrowser1 with the color blue.

When I build it the error output says:

Error 1 'WEB.Preferences' does not contain a definition for 'axWebBrowser1'
C:\Documents and Settings\Administrator\Desktop\Web Browser\Preferences.cs.

We're getting closer :)

Thanks,

Matt
 
Matt,

I thought it was a solution, however this is about the favorite window in
IE. So before we are looking for a solution too get it working. Is that what
you are after? I could not find what was the preferences dialog so I thought
it was this one.

Cor
 
Back
Top