incorrect window location, size & position (with .NET 2.0 beta2)

L

Lloyd Dupont

I have a Form initialized like that:
//--
public DragingForm()
{
SetStyle(ControlStyles.Opaque, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.ContainerControl, false);
SetStyle(ControlStyles.Selectable, false);
SetStyle(ControlStyles.StandardClick, false);
SetStyle(ControlStyles.StandardDoubleClick, false);
SetStyle(ControlStyles.UserMouse, false);
SetStyle(ControlStyles.SupportsTransparentBackColor, false);
SetStyle(ControlStyles.CacheText, false);

TopMost = true;
ShowInTaskbar = false;
FormBorderStyle = FormBorderStyle.None;
Opacity = 0.6;
Size = new Size(100, 20);
}
//--

When I want to display it I call the following:
//--
public void StartTracking(Control c)
{
TakeSnapshot(c, new Rectangle(0, 0, c.Width, c.Height));
CreateControl();
MoveToMouse();
SetBoundsCore(0, 0, c.Width, c.Height, BoundsSpecified.Size);
Show();
tracking = true;
//Size = c.Size;
//Tracking = true;
}
public void MoveToMouse()
{
Location = new Point(Control.MousePosition.X + offsetX, Control.MousePosition.Y + offsetY);
}
//--

However, for some reason, it always start with its DefaultSize in location {100, 100}
How could this be?
How could I ensure it is at the desired location with the desired size?

On a final note, it's displayed in a MouseMoved event handler, maybe that has some side effect?
 
P

Phil Wright

You need to set the StartPosition property of your Form in the constructor...

this.StartPosition = FormStartPosition.Manual;

....otherwise the Form will ignore your defined position and auto calculate it.

Phil Wright
Follow my C# microISV startup at...
http://componentfactory.blogspot.com
I have a Form initialized like that:
//--
public DragingForm()
{
SetStyle(ControlStyles.Opaque, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.ContainerControl, false);
SetStyle(ControlStyles.Selectable, false);
SetStyle(ControlStyles.StandardClick, false);
SetStyle(ControlStyles.StandardDoubleClick, false);
SetStyle(ControlStyles.UserMouse, false);
SetStyle(ControlStyles.SupportsTransparentBackColor, false);
SetStyle(ControlStyles.CacheText, false);

TopMost = true;
ShowInTaskbar = false;
FormBorderStyle = FormBorderStyle.None;
Opacity = 0.6;
Size = new Size(100, 20);
}
//--

When I want to display it I call the following:
//--
public void StartTracking(Control c)
{
TakeSnapshot(c, new Rectangle(0, 0, c.Width, c.Height));
CreateControl();
MoveToMouse();
SetBoundsCore(0, 0, c.Width, c.Height, BoundsSpecified.Size);
Show();
tracking = true;
//Size = c.Size;
//Tracking = true;
}
public void MoveToMouse()
{
Location = new Point(Control.MousePosition.X + offsetX, Control.MousePosition.Y + offsetY);
}
//--

However, for some reason, it always start with its DefaultSize in location {100, 100}
How could this be?
How could I ensure it is at the desired location with the desired size?

On a final note, it's displayed in a MouseMoved event handler, maybe that has some side effect?
 
L

Lloyd Dupont

Hey that looks like it!
thanks Phil!

Tricky one...
You need to set the StartPosition property of your Form in the constructor...

this.StartPosition = FormStartPosition.Manual;

...otherwise the Form will ignore your defined position and auto calculate it.

Phil Wright
Follow my C# microISV startup at...
http://componentfactory.blogspot.com
I have a Form initialized like that:
//--
public DragingForm()
{
SetStyle(ControlStyles.Opaque, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.ContainerControl, false);
SetStyle(ControlStyles.Selectable, false);
SetStyle(ControlStyles.StandardClick, false);
SetStyle(ControlStyles.StandardDoubleClick, false);
SetStyle(ControlStyles.UserMouse, false);
SetStyle(ControlStyles.SupportsTransparentBackColor, false);
SetStyle(ControlStyles.CacheText, false);

TopMost = true;
ShowInTaskbar = false;
FormBorderStyle = FormBorderStyle.None;
Opacity = 0.6;
Size = new Size(100, 20);
}
//--

When I want to display it I call the following:
//--
public void StartTracking(Control c)
{
TakeSnapshot(c, new Rectangle(0, 0, c.Width, c.Height));
CreateControl();
MoveToMouse();
SetBoundsCore(0, 0, c.Width, c.Height, BoundsSpecified.Size);
Show();
tracking = true;
//Size = c.Size;
//Tracking = true;
}
public void MoveToMouse()
{
Location = new Point(Control.MousePosition.X + offsetX, Control.MousePosition.Y + offsetY);
}
//--

However, for some reason, it always start with its DefaultSize in location {100, 100}
How could this be?
How could I ensure it is at the desired location with the desired size?

On a final note, it's displayed in a MouseMoved event handler, maybe that has some side effect?
 
Top