Hello!
I have a problem with the size. I've made a function that saves the size, but each time I start the application does the size get larger then the last time. How do I fix that problem?
Here are the code for the function:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
FileInfo FI1 = new FileInfo("Width.txt");
FileInfo FI2 = new FileInfo("Height.txt");
if (!FI1.Exists)
{
StreamWriter SW = new StreamWriter("Width.txt");
SW.Write(this.Size.Width);
SW.Close();
}
if (!FI2.Exists)
{
StreamWriter SW = new StreamWriter("Height.txt");
SW.Write(this.Size.Height);
SW.Close();
}
StreamReader SR1 = new StreamReader("Width.txt");
StreamReader SR2 = new StreamReader("Height.txt");
TextBox TB1 = new TextBox();
TextBox TB2 = new TextBox();
TB1.Text = SR1.ReadLine();
TB2.Text = SR2.ReadLine();
SR1.Close();
SR2.Close();
this.ClientSize = new Size(Convert.ToInt32(TB1.Text), Convert.ToInt32(TB2.Text));
}
private void Form1_SizeChanged(object sender, EventArgs e)
{
if (this.WindowState != FormWindowState.Maximized)
{
StreamWriter SW1 = new StreamWriter("Width.txt");
StreamWriter SW2 = new StreamWriter("Height.txt");
SW1.Write(this.Size.Width);
SW2.Write(this.Size.Height);
SW1.Close();
SW2.Close();
}
}
}
}