1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
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 Papillon
{
public partial class frmExo3 : Form
{
int hsens;
int vsens;
bool Ouvert;
int Xpos;
int Ypos;
int Xmax;
int Ymax;
int haut;
int bas;
int gauche;
int droite;
int LocX;
int LocY;
public frmExo3()
{
InitializeComponent();
timPapillon.Start();
hsens = 1;
vsens = -1;
}
private void frmExo3_Load(object sender, EventArgs e)
{
}
private void timPapillon_Tick(object sender, EventArgs e)
{
Xpos = pictPapillon.Location.X;
Ypos = pictPapillon.Location.Y;
Xmax = quitter.Left-pictPapillon.Width;
Ymax = ClientSize.Height-pictPapillon.Height;
if (Xpos >= Xmax)
{
hsens = -1;
System.Threading.Thread.Sleep(100);
}
else if (Xpos <= 0)
{
hsens = 1;
System.Threading.Thread.Sleep(100);
}
if (Ypos <= 0)
{
vsens = 1;
System.Threading.Thread.Sleep(100);
}
else if (Ypos >= Ymax)
{
vsens = -1;
System.Threading.Thread.Sleep(100);
}
LocX = Xpos + trackBar1.Value * hsens;
LocY = Ypos + trackBar1.Value * vsens;
if (LocX < 0)
{
LocX = 0;
}
else if (LocX > Xmax)
{
LocX = Xmax;
}
if (LocY < 0)
{
LocY = 0;
}
else if (LocY > Ymax)
{
LocY = Ymax;
}
pictPapillon.Location = new Point(LocX, LocY);
if (hsens>0 && vsens<0)
{
if (Ouvert)
{
this.pictPapillon.Image = Image.FromFile(".../papGDBH.bmp");
}
else
{
this.pictPapillon.Image = Image.FromFile(".../papfermeGDBH.bmp");
}
}
else if (hsens>0 && vsens>0)
{
if (Ouvert)
{
this.pictPapillon.Image = Image.FromFile(".../papGDHB.bmp");
}
else
{
this.pictPapillon.Image = Image.FromFile(".../papfermeGDHB.bmp");
}
}
else if (hsens<0 && vsens>0)
{
if (Ouvert)
{
this.pictPapillon.Image = Image.FromFile(".../papDGHB.bmp");
}
else
{
this.pictPapillon.Image = Image.FromFile(".../papfermeDGHB.bmp");
}
}
else if (hsens<0 && vsens<0)
{
if (Ouvert)
{
this.pictPapillon.Image = Image.FromFile(".../papDGBH.bmp");
}
else
{
this.pictPapillon.Image = Image.FromFile(".../papfermeDGBH.bmp");
}
}
Ouvert = !Ouvert;
}
private void quitter_Click(object sender, EventArgs e)
{
Environment.Exit(1);
}
}
} |
Partager