Оценить:
 Рейтинг: 0

Справочник Жаркова по проектированию и программированию искусственного интеллекта. Том 1: Программирование на Visual C# искусственного интеллекта

<< 1 2 3 4 5 6 7 8 9 ... 13 >>
На страницу:
5 из 13
Настройки чтения
Размер шрифта
Высота строк
Поля

Появляется файл Form1.cs с автоматически сгенерированным шаблоном метода, выше которого объявляем булеву переменную, а в шаблон записываем такой код.

Листинг 2.3. Код для создания анимации. Вариант 1.

//We declare the Boolean myText variable and appropriate it

//«false» (by default too «false»):

bool myText = false;

private void timer1_Tick (object sender, EventArgs e)

{

//We set the alternation of «Calculator» and

//" Calculator with animation»:

if (myText == false)

{

this. Text = " Calculator»;

//We change the myText value to opposite:

myText = true; //or so: myText =! myText;

}

else

{

this. Text = " Calculator with animation»;

//We change the myText value to opposite:

myText = false; //or so: myText =! myText;

}

}

В этом коде использовано правило переноса текста с одной строки на другую.

Теперь изучим второй вариант, когда анимация выполняется безостановочно столько, сколько выполняется наше приложение, но анимационный объект изменяется не за каждый интервал времени Interval, а через заданное нами число интервалов N_Interval. Для этого в файле Form1.cs выше того же (что и в предыдущем варианте) автоматически сгенерированного шаблона метода объявляем переменные, а в шаблон записываем код, как показано на следующем листинге.

Листинг 2.4. Код для создания анимации. Вариант 2.

//We declare the counter of number of intervals

//and set its initial value:

private int counter = 0; //by default too it is equal to 0.

//We declare and set the number N_Interval of intervals,

//after which one text is replaced by another:

private int N_Interval = 3;

private void timer1_Tick (object sender, EventArgs e)

{

//We check, value of the counter

//equally or yet is not present to number N_Interval of

//intervals,

//after which one text is replaced by another:

if (counter> = N_Interval)

{

//If value of the counter collected and is equal

//N_Interval, we output other text:

this. Text = «Calculator»;

//We nullify the value of the counter again:

counter = 0;

}

else

{

//If value of the counter did not collect yet

//and N_Interval is not equal,

//that we output the first text:
<< 1 2 3 4 5 6 7 8 9 ... 13 >>
На страницу:
5 из 13