Timer刷新问题

AwL_1124 2011-10-10 02:43:57
功能:
用定时器,每隔多少秒刷新path下文件内容到Textbox
VS2010的Windows Froms Application
这是在button1_Click中的方法
 			 //调用刷新方法来定时分析数据
refrushClass^ re = gcnew refrushClass;
path = "c:\\SceneServer.log5696";
re->Main(path);

refrushClass类(与public ref class Form1 : public System::Windows::Forms::Form在同一源码中):

public ref class refrushClass
{
private:
static System::Windows::Forms::Timer^ myTimer = gcnew System::Windows::Forms::Timer;
static int alarmCounter = 1;
static String^ pathRefrush;
static String^ strTotal;
// This is the method to run when the timer is raised.
static void TimerEventProcessor( Object^ /*myObject*/, EventArgs^ /*myEventArgs*/ )
{
myTimer->Stop();
myTimer->Enabled = true;
//读取path文件内容
StreamReader^ sr = File::OpenText(pathRefrush);
try
{
//临时存放每次读取到的文件
String^ s = "";
while (s = sr->ReadLine())
{
strTotal += s;
}
}
finally
{
if (sr)
{
//释放缓存文件
delete (IDisposable^)(sr);
}
}
/*不知道怎么把strTotal传递到指定的textbox中,textbox无法直接在此引用*/
}


public:
static void Main(String^ path)
{
pathRefrush = path;
/* Adds the event and the event handler for the method that will
process the timer event to the timer. */
myTimer->Tick += gcnew EventHandler( TimerEventProcessor );

// Sets the timer interval to 5 seconds.
myTimer->Interval = 5000;
myTimer->Start();

// 调用TimerEventProcessor()方法
while(true)
{
Application::DoEvents();
}
}
};

设计思路:
通过TimerEventProcessor方法来定时读取Path中的内容,但不知道如何传递到textbox控件中
...全文
248 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
strife013 2011-10-10
  • 打赏
  • 举报
回复
另外的线程更新界面,有个textbox1.invoke这样的方法可以使用。
liuwei2500 2011-10-10
  • 打赏
  • 举报
回复
可以使用SetWindowText这个API函数,无论在哪里,你只需要知道句柄就可以设置。
k_sh_y 2011-10-10
  • 打赏
  • 举报
回复
1, 把你的textbox的访问修饰符扩大一下,到你在此能访问
2, 导入windows的SendMessage函数,向textBox发送消息去修改
AwL_1124 2011-10-10
  • 打赏
  • 举报
回复
在Form1里定义的textbox[Quote=引用 1 楼 inzaghi97 的回复:]

textbox 怎么定义的。。。
[/Quote]
AwL_1124 2011-10-10
  • 打赏
  • 举报
回复
refrushClass类(与public ref class Form1 : public System::Windows::Forms::Form在同一源码中):所以无法访问Form1的textbox
[Quote=引用 2 楼 inzaghi97 的回复:]

理论上是在哪都能引用你的textbox,除非出于设计考虑,你不想再那里用
[/Quote]
jijiyuyisheng 2011-10-10
  • 打赏
  • 举报
回复
Kaile 2011-10-10
  • 打赏
  • 举报
回复
这是托管C++吗? 和C#差不多
我要戒烟了 2011-10-10
  • 打赏
  • 举报
回复
理论上是在哪都能引用你的textbox,除非出于设计考虑,你不想再那里用
我要戒烟了 2011-10-10
  • 打赏
  • 举报
回复
textbox 怎么定义的。。。

110,567

社区成员

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

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

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