[C#] Lokalne varijable
26.12.2009. u 21:56 · pre 204 meseci
#1
Code:
private void slikaPanel_MouseClick(object sender, MouseEventArgs e)
{
int x1, y1;
int x2, y2;
int xElement, yElement;
if (e.Button == MouseButtons.Left && e.Clicks == 1)
{
x1 = e.X;
y1 = e.Y;
slikaPanel.CreateGraphics().FillRectangle(Brushes.Red, x1, y1, 2, 2);
}
if (e.Button == MouseButtons.Left && e.Clicks == 2)
{
x2 = e.X;
y2 = e.Y;
slikaPanel.CreateGraphics().FillRectangle(Brushes.Red, x2, y2, 2, 2);
}
xElement = x2 - x1;
yElement = y2 - y1;
double udaljenostTocaka = Math.Sqrt(Math.Pow(yElement, 2) + Math.Pow(xElement, 2));
}
private void slikaPanel_MouseClick(object sender, MouseEventArgs e)
{
int x1, y1;
int x2, y2;
int xElement, yElement;
if (e.Button == MouseButtons.Left && e.Clicks == 1)
{
x1 = e.X;
y1 = e.Y;
slikaPanel.CreateGraphics().FillRectangle(Brushes.Red, x1, y1, 2, 2);
}
if (e.Button == MouseButtons.Left && e.Clicks == 2)
{
x2 = e.X;
y2 = e.Y;
slikaPanel.CreateGraphics().FillRectangle(Brushes.Red, x2, y2, 2, 2);
}
xElement = x2 - x1;
yElement = y2 - y1;
double udaljenostTocaka = Math.Sqrt(Math.Pow(yElement, 2) + Math.Pow(xElement, 2));
}
Izbacuje grešku Use of unassigned local variable x1,x2,y1,y2.
Znam u čemu je greška ali ne znam kako sada dobiti te varijable "van" da ih mogu koristiti za izračun xElement i yElement.
Potpis
Windows 95 /Win’ dz/: n., 32-bit extensions and a graphical shell for a 16-bit patch to an 8-bit operating system
originally coded for a 4-bit microprocessor, written by a 2-bit company, that can’t stand 1 bit of competition.
originally coded for a 4-bit microprocessor, written by a 2-bit company, that can’t stand 1 bit of competition.