CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Jan 2010
    Posts
    12

    my code is set to a site. how can I have it redirect someone to other site after 10..

    seconds?

    here is my code for the set website:

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

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

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: my code is set to a site. how can I have it redirect someone to other site after

    just change the webBrowser1.Url to the new Url in the timer tick event

  3. #3
    Join Date
    Jan 2010
    Posts
    12

    Re: my code is set to a site. how can I have it redirect someone to other site after

    Do you mean by doing this?

    Code:
            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

  4. #4
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: my code is set to a site. how can I have it redirect someone to other site after

    call the Navigate method.
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  5. #5
    Join Date
    Jan 2010
    Posts
    12

    Re: my code is set to a site. how can I have it redirect someone to other site after

    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
    Code:
    TimeTest.Text = DateTime.Now.ToLongTimeString();

  6. #6
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    Re: my code is set to a site. how can I have it redirect someone to other site after

    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.

  7. #7
    Join Date
    Jan 2010
    Posts
    12

    Re: my code is set to a site. how can I have it redirect someone to other site after

    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?

    Code:
    {
        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"));
            }
    
         }
    }

  8. #8
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    Re: my code is set to a site. how can I have it redirect someone to other site after

    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.

  9. #9
    Join Date
    Jan 2010
    Posts
    12

    Re: my code is set to a site. how can I have it redirect someone to other site after

    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

  10. #10
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: my code is set to a site. how can I have it redirect someone to other site after

    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?
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  11. #11
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    Re: my code is set to a site. how can I have it redirect someone to other site after

    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?

  12. #12
    Join Date
    Jan 2010
    Posts
    12

    Re: my code is set to a site. how can I have it redirect someone to other site after

    sorry I don't know how else to explain this


    this is the entire code

    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)
            {
    
            }
    
         }
    }

  13. #13
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: my code is set to a site. how can I have it redirect someone to other site after

    post the content of the Form1.Designer.cs file too.
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  14. #14
    Join Date
    Jan 2010
    Posts
    12

    Re: my code is set to a site. how can I have it redirect someone to other site after

    Code:
    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;
        }
    }

  15. #15
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: my code is set to a site. how can I have it redirect someone to other site after

    Did you miss the reply where you were told to use the Navigate method?

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

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured