What I want to do is pass two variables from a button click event to another class in the same file.
Here is my code:
Settings.cs (Windows Form file)
namespace ShovelShovel
public partial class Settings : Form
{
public Settings()
{
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e)
{
SetWindowSize.SaveData(textBoxWidth.Text, textBoxHeight.Text);
}
}
}
}
SetWindowSize.cs (class file)
namespace ShovelShovel
class SetWindowSize
{
public static void SaveData(string width, string height)
{
using (BinaryWriter binaryWriter = new BinaryWriter(File.Open("file.dat", FileMode.Create)))
{
binaryWriter.Write(width, height);
}
}
}
}
I want Settings.width
and Settings.height
in SetWindowSize.cs to get the text from textBoxWidth
and textBoxHeight
.
I can't change
public void button1_Click(object sender, EventArgs e)
to anything else, since it would break the function of the form, so I don't know what to do.
See Question&Answers more detail:os