I have a page which contains a Windows Forms UserControl and several
DIVs within a table. When the mouse is moved over the UserControl,
it ends up calling the following Javascript:
function Map_mouseMoved()
{
var map = document.getElementById("Map"); // the UserControl
var msg = document.getElementById("Msgbox"); // a DIV
if(map != null)
{
if (msg != null)
{
msg.innerHTML = map.getMessgage();
}
window.status = map.getMessage();
}
}
The getMessage() function returns a string which indicates the mouse
position. What I see when I run it is, when I move the mouse over the
control the text gets written to the status bar every time the mouse
moves by a pixel (OK), but the message DIV only changes when the mouse
enters or leaves the control. I know this function is being called,
so how can I force the browser to refresh the DIV?
The strange thing is, this precise same Javscript worked fine with
a Java applet performing the same task as the UserControl!
Thanks a lot,
Julian
bruce barker - 19 May 2004 17:53 GMT
the div will not update until the next DoEvents loop is called (as the div
update is queued as a windows message). your control could do this after
firing an event.
-- bruce (sqlwork.com)
> I have a page which contains a Windows Forms UserControl and several
> DIVs within a table. When the mouse is moved over the UserControl,
[quoted text clipped - 28 lines]
>
> Julian
Julian Hayward - 27 May 2004 12:15 GMT
I had a try, putting the following in my control:
protected override void OnMouseMove(MouseEventArgs e)
{
// Internal stuff that updates the control
foo(e.X, e.Y);
this.Refresh();
// Now fire off an event that javascript can pick up.
if (MapMouseMoved != null)
MapMouseMoved(this, e);
// This should get my DIV updated?
Application.DoEvents();
// don't forget anything in the baseclass handler.
base.OnMouseMove(e);
}
Included in my page is:
<SCRIPT LANGUAGE=javascript FOR=Map EVENT=MapMouseMoved>
<!--
Map_mouseMoved();
//-->
</SCRIPT>
and this function gets called - this is what updates the DIV. But no joy,
it still doesn't update while the mouse is moved over the control. Is this
what you meant, or have I missed something?
Thanks,
Julian
bruce barker - 27 May 2004 20:08 GMT
move Application.DoEvents(); to the end of the function (so its called after
the base calless the javascript routine).
-- bruce (sqlwork.com)
> I had a try, putting the following in my control:
>
[quoted text clipped - 27 lines]
>
> Julian
Julian Hayward - 01 Jun 2004 09:18 GMT
> move Application.DoEvents(); to the end of the function (so its called after
> the base calless the javascript routine).
Tried that, sadly it made no difference. I'm really confused now!
Julian