Click to See Complete Forum and Search --> : my code is set to a site. how can I have it redirect someone to other site after 10..


SharpGuy
January 6th, 2010, 04:01 PM
seconds?

here is my code for the set website:

private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Url = new Uri ("http://www.microsoft.com");

}


here is my timer:

private void timer1_Tick(object sender, EventArgs e)
{
TimeTest.Text = DateTime.Now.ToLongTimeString();
}

dannystommen
January 7th, 2010, 02:33 AM
just change the webBrowser1.Url to the new Url in the timer tick event

SharpGuy
January 7th, 2010, 07:42 AM
Do you mean by doing this?

private void timer1_Tick(object sender, EventArgs e)
{
TimeTest.Text = DateTime.Now.ToLongTimeString();

webBrowser1.Url = new Uri("http://www.yahoo.com");
}


that doesn't work

memeloo
January 7th, 2010, 07:52 AM
call the Navigate method.

SharpGuy
January 7th, 2010, 08:14 AM
I created a second timer and call the Navigate method in it, but what should I change the timer to, to redirect the site in 10 secs

this is my current timer
TimeTest.Text = DateTime.Now.ToLongTimeString();

mariocatch
January 7th, 2010, 08:23 AM
That's not a timer. That's a text element being set to the current time.

What are you trying to achieve? Person opens web page, after 10 seconds they are redirected to another page? Create a timer, set the tick for 10 seconds, listen for the tick/elapsed event. When it ticks, call the Navigate() method on your webbrowser control and give it the URL you want to navigate to.

SharpGuy
January 7th, 2010, 08:37 AM
when you said set the ticks to 10 seconds, is it something I set in the property or I have to write a code for it?

here is my entire code, what am i not doing?


{
public partial class FormOne : Form
{
public TestOne()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Url = new Uri ("http://www.microsoft.com");

}



private void timer1_Tick(object sender, EventArgs e)
{
TimeTest.Text = DateTime.Now.ToLongTimeString();

}

private void timer2_Tick(object sender, EventArgs e)
{
TimeTest.Text = DateTime.Now.ToLongTimeString();

webBrowser1.Navigate(new Uri("http://www.c-sharpcorner.com"));
}

}
}

mariocatch
January 7th, 2010, 08:58 AM
Where are your timers (timer1, timer2) defined? There is an Interval property, which is the amount of milliseconds in between each Tick event fired. You can set the Interval to 10*1000 (10 seconds), and then when the Tick event is hit, it will call the Navigate() method. Is that what you're trying to achieve.

You'll have to explain yourself better if not.

SharpGuy
January 7th, 2010, 09:12 AM
what I am trying to achieve is, creating a simple software that when it opens, it will have a website that I embed in it open, let's say the website is microsoft.com. then after 10 seconds, the site will get redirect to something else, let's say yahoo.com

so I have create two timers, one to display the current time on my status bar(I want that one like that). and the other timer to be a tick to redirect the website to another.

I went to my property and change the interval to 10*1000, but it says property value is not valid

memeloo
January 7th, 2010, 09:24 AM
I have no idea what you are doing. can you post the whole code? What is this TimeTest? is it a lable, a form, a text box? actually it's not important but why do you use it there at all? where is/are your timer(s) defined and how do you use it/them?

mariocatch
January 7th, 2010, 09:39 AM
What type were you trying to change the Interval (case-sensitive) property off of? The timer? What is the type of your Timer? System.Windows.Forms.Timer? System.Timers.Timer?

SharpGuy
January 7th, 2010, 09:45 AM
sorry I don't know how else to explain this


this is the entire code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WMPLib;
using System.IO;

namespace FormOne
{
public partial class FormOne : Form
{
public TestOne()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Url = new Uri ("http://www.microsoft.com");

}




private void timer1_Tick(object sender, EventArgs e)
{
TimeTest.Text = DateTime.Now.ToLongTimeString();
}

private void timer2_Tick(object sender, EventArgs e)
{

}

}
}

memeloo
January 7th, 2010, 09:49 AM
post the content of the Form1.Designer.cs file too.

SharpGuy
January 7th, 2010, 10:19 AM
namespace FormOne
{
partial class FormOne
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TestOne));
this.Player = new AxWMPLib.AxWindowsMediaPlayer();
this.webBrowser1 = new System.Windows.Forms.WebBrowser();
this.button1 = new System.Windows.Forms.Button();
this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar();
this.toolStripStatusLabel2 = new System.Windows.Forms.ToolStripStatusLabel();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.TimeTest = new System.Windows.Forms.ToolStripStatusLabel();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.timer2 = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.Player)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
// Player
//
this.Player.Enabled = true;
this.Player.Location = new System.Drawing.Point(12, 12);
this.Player.Name = "Player";
this.Player.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("Player.OcxState")));
this.Player.Size = new System.Drawing.Size(309, 264);
this.Player.TabIndex = 0;
//
// webBrowser1
//
this.webBrowser1.Location = new System.Drawing.Point(343, 12);
this.webBrowser1.MinimumSize = new System.Drawing.Size(20, 20);
this.webBrowser1.Name = "webBrowser1";
this.webBrowser1.Size = new System.Drawing.Size(542, 538);
this.webBrowser1.TabIndex = 3;
//
// button1
//
this.button1.Location = new System.Drawing.Point(112, 316);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(102, 29);
this.button1.TabIndex = 4;
this.button1.Text = "upload file";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// toolStripProgressBar1
//
this.toolStripProgressBar1.Name = "toolStripProgressBar1";
this.toolStripProgressBar1.Size = new System.Drawing.Size(100, 16);
//
// toolStripStatusLabel2
//
this.toolStripStatusLabel2.Name = "toolStripStatusLabel2";
this.toolStripStatusLabel2.Size = new System.Drawing.Size(118, 17);
this.toolStripStatusLabel2.Text = "toolStripStatusLabel2";
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.TimeTest});
this.statusStrip1.Location = new System.Drawing.Point(0, 549);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(908, 22);
this.statusStrip1.TabIndex = 5;
this.statusStrip1.Text = "statusStrip1";
//
// TimeTest
//
this.TimeTest.ImageAlign = System.Drawing.ContentAlignment.TopRight;
this.TimeTest.Name = "TimeTest";
this.TimeTest.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.TimeTest.Size = new System.Drawing.Size(139, 17);
this.TimeTest.Text = "@@@@@@@@@@@@";
this.TimeTest.TextAlign = System.Drawing.ContentAlignment.BottomRight;
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// timer2
//
this.timer2.Enabled = true;
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
//
// TestOne
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(908, 571);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.button1);
this.Controls.Add(this.webBrowser1);
this.Controls.Add(this.Player);
this.Name = "TestOne";
this.Text = "TestOne";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.Player)).EndInit();
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private AxWMPLib.AxWindowsMediaPlayer Player;
private System.Windows.Forms.WebBrowser webBrowser1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ToolStripProgressBar toolStripProgressBar1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel2;
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel TimeTest;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Timer timer2;
}
}

Arjay
January 7th, 2010, 10:35 AM
Did you miss the reply where you were told to use the Navigate method?

Btw, are you setting a breakpoint and using the debugger?

mariocatch
January 7th, 2010, 10:59 AM
Both of your timer1 and timer2 have no Interval property setup. And neither are started anywhere.

In your Form's constructor, set timer1.Interval to X and timer2.Interval to Y (in milliseconds).
Then, call timer1.Start() and timer2.Start(). Also, use the Navigate() method off your webbrowser control.