Но я только недавно начал изучать c#.По практике в техникуме нужно сделать Пинг Понг. Хочу чтобы при достижении определенного кол-ва очков, выходила другая форм в которой было написано, какой игрок победил. Но не могу передать данные из переменных form1 в wpfresult(это form2). Выходит: Ошибка CS1061 "Form" не содержит определения "w1", и не удалось найти доступный метод расширения "w1", принимающий тип "Form" в качестве первого аргумента (возможно, пропущена директива using или ссылка на сборку) То что погуглил почему-то не работает.
Form1
using System;
using System.Windows.Forms;
namespace PingPong
{
public partial class Form1 : Form
{
int speedx;
int speedy;
int w1;
int w2;
public Form1()
{
InitializeComponent();
speedx = 4;
speedy = 4;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
int x = pong1.Left;
if (e.KeyCode == Keys.D)
{
pong1.Left += 20;
}
if (e.KeyCode == Keys.A)
{
pong1.Left += -20;
}
if (e.KeyCode == Keys.Right)
{
pong2.Left += 20;
}
if (e.KeyCode == Keys.Left)
{
pong2.Left += -20;
}
if (x < 0)
{
pong1.Left = 0;
}
if (x > 470)
{
pong1.Left = 469;
}
int x1 = pong2.Left;
if (x1 < 0)
{
pong2.Left = 0;
}
if (x1 > 470)
{
pong2.Left = 469;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
pong3.Left = pong3.Left + speedx;
pong3.Top = pong3.Top + speedy;
if (pong3.Top <= 0)
{
speedy = -speedy;
}
if (pong3.Left <= 0)
{
speedx = -speedx;
}
if (pong3.Left >= 530)
{
speedx = -speedx;
}
if (pong3.Top >= 465)
{
speedy = -speedy;
}
if ((pong3.Left + pong3.Width >= pong1.Left) & (pong3.Left <= pong1.Left + pong1.Width) & (pong1.Top + pong1.Height >= pong3.Top))
{
speedy = -speedy;
}
if ((pong3.Left + pong3.Width >= pong2.Left) & (pong3.Left <= pong2.Left + pong2.Width) & (pong3.Top + pong3.Height >= pong2.Top))
{
speedy = -speedy;
}
if (pong3.Top < 0)
{
label2.Text = Convert.ToString(Convert.ToInt32(label2.Text) + 1);
w2 = int.Parse(label2.Text);
}
if (pong3.Top > 464)
{
label1.Text = Convert.ToString(Convert.ToInt32(label1.Text) + 1);
w1 = int.Parse(label1.Text);
}
}
}
}
Form2
using System.Windows.Forms;
namespace PingPong
{
public partial class wpfresult : Form
{
public wpfresult()
{
Form Form1 = new Form1();
InitializeComponent();
if (Form1.w1)
{
}
}
}
}