Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# WinForm - HTML Browser

Status
Not open for further replies.

annethorne

Programmer
Apr 13, 2005
28
US
Hi,

I am using Syncfusion.Windows.Forms.HTMLUI.HTMLUIControl() to open a specific url in an html browser. The documentation gives me an example that does work; however, I want to modify it so that the url is automatically displayed when the winform is rendered.

Here is what works (NOTE: The ... indicates code that I have not shown here, for brevity's sake):



...
#region Windows Form Designer generated code
...
private void InitializeComponent()
{
...
this.textBox1.Text = "...
}
...

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if( ( ( int )e.KeyChar ) == 13 )
{
LoadDocument( textBox1.Text );
}
}

private void LoadDocument( string path )
{
if( path == null )
throw new ArgumentNullException( "path" );

if( path.Length == 0 )
throw new ArgumentException( "path - string can not be empty" );

try
{
Uri uri = new Uri( path );
htmluiControl1.LoadHTML( uri );
}
catch( Exception )
{
ShowError();
}
}
...


Again, what I want, is to have the url automatically loaded when the winform is rendered and eliminate the textbox and the need for the user to press the enter key.

Thank you in advance for any help you can give me.
Anne
 
Declare the uri string as member of the form:
Code:
	private string m_defaulturi="[URL unfurl="true"]http://www.google.com";[/URL]
Add in the Form contsructor after calling InitializeComponent();
Code:
	this.textBox1.Text = m_defaulturi;
	LoadDocument(m_defaulturi);
Do not remove the textBox1_KeyPress() since it will be called when the user types in textBox1 another path.
obislavu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top