|
Use NotePad
What type of documentation are you referring to? I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Something like :
Tools--->analyze---->Documenter in ACCESS Database modified on Saturday, March 13, 2010 1:06 PM
|
|
|
|
|
|
I got conversion from lat/long to georef(x and y coordinates) in this site itself. But did not get from lat/long to mils...
|
|
|
|
|
You already posted question and this one is still linked to that post, so post there.
|
|
|
|
|
I'm having trouble figuring this out. I want to move around a form using mouse coordinates, much like a tooltip moves with the cursor. In other words I want the form to maintain a fixed relative position to the cursor. Any help would be much appreciated.
|
|
|
|
|
That is eazy.
Use MouseMove event and calculate the difrance betwen previous saved position and current mouse position. After that, handle Form.Location in orther to change position.
|
|
|
|
|
I had thought I could do something like this but I just get a flickering mess?
void Form1_MouseMove(object sender, MouseEventArgs e)
{
this.Location = new Point(e.X, e.Y);
}
|
|
|
|
|
The problem with this code is, that Location is screen based cordinate and e.x, e.y are client based cordinates.
it gees like this:
private int x;
private int y;
private bool first = true;
void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (first)
{
x=e.X;
y=e.Y;
return;
}
int aX = x-e.X;
int aY = y-e.Y;
this.Location = new Point(this.Location.X-aX, this.Location.Y-aY);
x = e.X;
y = e.Y;
}
for flickering issue try setting Double Buffer.
this.SetStyle(
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer, true);
ps: I am coding from memory without actualy testing for errors
|
|
|
|
|
Thanks, but is it possible to move the form with the cursor when its not over the form? Woulkd it be easier if I was moving a child form within the area of a parent form, and how would I communication the mousemove events to the child form?
|
|
|
|
|
|
Thank you very much for your help. Here is the completed working code.
private int x;
private int y;
private int aX;
private int aY;
[DllImport("user32.dll")]
static extern bool GetCursorPos(ref Point lpPoint);
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
Point pt = new Point();
GetCursorPos(ref pt);
if (aX != pt.X || aY != pt.Y)
{
aX = (pt.X - x);
aY = (pt.Y - y);
this.Location = new Point(pt.X - aX, pt.Y - aY);
}
x = pt.X;
y = pt.Y;
}
modified on Saturday, March 13, 2010 2:38 PM
|
|
|
|
|
|
So his entire problem comes down to one line of code:
Location = System.Windows.Forms.Control.MousePosition;
That's cruel, Luc! He's been at this for days
(and before anyone says anything, yes, you need to use the original offset, and yes, you need to know if you are supposed to move the form, and yes, yada yada yada)You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
So you and I and everyone else have given him the opportunity to learn a lot, not just a single line of code.
|
|
|
|
|
Actually just a few hours if you look at the time stamps
|
|
|
|
|
Not sure he took the opportunity though.
|
|
|
|
|
private int x;
private int y;
private int aX;
private int aY;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
Point pt = PointToClient(Control.MousePosition));
if (aX != pt.X || aY != pt.Y)
{
aX = (pt.X - x);
aY = (pt.Y - y);
this.Location = new Point(pt.X - aX, pt.Y - aY);
}
x = pt.X;
y = pt.Y;
}
If you do something like this you get a nasty oscillating effect. I'm not sure why?
|
|
|
|
|
you have a twisted mind.
Check the documentation: both Control.MousePosition and Form.Location use screen coordinates (unless your Form isn't a TopMost one).
Now check again what Griff showed you.
|
|
|
|
|
Only a little twisted! I've only been at this for a couple of months so there is still time! However, I tried the one line approach and this certainly is not correct:
private void timer1_Tick(object sender, EventArgs e)
{
this.Location = PointToClient(Control.MousePosition);
}
You get an oscillating set of windows. I would appreciate knowing how you would do it?
|
|
|
|
|
For a window on the desktop it would be
window.Location=Control.MousePosition;
and for a moving Control held in some container Control it is
movingControl.Location=containingControl.PointToClient(Control.MousePosition);
as Control.PointToClient[^] translates screen coordinates to coordinates relative to the Control.
BTW: if you apply your (or my) logic to just one object, there is no way it could oscillate. And generally it is wise to test new techniques on one object only, until it works satisfactorily; this helps observation and understanding of what is going on.
|
|
|
|
|
Thank's that very informative.
|
|
|
|
|
really? all PointToClient does is subtract the screen location of the containing Control. I admit MSDN could have made that clearer (as usual), but if you think about it, it can't be doing anything else. So pick the right sucker before calling PointToClient.
Homework: how does a container figure out its screen location?
|
|
|
|
|
|
Yes, that is the method that does it if you feed it (0,0), but the question really is how does it do so? what is inside?
|
|
|
|