Вход/Регистрация
Справочник Жаркова по проектированию и программированию искусственного интеллекта. Том 7: Программирование на Visual C# искусственного интеллекта. Издание 2
вернуться

Жарков Валерий

Шрифт:

Листинг 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:

this.Text = "Calculator with animation";

//We increase value of the counter on 1:

counter = counter + 1;

}

}

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

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

//We declare the counter of number of intervals

//and set its initial value:

private int counter = 0;

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

//after which one text is replaced by another:

private int N_Interval = 3;

//We declare and nullify the i_Interval_Stop counter,

//which calculates the number of intervals

//to an animation stop:

private int i_Interval_Stop = 0;

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

//on reaching which animation stops:

private int N_Interval_Stop = 10;

private void timer1_Tick(object sender, EventArgs e)

{

//Value of the i_Interval_Stop counter,

//which calculates the number of intervals

//to an animation stop, we increase on 1:

i_Interval_Stop = i_Interval_Stop + 1;

//We check the number i_Interval_Stop of intervals,

//on reaching which animation stops:

if (i_Interval_Stop >= N_Interval_Stop)

timer1.Enabled = false;

//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 value of the counter again:

counter = 0;

  • Читать дальше
  • 1
  • ...
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • ...

Ебукер (ebooker) – онлайн-библиотека на русском языке. Книги доступны онлайн, без утомительной регистрации. Огромный выбор и удобный дизайн, позволяющий читать без проблем. Добавляйте сайт в закладки! Все произведения загружаются пользователями: если считаете, что ваши авторские права нарушены – используйте форму обратной связи.

Полезные ссылки

  • Моя полка

Контакты

  • chitat.ebooker@gmail.com

Подпишитесь на рассылку: