如何知道特定字符串何时在滚动应用程序中显示 [英] How to know when a particular string has displayed in a scrolling application

查看:118
本文介绍了如何知道特定字符串何时在滚动应用程序中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助在我的滚动条应用程序中编写一个逻辑,这将使它更有资源。它的设计与vb.net 2012.该应用程序有2个标签。一个用于滚动内容,另一个用于显示其他内容,如标题。



文本文件包含不同部分的内容。请参阅下面的文本文件示例:



ITD - 05 / MAY / 17 1:20 pm - 从上午10点开始,计算机房中的临时网络停机将用于维护工作


HSE - 01 / MAY / 17 1:20 pm - 安全警告:在步行道进行建筑工程。请不要使用WALKWAY来避免伤害



一般 - 07 / Apr / 17下午2:00 - 公众假期已于2017年10月1日预定



每个句子的开头都有一个独特的短语来标识信息的来源。



滚动条应用程序拉动来自文本文件的信息和file.readalltext方法。请参阅下面的代码



I need help in working out a logic in my scroller application that would make it more resourceful. Its designed with vb.net 2012. The app has 2 labels. One for scrolling contents and the other to display something else like a header.

The text file has contents for different sections. See text file sample below:

ITD - 05/MAY/17 1:20pm - THERE WILL BE TEMPORARY NETWORK OUTAGE IN COMPUTER ROOM FROM 10AM FOR MAINTENANCE WORK

HSE - 01/MAY/17 1:20pm - SAFETY ALERT: ONGOING CONSTRUCTION WORK AT THE WALKWAY. PLEASE DO NOT USE THE WALKWAY TO AVOID INJURIES

GENERAL - 07/Apr/17 2:00pm - PUBLIC HOLIDAYS HAS BEEN SCHEDULED FOR OCT 1st 2017

A distinctive phrase is placed at the beginning of each sentence to identify the source of the information.

The scroller application pulls information from the text file with the file.readalltext method. See code below

lblScroller.Text = File.ReadAllText(FILE_NAME).Replace(vbCr & vbLf, " ")





然后代码从右到左连续滚动标签中的内容。



我想知道如何检查特定文本或字符串何时滚动显示在标签控件上然后另一个标签也会更改为该部分的名称。



例如,应用程序将检查字符串 HSE 滚动的时间进入显示,另一个标签将变为HSE。然后,用户将知道滚动信息来自HSE。当字符串GENERAL滚入时,标签然后更改为GENERAL,因此用户将知道滚动的信息来自GENERAL。



我尝试过:



我曾经教过为每个部门或部门使用不同的文本文件,但它没有有效工作,因为我不得不使用计时器为不同的流程读取器每个文本文件。但是如果文本文件的内容很大,那么计时器将不允许所有内容在它过去之前完成滚动并触发下一个流读取器。



我尝试使用'contains'方法来检查唯一的短语,它总是返回true,因为streamreader立即将文件的整个内容加载到标签控件中。



如果我能够以编程方式判断短语或单词何时从头开始滚动,那么另一个标签将指示信息的来源。 />


它就像普通的电视台滚动不同部分的新闻一样。 E.g当滚动体育信息时,最左边的标签变为SPORTS。



Then a code scrolls the contents in the label from right to left continuously.

I want to know how to check when a particular text or string scrolls into display on the label control and then the other label would also change to the name of the section.

For example, the app would check when the string HSE scrolls into display, the other label would change to HSE. Users will then know that the information scrolling is from HSE. When the string GENERAL scrolls in, the label then changes to GENERAL so users would know that the information scrolling in is from GENERAL.

What I have tried:

I had taught of using different text files for each section or departments but it didn't work effectively because I had to use timers for different streamreaders for each text files. But if the content of a text file is large then the timer would not allow all the content to finish scrolling before it elapse and triggers the next streamreader.

I have tried using the 'contains' method to check for unique phrase and it always return true because streamreader loads the whole content of the file into the label control at once.

If I could be able to programmatically tell when a phrase or word just scrolls in from the beginning then the other label would indicate the source of the information.

Its like the normal TV Station scrolling news with different sections. E.g When sports information is scrolling in, a label at the far left changes to SPORTS.

推荐答案

我假设你有一个计时器来操作滚动。这样的工作:

I am assuming you have a timer to action the scrolling. Something like this works:
private string[] distinctivePhrases = {"HSE", "GENERAL"};
private void Form1_Load(object sender, EventArgs e)
{
    Scrll = -1;
    tmr = new Timer();
    tmr.Tick += TimerTick;
    tmr.Interval = 200;
    tmr.Start();
}
private void TimerTick(object sender, EventArgs e)
{
    var iLmt = ScrollString.Length - (Scrll++);
    if (iLmt < maxChars) Scrll = 0;

    lblScroller.Text = ScrollString.Substring(Scrll, maxChars);
    foreach (var phrase in distinctivePhrases.Where(phrase => lblScroller.Text.Contains(phrase)))
    {
        lblHeader.Text = phrase;
        break;
    }
}

我建议你更加区别地区分这个独特的短语,例如:带有**的前缀,以便在文本中使用general一词不会触发标题更改。它还使代码更简单地更改标题

I suggest that you demark the distinctive phrase a bit more distinctively e.g. prefix with "**" so that having the word "general" in the text does not trigger a header change. It also makes the code to change the header a little simpler

private void TimerTick(object sender, EventArgs e)
{
    var iLmt = ScrollString.Length - (Scrll++);
    if (iLmt < maxChars) Scrll = 0;

    var scrollText = ScrollString.Substring(Scrll, maxChars);
    lblScroller.Text = scrollText;

    if (!scrollText.StartsWith("**")) return;
    lblHeader.Text = scrollText.Substring(2, 
        scrollText.IndexOf(" ", StringComparison.InvariantCultureIgnoreCase) - 1);
}

注意Substring从元素[2]开始忽略**。

Note the Substring starts at element [2] to ignore the "**".


这篇关于如何知道特定字符串何时在滚动应用程序中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆