Timer控件,通过txtbox赋值无效的问题.

geminizane 2010-05-08 03:10:44

细节问题请看图,
如图所示,我是想通过txtbox1获取输入的链接,点击button1跳转到web,同时,通过txtbox2获取timer的自动刷新的时间.
但是,我直接在timer控件的属性里边设置,就可以,当然,不敢设置太少,不然因为没有输入url而程序异常.....这个还不会弄.
但是现在我这样写,我觉得好像没错,参照MSDN上的例子,貌似也是这样的,但是为什么我运行之后,输入了时间,页面不自动刷新呢?
谢谢.我是新手,有些问题可能有些可笑,但是难得想要认真学习一回...给我点帮助吧,像上图的system.uri都是自己找的,但是timer控件的问题木有找到.
谢谢.
...全文
226 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
geminizane 2010-05-08
  • 打赏
  • 举报
回复
感谢诸位的帮助,通过一晚上的问人和股沟百毒,终于弄好了....全部代码奉上,同时散分...目前来看是可以运行的.....

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;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Text = "启动时间" + DateTime.Now.ToString();
}

private void button1_Click(object sender, EventArgs e)
{
string geturl = textBox1.Text.Trim().ToLower();
if (geturl == null || geturl == "")
{
MessageBox.Show("总得给我个网址我才知道你要去哪吧...");
}
else
{
this.webBrowser1.Url = new System.Uri("http://" + geturl);
}
}

private void timer1_Tick(object sender, EventArgs e)
{
Text ="上次刷新时间"+DateTime.Now.ToString();
string geturl1 = textBox1.Text;
this.webBrowser1.Url = new System.Uri("http://" + geturl1);
}

private void textBox2_TextChanged(object sender, EventArgs e)
{
try
{
string txtime = textBox2.Text;
if (txtime == null || txtime == "")
{
button1.Enabled = false;
return;
}
else
{
if (!string.IsNullOrEmpty(txtime))
{
int itime = Convert.ToInt32(txtime);
if (itime >= 1)
{
button1.Enabled = true;
timer1.Enabled = true;
timer1.Interval = itime * 60000;
}
}
else
{
timer1.Enabled = false;
}
}
}
catch
{
MessageBox.Show("别用非数字来玩我啊...");
}

}
}
}
geminizane 2010-05-08
  • 打赏
  • 举报
回复
-,-杯具..弄了一下午了....
我就是想,通过timer控件事件webbro控件按照设定好的时间不停的刷新的功能..........
结果还是没弄明白....
geminizane 2010-05-08
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 zenghd 的回复:]
C# code

测试
private void timer1_Tick(object sender, EventArgs e)
{
Text = DateTime.Now.ToString();
//这句代码让标题栏有了日期和时间.好神奇.又会了一招,谢谢哈...
}

private void textBox1_TextChanged(object sender, E……
[/Quote]

用了您的代码,还是不会刷新-,-
现在的全部代码如下

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;

namespace WindowsFormsApplication10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string geturl = textBox1.Text;
webBrowser1.Url=new System.Uri("http://"+geturl);
}

private void timer1_Tick(object sender, EventArgs e)
{

//button1.PerformClick();
//string txttime = textBox2.Text;
//if (txttime != null)
//{
// int sxtime = int.Parse(txttime);
// if (sxtime > 10)
// {
// this.timer1.Enabled = true;
// this.timer1.Interval = sxtime;
// this.timer1.Start();
// }
//}
//else
//{
// this.timer1.Enabled = false;
// this.timer1.Stop();
//}
Text = DateTime.Now.ToString();
}

private void textBox2_TextChanged(object sender, EventArgs e)
{
string txttime = textBox2.Text;
if (string.IsNullOrEmpty(txttime))
{
return;
}
int iTime = Convert.ToInt32(textBox2.Text);
if (iTime > 0)
{
timer1.Enabled = true;
timer1.Interval = iTime;
}
else
{
timer1.Enabled = false;
}
}
}
}
ZengHD 2010-05-08
  • 打赏
  • 举报
回复

测试
private void timer1_Tick(object sender, EventArgs e)
{
Text = DateTime.Now.ToString();
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txttime))
{
return;
}

int iTime = Convert.ToInt32(textBox1.Text);
if (iTime > 0)
{
timer1.Enabled = true;
timer1.Interval = iTime;
}
else
timer1.Enabled = false;
}
geminizane 2010-05-08
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 zenghd 的回复:]
Timer还有Click啊
[/Quote]
#8L的朋友,谢谢你,但是...timer没有chick事件吧....只有timer1_Tick这个-,-但是我也加进去了,貌似还是没反应...
[Quote=引用 12 楼 mngzilin 的回复:]
timer1.Start()
[/Quote]
这个代码中,按照#3的朋友的代码改过了,但是-.-还是不刷新..
我真笨...
mngzilin 2010-05-08
  • 打赏
  • 举报
回复
private void timer1_Tick(object sender, EventArgs e)
{
button1.PerformClick();
}
mngzilin 2010-05-08
  • 打赏
  • 举报
回复
timer1.Start()
ZengHD 2010-05-08
  • 打赏
  • 举报
回复
Timer还有Click啊
geminizane 2010-05-08
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 assky124 的回复:]
Timer1.Click事件中

C# code

Timer1_Click(sender,e)
{
//Url转向函数
//你的应该是Button1_Click(),控件的名称最好改下,时间长了都不知道是什么了
button_Click(this.Button1,new EventArg());
}
[/Quote]

嘿嘿,这不是周末,在公司无聊,先看看自己昨晚上掌握的东西怎么样,还是打草稿嘛~还没正式开始弄呢.
geminizane 2010-05-08
  • 打赏
  • 举报
回复

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;

namespace WindowsFormsApplication10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string geturl = textBox1.Text;
webBrowser1.Url=new System.Uri("http://"+geturl);
}

private void textBox2_TextChanged(object sender, EventArgs e)
{
string txttime = textBox2.Text;
if (txttime != null)
{
int sxtime = int.Parse(txttime);
if (sxtime > 100)
{
this.timer1.Enabled = true;
this.timer1.Interval =sxtime;
this.timer1.Start();
}
}
else
{
this.timer1.Enabled = false;
this.timer1.Stop();
}
}
}
}

这是刚刚按照#3的朋友的代码改的,还没运行...
刚刚运行了,运行通过...但是貌似还是不会刷新-.-杯具...
assky124 2010-05-08
  • 打赏
  • 举报
回复
Timer1.Click事件中

Timer1_Click(sender,e)
{
//Url转向函数
//你的应该是Button1_Click(),控件的名称最好改下,时间长了都不知道是什么了
button_Click(this.Button1,new EventArg());
}
sxmonsy 2010-05-08
  • 打赏
  • 举报
回复
代码贴全看下。
ZengHD 2010-05-08
  • 打赏
  • 举报
回复
timer1里进行了什么操作?
geminizane 2010-05-08
  • 打赏
  • 举报
回复
我下断之后,txttime是可以收到值的...首先在txttime!=null的时候,下断,=true了,
再在timer1.Interval = Convert.ToInt32(txttime);下断,也传进来了值...
结果杯具的事,还是不刷新...
是不是我事件弄错了...是要timer的时间,但是我也加进去了试过了...还是不刷新...
ZengHD 2010-05-08
  • 打赏
  • 举报
回复

没有问题啊
if (string.IsNullOrEmpty(txttime))
{
}
assky124 2010-05-08
  • 打赏
  • 举报
回复
txtBox2的 Change事件中加个判断。


txB2_TextChanged()
{
string str= _txtBox2.Text;
if(!string.IsNullOrEmpty(str))
{
int interval = int.Parse(str);
if(interval > 100) //加个条件,不然程序输入1的时候直接卡死
{
this.timer1.Interval = interval;
this.timer1.Start();
}
}
else
{
this.timer1.Stop();
}
}
b87936260 2010-05-08
  • 打赏
  • 举报
回复
断点调试,看txttime的值,我怀疑是空的
geminizane 2010-05-08
  • 打赏
  • 举报
回复
顺便说下,因为贴图的原因,txtbox2控件被遮挡了,点击之后可以看大图-,-

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧