Visual CSharp .NET - Ayuda con GDI - mover figuras dentro de un panel

 
Vista:

Ayuda con GDI - mover figuras dentro de un panel

Publicado por IEValdiviaO (1 intervención) el 25/11/2013 07:02:13
Estoy haciendo un programa tipo paint y ya dibuja figuras pero ahora quiere que las figuras que dibuje las pueda mover dentro del panel, aquí dejo el codigo esta por capas, espero y me puedan ayudar, gracias.

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
162
163
164
165
166
167
168
169
170
//Form.cs
public partial class Form1 : Form
{
public const int Sin_Dibujo = 0;
public const int DLinea = 1;
public const int DCirculo = 2;
public const int DCuadrado = 3;
 
int modo;
float xi, yi;
 
public Form1()
{
modo = Sin_Dibujo;
InitializeComponent();
}
 
private void button1_Click(object sender, EventArgs e)
{
modo = DLinea;
}
 
private void button2_Click(object sender, EventArgs e)
{
modo = DCirculo;
}
 
private void button3_Click(object sender, EventArgs e)
{
modo = DCuadrado;
}
 
private void button4_Click(object sender, EventArgs e)
{
 
}
 
private void panel2_MouseUp(object sender, MouseEventArgs e)
{
if (modo == Sin_Dibujo) return;
 
if (modo == DLinea)
{
this.panel2.CreateGraphics().DrawLine(Pens.White, xi, yi, e.X, e.Y);
}
 
if (modo == DCirculo)
{
this.panel2.CreateGraphics().DrawEllipse(Pens.White, xi, yi, e.X, e.Y);
}
 
if (modo == DCuadrado)
{
this.panel2.CreateGraphics().DrawRectangle(Pens.White, xi, yi, e.X, e.Y);
}
}
 
private void panel2_MouseDown(object sender, MouseEventArgs e)
{
if (modo == Sin_Dibujo) return;
 
if (modo == DLinea)
{
xi = e.X;
yi = e.Y;
}
 
if (modo == DCirculo)
{
xi = e.X;
yi = e.Y;
}
 
if (modo == DCuadrado)
{
xi = e.X;
yi = e.Y;
}
}
 
// Figura.cs
public abstract class Figura
{
public float x1
{
get
{
return x1;
}
set
{
x1 = value;
}
}
 
public float y1
{
get
{
return y1;
}
set
{
y1 = value;
}
}
 
public float x2
{
get
{
return x2;
}
set
{
x2 = value;
}
}
 
public float y2
{
get
{
return y2;
}
set
{
y2 = value;
}
}
 
public System.Drawing.Pen Color
{
get
{
throw new System.NotImplementedException();
}
set
{
}
}
public abstract void Dibujar(System.Drawing.Graphics fondo);
}
 
// Circulo.cs
class Circulo:Figura
{
public override void Dibujar(System.Drawing.Graphics fondo)
{
fondo.DrawEllipse(Color, x1, y1, x2, y2);
}
}
 
// Cuadrado.cs
class Cuadrado:Figura
{
public override void Dibujar(System.Drawing.Graphics fondo)
{
fondo.DrawRectangle(Color, x1, y1, x2, y2);
}
}
 
// Linea.cs
class Linea:Figura
{
public override void Dibujar(System.Drawing.Graphics fondo)
{
fondo.DrawLine(Color, x1, y1, x2, y2);
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder