0% found this document useful (0 votes)
53 views3 pages

Comparticion de Objetos Clase: Clspto

This document contains code for two Windows Forms applications that share data between forms by passing object references. The ClsPto class defines a point with x and y coordinates. Form1 stores an array of ClsPto objects, allows the user to add new points via a button click which saves to the array, and exposes getter methods to return point coordinates. Form2 instantiates Form1, retrieves point data from Form1's getter methods on a button click to display in labels, allowing the two forms to share point data through the shared ClsPto objects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views3 pages

Comparticion de Objetos Clase: Clspto

This document contains code for two Windows Forms applications that share data between forms by passing object references. The ClsPto class defines a point with x and y coordinates. Form1 stores an array of ClsPto objects, allows the user to add new points via a button click which saves to the array, and exposes getter methods to return point coordinates. Form2 instantiates Form1, retrieves point data from Form1's getter methods on a button click to display in labels, allowing the two forms to share point data through the shared ClsPto objects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 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)


{

}
}
}

You might also like