By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,200 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

Crazy behaviour!!

P: n/a
Lee
Hi,

I am saving a forms location by getting the x and y coordinates as such;-

this.Location.X.ToString();
this.Location.Y.ToString();

when i again load the form i am using the saved x and y coordinates as
such;-

public void setLocation(int x, int y)
{
Point moveTo = this.PointToScreen(new Point(x, y));
this.Location = moveTo;
}

Now if i close the app and re-start it the form itself moves across and down
the screen a little bit, it does this each time until it eventually goes out
of view (note, i have not manuall moved the form at all).

what could be causing this?

thanks
Mar 20 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Its probably the PointToScreen method.

Mar 20 '06 #2

P: n/a
Lee
how can I tell? or how should it be implemented?

thanks
"Andy" <aj*****@alum.rit.edu> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Its probably the PointToScreen method.

Mar 20 '06 #3

P: n/a
Lee
ok thsi seems to of sorted it;-

public void setLocation(int x, int y)
{
this.Location = new Point(x, y);
}

thanks

"Lee" <le*****@hotmail.com> wrote in message
news:u%***************@TK2MSFTNGP12.phx.gbl...
how can I tell? or how should it be implemented?

thanks
"Andy" <aj*****@alum.rit.edu> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Its probably the PointToScreen method.


Mar 20 '06 #4

P: n/a
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
Mar 20 '06 #5

P: n/a
"Lee" <le*****@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
ok thsi seems to of sorted it;-

public void setLocation(int x, int y)
{
this.Location = new Point(x, y);
}

thanks


You shouldn't really have posted this question, it would be very easy to
work out by debugging.

Michael
Mar 20 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.