ОПИ5
.docxМіністерство освіти і науки України
Запорізький національний технічний університет
кафедра програмних засобів
ЗВІТ
з лабораторної роботи № 5
з дисципліни «Основи програмної інженерії» на тему:
«ОБРОБКА ПОДІЙ МИЩІ»
Виконав:
студент групи КНТ-423 Білевський В.В.
Прийняли: Є.М. Федорченко
2014
5.1 Мета: Навчитися основним принципам обробки подій маніпулятора в середовищі Visual Studio
5.2 Завдання до роботи:
5.2.1 Реалізувати кнопку чуттєву до руху мищі. При її наведенні вона повинна рухатися в бік протилежний, або будь який інший бік, від курсору.
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();
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
Random rnd = new Random();
Point tmp_location;
int _w = System.Windows.Forms.SystemInformation.PrimaryMonitorSize.Width;
int _h = System.Windows.Forms.SystemInformation.PrimaryMonitorSize.Height;
int t = (int)trackBar1.Value;
if (e.X > 145-t && e.X < 210+t && e.Y > 38-t/2 && e.Y < 61+t/2)
{
tmp_location = this.Location;
tmp_location.X += rnd.Next(-100, 100);
tmp_location.Y += rnd.Next(-100, 100);
if (tmp_location.X < 0 || tmp_location.X > (_w - this.Width / 2) || tmp_location.Y < 0 || tmp_location.Y > (_h - this.Height / 2))
{
tmp_location.X = _w / 2;
tmp_location.Y = _h / 2;
}
this.Location = tmp_location;
}
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("You win!");
}
}
}
Рисунок 5.1-Перша програма.
5.2.2 Реалізувіти програму де певний елемент управління можна переміщувати запомогою мищі у певні 4 області форми.
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 WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
Point a = pictureBox1.Location;
a.X = 0;
a.Y = 0;
pictureBox1.Location = a;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
Point a = pictureBox1.Location;
a.X = 208;
a.Y = 0;
pictureBox1.Location = a;
}
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
Point a = pictureBox1.Location;
a.X = 208;
a.Y = 190;
pictureBox1.Location = a;
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
Point a = pictureBox1.Location;
a.X = 0;
a.Y = 190;
pictureBox1.Location = a;
}
}
}
Рисунок 5.2- Друга програма.
5.2.3 Реалізувати обробку подій потрійного натискання кнопки мищі.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
Timer timer1 = new Timer();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Interval = 400;
timer1.Tick += new EventHandler(Tick);
}
public void Tick(object sender, EventArgs e)
{
timer1.Enabled = false;
}
private int counts = 0;
private void button1_MouseClick_1(object sender, MouseEventArgs e)
{
if (!timer1.Enabled)
{
timer1.Enabled = true;
timer1.Start();
counts = 1;
}
else
{
counts++;
if (counts >= 3)
{
label1.ForeColor = ColorTranslator.FromHtml("#00FF00");
label1.Text = "HELLO WORLD!";
}
}
}
}
}
Рисунок 5.4-Третя програма
Висновок: Я навчився основним принципам обробки подій маніпулятора в середовищі Visual Studio