Вы находитесь на странице: 1из 3

COMPARTICION DE OBJETOS

CLASE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CompartirObjetos
{
public class ClsPto
{
double x;
double y;
public double px
{
get { return x; }
set { x = value; }
}
public double py
{
get { return y; }
set { y = value; }
}

}
}

FORM1
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 CompartirObjetos
{
public partial class Form1 : Form
{
// anteponer static para conservar valores
static ClsPto [] p = new ClsPto[50];
int IP;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
IP++;
p[IP] = new ClsPto();
p[IP].px = Convert.ToDouble(textBox1.Text);
p[IP].py = Convert.ToDouble(textBox2.Text);

private void button2_Click(object sender, EventArgs e)


{
Form2 frm2 = new Form2();
frm2.Show();

}
public double retpx(int I)
{
if (p[I] == null)
return 0;
else
return p[I].px;
}
public double retpy(int I)
{
if (p[I] == null)
return 0;
else
return p[I].py; }
}
}
FORM1
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 CompartirObjetos
{
public partial class Form2 : Form
{
int IP;
public Form2()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
Form1 frm1=new Form1();
IP++;
label1.Text = Convert.ToString(frm1.retpx(IP));
label2.Text = Convert.ToString(frm1.retpy(IP));
}

private void Form2_Load(object sender, EventArgs e)


{

}
}
}

Вам также может понравиться