I'm sorry for yet another stupid question. I am almost finished with my settings saving winform, with many thanks to the people of StackOverflow of course, but I am stuck on one final thing. Please don't mark this down just because I am a beginner.
I am getting the following errors:
An object reference is required for the non-static field, method, or property 'ShovelShovel.WindowSize.Width.get'
An object reference is required for the non-static field, method, or property 'ShovelShovel.WindowSize.Height.get'
Here:
Settings.cs
public partial class Settings : Form
{
public Settings()
{
InitializeComponent();
}
public void button1_Click(object sender, EventArgs e)
{
var windowSize = new WindowSize { Width = WindowSize.Width, Height = WindowSize.Height };
WindowSizeStorage.WriteSettings(windowSize);
Application.Exit();
}
}
Which goes to:
WindowSize.cs
public class WindowSize
{
public int Width { get; set; }
public int Height { get; set; }
}
public static class WindowSizeStorage
{
public static string savePath = "WindowSize.dat";
public static WindowSize ReadSettings()
{
var result = new WindowSize();
using (FileStream fileStream = new FileStream(savePath, FileMode.Open))
{
using (BinaryReader binaryReader = new BinaryReader(fileStream))
{
result.Width = binaryReader.ReadInt32();
result.Height = binaryReader.ReadInt32();
}
}
return result;
}
public static void WriteSettings(WindowSize toSave)
{
using (BinaryWriter binaryWriter = new BinaryWriter(File.Open(savePath, FileMode.Create)))
{
binaryWriter.Write(toSave.Width);
binaryWriter.Write(toSave.Height);
}
}
}
http://forums.codeguru.com/showthread.php?530631-I-m-having-trouble-with-my-code
There you can find the full files of my project in the attachments, in case the above is insufficient.