Please use this.Location.X and this.Location.Y
Example:
File: Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PointOnScreen
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void CloseMe(object sender, FormClosingEventArgs e)
{
System.IO.StreamWriter sw = new
System.IO.StreamWriter("C:\\point.txt");
sw.WriteLine(this.Location.X.ToString());
sw.WriteLine(this.Location.Y.ToString());
sw.Close();
}
private void ShowForm(object sender, EventArgs e)
{
try
{
System.IO.StreamReader sr = new
System.IO.StreamReader("C:\\point.txt");
Point p = new Point();
p.X = System.Convert.ToInt32(sr.ReadLine());
p.Y = System.Convert.ToInt32(sr.ReadLine());
sr.Close();
this.Location = p;
} catch { }
}
}
}
File: Form1.Designer.cs
namespace PointOnScreen
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(129, 234);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(296, 269);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Shown += new System.EventHandler(this.ShowForm);
this.FormClosing += new
System.Windows.Forms.FormClosingEventHandler(this.CloseMe);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
}
}
Regards,
Lars-Inge Tønnessen