Setting a Windows Form position manually....

C

Cip

Hi, I am trying to open a new form immediately below a custom TextBox
control. (To simulate a type of drop-down list).

Anyways, this is how I am defining the new form:

(Me refers to the custom TextBox control)

_frm.TopMost = True
_frm.FormBorderStyle = FormBorderStyle.None
_frm.Size = New Size(150, 100)
_frm.StartPosition = FormStartPosition.Manual
_frm.Location = New Point(Me.PointToScreen(Me.Location))


Now when users click on the TextBox I have:
_frm.show()


For some reason _frm shows up in completely random places and I cannot
figure out what is going on. Sometimes lodged in the top left corner
of my screen, sometimes in the bottom... nowhere close to where it is
supposed to be.

Any help?
 
J

Jeff Gaines

Hi, I am trying to open a new form immediately below a custom TextBox
control. (To simulate a type of drop-down list).

Anyways, this is how I am defining the new form:

(Me refers to the custom TextBox control)

_frm.TopMost = True
_frm.FormBorderStyle = FormBorderStyle.None
_frm.Size = New Size(150, 100)
_frm.StartPosition = FormStartPosition.Manual
_frm.Location = New Point(Me.PointToScreen(Me.Location))


Now when users click on the TextBox I have:
_frm.show()


For some reason _frm shows up in completely random places and I cannot
figure out what is going on. Sometimes lodged in the top left corner
of my screen, sometimes in the bottom... nowhere close to where it is
supposed to be.

Any help?

I am doing something similar with a button and the following
works:

private void btnMenu_Click(object sender, EventArgs e)
{
Point p = new Point(panControl.ClientRectangle.Left,
panControl.ClientRectangle.Bottom);
ctxColour.Show(panControl, p);
}

i.e. it uses ClientRectangle for positioning.

I also have a note:

Sometimes you need a double whammy:

Point pt = new Point(MousePosition.X, MousePosition.Y);
pt = this.PointToClient(pt);
pt = this.PointToScreen(pt);
JFunc.JShowContextMenu(m_JFilerCtl.Handle, lvid.Folder,
lvid.IDList, pt, ref JFilerCtl.JFilerCtl.m_IContextMenu2);

There must be a scientific way of doing it but I usually end up
playing with PointToClient and PointToScreen until it works!
 
S

Saurabh

You can set the form position. During the design time, in the prooerties,
set the StartPosition to manual. I guess it might be currently set as
windows default position.

HTH,

--Saurabh
 
C

Cip

Jeff Gaines said:
I also have a note:

Sometimes you need a double whammy:

Point pt = new Point(MousePosition.X, MousePosition.Y);
pt = this.PointToClient(pt);
pt = this.PointToScreen(pt);
JFunc.JShowContextMenu(m_JFilerCtl.Handle, lvid.Folder,
lvid.IDList, pt, ref JFilerCtl.JFilerCtl.m_IContextMenu2);

There must be a scientific way of doing it but I usually end up
playing with PointToClient and PointToScreen until it works!

hahaha..... i cannot believe it but it worked!
why must I PointToClient and then PointToScreen ??

it makes no sense but no one else was able to help me so I will go
with your 'solution'.

Thanks a lot. :)

If anyone knows what is going on I would appreciate comments.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Living With a Computer 3

Top