I have implemented a custom control with BeginUpdate/EndUpdate
functionality. The implementation of BeginUpdate basically sends the
WM_SETREDRAW message by P/Invoking SendMessage and setting wparam to 0 and
EndUpdate sends the same message with wparam = -1. When I invoke these
methods on my custom control, I am also getting the MouseMove event. Has
anyone else seen this? Is there a way to prevent the MouseMove event on the
control when BeginUpdate/EndUpdate is called?

Thanks,
Abhishek

RE: BeginUpdate/EndUpdate causing mouse move by v-yiy

v-yiy
Fri Oct 24 00:49:33 CDT 2003

Hi abhishek.
Thanks for your post!
You mean your mousemove event of your control or your form is fired when
you invoke the P/Invoke SendMessage
method?
I made a small program and tried to repro your problem, however I didn't
get any mouse move event on the user control or on the Form when invoking
these two methods.
I pasted my test code after the signature, you may try it on your system.
Probably it will be helpful if you could give me a
small sample project to repro this problem.

Thanks for using MSDN Newsgroup!!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!

<code file="MyUserControl.cs">
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WinForm_BeginEndUpdate_MouseMove
{
/// <summary>
/// Summary description for MyUserControl.
/// </summary>
public class MyUserControl : System.Windows.Forms.UserControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public MyUserControl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitializeComponent call

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Component 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()
{
//
// MyUserControl
//
this.BackColor = System.Drawing.SystemColors.Desktop;
this.Name = "MyUserControl";
this.Size = new System.Drawing.Size(368, 424);

}
#endregion

private class NativeMethods
{
[DllImport("user32.dll")]
private extern static int SendMessage(IntPtr hwnd, uint nMsg,
int wParam, int lParam);
private const int WM_SETREDRAW = 0x000B;
public static void BeginUpdate(IntPtr hwnd)
{
SendMessage(hwnd,WM_SETREDRAW,0,0);
}
public static void EndUpdate(IntPtr hwnd)
{
SendMessage(hwnd,WM_SETREDRAW,-1,0);
}

}


public void BeginUpdate()
{
NativeMethods.BeginUpdate(Handle);
}
public void EndUpdate()
{
NativeMethods.EndUpdate(Handle);
}


protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove (e);
System.Diagnostics.Debug.WriteLine("MouseMove received");
}
public void DoUpdate()
{
Graphics g = CreateGraphics();
g.FillRectangle(Brushes.Indigo,this.Bounds);
g.Dispose();
}
}
}
</code>
<code file="Form1.cs">
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WinForm_BeginEndUpdate_MouseMove
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private WinForm_BeginEndUpdate_MouseMove.MyUserControl myUserControl1;
private System.Timers.Timer timer1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (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.myUserControl1 = new
WinForm_BeginEndUpdate_MouseMove.MyUserControl();
this.timer1 = new System.Timers.Timer();
((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
this.SuspendLayout();
//
// myUserControl1
//
this.myUserControl1.BackColor = System.Drawing.SystemColors.Desktop;
this.myUserControl1.Location = new System.Drawing.Point(72, 64);
this.myUserControl1.Name = "myUserControl1";
this.myUserControl1.Size = new System.Drawing.Size(256, 240);
this.myUserControl1.TabIndex = 2;
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 500;
this.timer1.SynchronizingObject = this;
this.timer1.Elapsed += new
System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(408, 421);
this.Controls.Add(this.myUserControl1);
this.Name = "Form1";
this.Text = "Form1";
this.MouseMove += new
System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
System.Diagnostics.Debug.WriteLine("MainForm MouseMove received");
}

private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs
e)
{
myUserControl1.BeginUpdate();
System.Diagnostics.Debug.WriteLine("BeginUpdate");
myUserControl1.DoUpdate();
myUserControl1.EndUpdate();
System.Diagnostics.Debug.WriteLine("EndUpdate");

}
}
}

</code>





Re: BeginUpdate/EndUpdate causing mouse move by abhishek

abhishek
Fri Oct 24 12:00:39 CDT 2003

Another interesting note...Calling BeingUpdate/EndUpdate on the ListBox
control does not exhibit this behavior. Is there something additional I need
to do, besides sending the message to get the correct behavior (no mouse
move event)?

Thanks,
Abhishek

"abhishek ghuwalewala" <abhishekg.nospam@nospam.mail.com> wrote in message
news:uV%23BF5bmDHA.2592@TK2MSFTNGP10.phx.gbl...
> I have implemented a custom control with BeginUpdate/EndUpdate
> functionality. The implementation of BeginUpdate basically sends the
> WM_SETREDRAW message by P/Invoking SendMessage and setting wparam to 0 and
> EndUpdate sends the same message with wparam = -1. When I invoke these
> methods on my custom control, I am also getting the MouseMove event. Has
> anyone else seen this? Is there a way to prevent the MouseMove event on
the
> control when BeginUpdate/EndUpdate is called?
>
> Thanks,
> Abhishek
>
>



Re: BeginUpdate/EndUpdate causing mouse move by v-yiy

v-yiy
Mon Oct 27 01:25:43 CST 2003

Hi abhishek,
Thanks for your sample, I reproed your problem now.
For now, I haven't found a way to prevent MouseMove method to be called.
However, since BeginUpdate/Endupate is called by yourself, could you add a
boolean flag before actually executing your codes in the MouseMove?
such as
InUpdating = false;
void BeginUpdate()
{
InUpdating = true;
SendMessage ....
}
void EndUpdate()
{
SendMessage() ...
InUpdating = false;
}
void MouseMove( ....)
{
if(!IsUpdating)
{
DoMouseMove();
}
}

Does this work around solve your problem?
Please be free to post on the group, if you still have problem on this
issue.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!

--------------------
| From: "abhishek ghuwalewala" <abhishekg.nospam@nospam.mail.com>
| References: <uV#BF5bmDHA.2592@TK2MSFTNGP10.phx.gbl>
<mWgycKfmDHA.2808@cpmsftngxa06.phx.gbl>
| Subject: Re: BeginUpdate/EndUpdate causing mouse move
| Date: Fri, 24 Oct 2003 11:05:22 -0500
| Lines: 638
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#o2aiikmDHA.372@TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| NNTP-Posting-Host: client-64-158.natinst.com 130.164.64.158
| Path:
cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.
phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:55191
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| Ying-Shen,
|
| Thanks for your prompt reply. I am attaching a small sample project that
| reproduces the problem. The instructions for reproducing the problem are
| described in the application.
|
| Thanks,
| Abhishek
|
| "Ying-Shen Yu[MSFT]" <v-yiy@online.microsoft.com> wrote in message
| news:mWgycKfmDHA.2808@cpmsftngxa06.phx.gbl...
| > Hi abhishek.
| > Thanks for your post!
| > You mean your mousemove event of your control or your form is fired when
| > you invoke the P/Invoke SendMessage
| > method?
| > I made a small program and tried to repro your problem, however I didn't
| > get any mouse move event on the user control or on the Form when
invoking
| > these two methods.
| > I pasted my test code after the signature, you may try it on your
system.
| > Probably it will be helpful if you could give me a
| > small sample project to repro this problem.
| >
| > Thanks for using MSDN Newsgroup!!
| >
| > Best regards,
| >
| > Ying-Shen Yu [MSFT]
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| >
| > This posting is provided "AS IS" with no warranties and confers no
rights.
| > You should not reply this mail directly, "Online" should be removed
before
| > sending, Thanks!
| >
| > <code file="MyUserControl.cs">
| > using System;
| > using System.Collections;
| > using System.ComponentModel;
| > using System.Drawing;
| > using System.Data;
| > using System.Windows.Forms;
| > using System.Runtime.InteropServices;
| >
| > namespace WinForm_BeginEndUpdate_MouseMove
| > {
| > /// <summary>
| > /// Summary description for MyUserControl.
| > /// </summary>
| > public class MyUserControl : System.Windows.Forms.UserControl
| > {
| > /// <summary>
| > /// Required designer variable.
| > /// </summary>
| > private System.ComponentModel.Container components = null;
| >
| > public MyUserControl()
| > {
| > // This call is required by the Windows.Forms Form Designer.
| > InitializeComponent();
| >
| > // TODO: Add any initialization after the InitializeComponent call
| >
| > }
| >
| > /// <summary>
| > /// Clean up any resources being used.
| > /// </summary>
| > protected override void Dispose( bool disposing )
| > {
| > if( disposing )
| > {
| > if(components != null)
| > {
| > components.Dispose();
| > }
| > }
| > base.Dispose( disposing );
| > }
| >
| > #region Component 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()
| > {
| > //
| > // MyUserControl
| > //
| > this.BackColor = System.Drawing.SystemColors.Desktop;
| > this.Name = "MyUserControl";
| > this.Size = new System.Drawing.Size(368, 424);
| >
| > }
| > #endregion
| >
| > private class NativeMethods
| > {
| > [DllImport("user32.dll")]
| > private extern static int SendMessage(IntPtr hwnd, uint nMsg,
| > int wParam, int lParam);
| > private const int WM_SETREDRAW = 0x000B;
| > public static void BeginUpdate(IntPtr hwnd)
| > {
| > SendMessage(hwnd,WM_SETREDRAW,0,0);
| > }
| > public static void EndUpdate(IntPtr hwnd)
| > {
| > SendMessage(hwnd,WM_SETREDRAW,-1,0);
| > }
| >
| > }
| >
| >
| > public void BeginUpdate()
| > {
| > NativeMethods.BeginUpdate(Handle);
| > }
| > public void EndUpdate()
| > {
| > NativeMethods.EndUpdate(Handle);
| > }
| >
| >
| > protected override void OnMouseMove(MouseEventArgs e)
| > {
| > base.OnMouseMove (e);
| > System.Diagnostics.Debug.WriteLine("MouseMove received");
| > }
| > public void DoUpdate()
| > {
| > Graphics g = CreateGraphics();
| > g.FillRectangle(Brushes.Indigo,this.Bounds);
| > g.Dispose();
| > }
| > }
| > }
| > </code>
| > <code file="Form1.cs">
| > using System;
| > using System.Drawing;
| > using System.Collections;
| > using System.ComponentModel;
| > using System.Windows.Forms;
| > using System.Data;
| >
| > namespace WinForm_BeginEndUpdate_MouseMove
| > {
| > /// <summary>
| > /// Summary description for Form1.
| > /// </summary>
| > public class Form1 : System.Windows.Forms.Form
| > {
| > private WinForm_BeginEndUpdate_MouseMove.MyUserControl myUserControl1;
| > private System.Timers.Timer timer1;
| > /// <summary>
| > /// Required designer variable.
| > /// </summary>
| > private System.ComponentModel.Container components = null;
| >
| > public Form1()
| > {
| > //
| > // Required for Windows Form Designer support
| > //
| > InitializeComponent();
| >
| > //
| > // TODO: Add any constructor code after InitializeComponent call
| > //
| > }
| >
| > /// <summary>
| > /// Clean up any resources being used.
| > /// </summary>
| > protected override void Dispose( bool disposing )
| > {
| > if( disposing )
| > {
| > if (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.myUserControl1 = new
| > WinForm_BeginEndUpdate_MouseMove.MyUserControl();
| > this.timer1 = new System.Timers.Timer();
| > ((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
| > this.SuspendLayout();
| > //
| > // myUserControl1
| > //
| > this.myUserControl1.BackColor = System.Drawing.SystemColors.Desktop;
| > this.myUserControl1.Location = new System.Drawing.Point(72, 64);
| > this.myUserControl1.Name = "myUserControl1";
| > this.myUserControl1.Size = new System.Drawing.Size(256, 240);
| > this.myUserControl1.TabIndex = 2;
| > //
| > // timer1
| > //
| > this.timer1.Enabled = true;
| > this.timer1.Interval = 500;
| > this.timer1.SynchronizingObject = this;
| > this.timer1.Elapsed += new
| > System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
| > //
| > // Form1
| > //
| > this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
| > this.ClientSize = new System.Drawing.Size(408, 421);
| > this.Controls.Add(this.myUserControl1);
| > this.Name = "Form1";
| > this.Text = "Form1";
| > this.MouseMove += new
| > System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
| > ((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
| > this.ResumeLayout(false);
| >
| > }
| > #endregion
| >
| > /// <summary>
| > /// The main entry point for the application.
| > /// </summary>
| > [STAThread]
| > static void Main()
| > {
| > Application.Run(new Form1());
| > }
| >
| > private void Form1_MouseMove(object sender,
| > System.Windows.Forms.MouseEventArgs e)
| > {
| > System.Diagnostics.Debug.WriteLine("MainForm MouseMove received");
| > }
| >
| > private void timer1_Elapsed(object sender,
System.Timers.ElapsedEventArgs
| > e)
| > {
| > myUserControl1.BeginUpdate();
| > System.Diagnostics.Debug.WriteLine("BeginUpdate");
| > myUserControl1.DoUpdate();
| > myUserControl1.EndUpdate();
| > System.Diagnostics.Debug.WriteLine("EndUpdate");
| >
| > }
| > }
| > }
| >
| > </code>
| >
| >
| >
| >
|
|
|


Re: BeginUpdate/EndUpdate causing mouse move by abhishek

abhishek
Mon Oct 27 09:49:23 CST 2003

I had thought of that work-around. The problem is that it is more of a hack
than anything else. I would prefer a "cleaner" solution to the problem. But,
if one does not exist, then I will have to make do with the hack. Since you
are confirming this as a bug, do you know when this might be fixed?

Thanks,
Abhishek

"Ying-Shen Yu[MSFT]" <v-yiy@online.microsoft.com> wrote in message
news:Km%23qNuFnDHA.2624@cpmsftngxa06.phx.gbl...
> Hi abhishek,
> Thanks for your sample, I reproed your problem now.
> For now, I haven't found a way to prevent MouseMove method to be called.
> However, since BeginUpdate/Endupate is called by yourself, could you add a
> boolean flag before actually executing your codes in the MouseMove?
> such as
> InUpdating = false;
> void BeginUpdate()
> {
> InUpdating = true;
> SendMessage ....
> }
> void EndUpdate()
> {
> SendMessage() ...
> InUpdating = false;
> }
> void MouseMove( ....)
> {
> if(!IsUpdating)
> {
> DoMouseMove();
> }
> }
>
> Does this work around solve your problem?
> Please be free to post on the group, if you still have problem on this
> issue.
> Thanks!
>
> Best regards,
>
> Ying-Shen Yu [MSFT]
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
>
> This posting is provided "AS IS" with no warranties and confers no rights.
> You should not reply this mail directly, "Online" should be removed before
> sending, Thanks!
>
> --------------------
> | From: "abhishek ghuwalewala" <abhishekg.nospam@nospam.mail.com>
> | References: <uV#BF5bmDHA.2592@TK2MSFTNGP10.phx.gbl>
> <mWgycKfmDHA.2808@cpmsftngxa06.phx.gbl>
> | Subject: Re: BeginUpdate/EndUpdate causing mouse move
> | Date: Fri, 24 Oct 2003 11:05:22 -0500
> | Lines: 638
> | X-Priority: 3
> | X-MSMail-Priority: Normal
> | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
> | Message-ID: <#o2aiikmDHA.372@TK2MSFTNGP11.phx.gbl>
> | Newsgroups: microsoft.public.dotnet.framework.windowsforms
> | NNTP-Posting-Host: client-64-158.natinst.com 130.164.64.158
> | Path:
>
cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.
> phx.gbl
> | Xref: cpmsftngxa06.phx.gbl
> microsoft.public.dotnet.framework.windowsforms:55191
> | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
> |
> | Ying-Shen,
> |
> | Thanks for your prompt reply. I am attaching a small sample project that
> | reproduces the problem. The instructions for reproducing the problem are
> | described in the application.
> |
> | Thanks,
> | Abhishek
> |
> | "Ying-Shen Yu[MSFT]" <v-yiy@online.microsoft.com> wrote in message
> | news:mWgycKfmDHA.2808@cpmsftngxa06.phx.gbl...
> | > Hi abhishek.
> | > Thanks for your post!
> | > You mean your mousemove event of your control or your form is fired
when
> | > you invoke the P/Invoke SendMessage
> | > method?
> | > I made a small program and tried to repro your problem, however I
didn't
> | > get any mouse move event on the user control or on the Form when
> invoking
> | > these two methods.
> | > I pasted my test code after the signature, you may try it on your
> system.
> | > Probably it will be helpful if you could give me a
> | > small sample project to repro this problem.
> | >
> | > Thanks for using MSDN Newsgroup!!
> | >
> | > Best regards,
> | >
> | > Ying-Shen Yu [MSFT]
> | > Microsoft Online Partner Support
> | > Get Secure! - www.microsoft.com/security
> | >
> | > This posting is provided "AS IS" with no warranties and confers no
> rights.
> | > You should not reply this mail directly, "Online" should be removed
> before
> | > sending, Thanks!
> | >
> | > <code file="MyUserControl.cs">
> | > using System;
> | > using System.Collections;
> | > using System.ComponentModel;
> | > using System.Drawing;
> | > using System.Data;
> | > using System.Windows.Forms;
> | > using System.Runtime.InteropServices;
> | >
> | > namespace WinForm_BeginEndUpdate_MouseMove
> | > {
> | > /// <summary>
> | > /// Summary description for MyUserControl.
> | > /// </summary>
> | > public class MyUserControl : System.Windows.Forms.UserControl
> | > {
> | > /// <summary>
> | > /// Required designer variable.
> | > /// </summary>
> | > private System.ComponentModel.Container components = null;
> | >
> | > public MyUserControl()
> | > {
> | > // This call is required by the Windows.Forms Form Designer.
> | > InitializeComponent();
> | >
> | > // TODO: Add any initialization after the InitializeComponent call
> | >
> | > }
> | >
> | > /// <summary>
> | > /// Clean up any resources being used.
> | > /// </summary>
> | > protected override void Dispose( bool disposing )
> | > {
> | > if( disposing )
> | > {
> | > if(components != null)
> | > {
> | > components.Dispose();
> | > }
> | > }
> | > base.Dispose( disposing );
> | > }
> | >
> | > #region Component 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()
> | > {
> | > //
> | > // MyUserControl
> | > //
> | > this.BackColor = System.Drawing.SystemColors.Desktop;
> | > this.Name = "MyUserControl";
> | > this.Size = new System.Drawing.Size(368, 424);
> | >
> | > }
> | > #endregion
> | >
> | > private class NativeMethods
> | > {
> | > [DllImport("user32.dll")]
> | > private extern static int SendMessage(IntPtr hwnd, uint nMsg,
> | > int wParam, int lParam);
> | > private const int WM_SETREDRAW = 0x000B;
> | > public static void BeginUpdate(IntPtr hwnd)
> | > {
> | > SendMessage(hwnd,WM_SETREDRAW,0,0);
> | > }
> | > public static void EndUpdate(IntPtr hwnd)
> | > {
> | > SendMessage(hwnd,WM_SETREDRAW,-1,0);
> | > }
> | >
> | > }
> | >
> | >
> | > public void BeginUpdate()
> | > {
> | > NativeMethods.BeginUpdate(Handle);
> | > }
> | > public void EndUpdate()
> | > {
> | > NativeMethods.EndUpdate(Handle);
> | > }
> | >
> | >
> | > protected override void OnMouseMove(MouseEventArgs e)
> | > {
> | > base.OnMouseMove (e);
> | > System.Diagnostics.Debug.WriteLine("MouseMove received");
> | > }
> | > public void DoUpdate()
> | > {
> | > Graphics g = CreateGraphics();
> | > g.FillRectangle(Brushes.Indigo,this.Bounds);
> | > g.Dispose();
> | > }
> | > }
> | > }
> | > </code>
> | > <code file="Form1.cs">
> | > using System;
> | > using System.Drawing;
> | > using System.Collections;
> | > using System.ComponentModel;
> | > using System.Windows.Forms;
> | > using System.Data;
> | >
> | > namespace WinForm_BeginEndUpdate_MouseMove
> | > {
> | > /// <summary>
> | > /// Summary description for Form1.
> | > /// </summary>
> | > public class Form1 : System.Windows.Forms.Form
> | > {
> | > private WinForm_BeginEndUpdate_MouseMove.MyUserControl myUserControl1;
> | > private System.Timers.Timer timer1;
> | > /// <summary>
> | > /// Required designer variable.
> | > /// </summary>
> | > private System.ComponentModel.Container components = null;
> | >
> | > public Form1()
> | > {
> | > //
> | > // Required for Windows Form Designer support
> | > //
> | > InitializeComponent();
> | >
> | > //
> | > // TODO: Add any constructor code after InitializeComponent call
> | > //
> | > }
> | >
> | > /// <summary>
> | > /// Clean up any resources being used.
> | > /// </summary>
> | > protected override void Dispose( bool disposing )
> | > {
> | > if( disposing )
> | > {
> | > if (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.myUserControl1 = new
> | > WinForm_BeginEndUpdate_MouseMove.MyUserControl();
> | > this.timer1 = new System.Timers.Timer();
> | > ((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
> | > this.SuspendLayout();
> | > //
> | > // myUserControl1
> | > //
> | > this.myUserControl1.BackColor = System.Drawing.SystemColors.Desktop;
> | > this.myUserControl1.Location = new System.Drawing.Point(72, 64);
> | > this.myUserControl1.Name = "myUserControl1";
> | > this.myUserControl1.Size = new System.Drawing.Size(256, 240);
> | > this.myUserControl1.TabIndex = 2;
> | > //
> | > // timer1
> | > //
> | > this.timer1.Enabled = true;
> | > this.timer1.Interval = 500;
> | > this.timer1.SynchronizingObject = this;
> | > this.timer1.Elapsed += new
> | > System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
> | > //
> | > // Form1
> | > //
> | > this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
> | > this.ClientSize = new System.Drawing.Size(408, 421);
> | > this.Controls.Add(this.myUserControl1);
> | > this.Name = "Form1";
> | > this.Text = "Form1";
> | > this.MouseMove += new
> | > System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
> | > ((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
> | > this.ResumeLayout(false);
> | >
> | > }
> | > #endregion
> | >
> | > /// <summary>
> | > /// The main entry point for the application.
> | > /// </summary>
> | > [STAThread]
> | > static void Main()
> | > {
> | > Application.Run(new Form1());
> | > }
> | >
> | > private void Form1_MouseMove(object sender,
> | > System.Windows.Forms.MouseEventArgs e)
> | > {
> | > System.Diagnostics.Debug.WriteLine("MainForm MouseMove received");
> | > }
> | >
> | > private void timer1_Elapsed(object sender,
> System.Timers.ElapsedEventArgs
> | > e)
> | > {
> | > myUserControl1.BeginUpdate();
> | > System.Diagnostics.Debug.WriteLine("BeginUpdate");
> | > myUserControl1.DoUpdate();
> | > myUserControl1.EndUpdate();
> | > System.Diagnostics.Debug.WriteLine("EndUpdate");
> | >
> | > }
> | > }
> | > }
> | >
> | > </code>
> | >
> | >
> | >
> | >
> |
> |
> |
>



Re: BeginUpdate/EndUpdate causing mouse move by abhishek

abhishek
Mon Oct 27 10:29:09 CST 2003

As I had mentioned before, this behavior does not reproduce for the ListBox
control. Would you happen to know what the ListBox control is doing that
prevents this from happening?

Abhishek

"Ying-Shen Yu[MSFT]" <v-yiy@online.microsoft.com> wrote in message
news:Km%23qNuFnDHA.2624@cpmsftngxa06.phx.gbl...
> Hi abhishek,
> Thanks for your sample, I reproed your problem now.
> For now, I haven't found a way to prevent MouseMove method to be called.
> However, since BeginUpdate/Endupate is called by yourself, could you add a
> boolean flag before actually executing your codes in the MouseMove?
> such as
> InUpdating = false;
> void BeginUpdate()
> {
> InUpdating = true;
> SendMessage ....
> }
> void EndUpdate()
> {
> SendMessage() ...
> InUpdating = false;
> }
> void MouseMove( ....)
> {
> if(!IsUpdating)
> {
> DoMouseMove();
> }
> }
>
> Does this work around solve your problem?
> Please be free to post on the group, if you still have problem on this
> issue.
> Thanks!
>
> Best regards,
>
> Ying-Shen Yu [MSFT]
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
>
> This posting is provided "AS IS" with no warranties and confers no rights.
> You should not reply this mail directly, "Online" should be removed before
> sending, Thanks!
>
> --------------------
> | From: "abhishek ghuwalewala" <abhishekg.nospam@nospam.mail.com>
> | References: <uV#BF5bmDHA.2592@TK2MSFTNGP10.phx.gbl>
> <mWgycKfmDHA.2808@cpmsftngxa06.phx.gbl>
> | Subject: Re: BeginUpdate/EndUpdate causing mouse move
> | Date: Fri, 24 Oct 2003 11:05:22 -0500
> | Lines: 638
> | X-Priority: 3
> | X-MSMail-Priority: Normal
> | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
> | Message-ID: <#o2aiikmDHA.372@TK2MSFTNGP11.phx.gbl>
> | Newsgroups: microsoft.public.dotnet.framework.windowsforms
> | NNTP-Posting-Host: client-64-158.natinst.com 130.164.64.158
> | Path:
>
cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.
> phx.gbl
> | Xref: cpmsftngxa06.phx.gbl
> microsoft.public.dotnet.framework.windowsforms:55191
> | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
> |
> | Ying-Shen,
> |
> | Thanks for your prompt reply. I am attaching a small sample project that
> | reproduces the problem. The instructions for reproducing the problem are
> | described in the application.
> |
> | Thanks,
> | Abhishek
> |
> | "Ying-Shen Yu[MSFT]" <v-yiy@online.microsoft.com> wrote in message
> | news:mWgycKfmDHA.2808@cpmsftngxa06.phx.gbl...
> | > Hi abhishek.
> | > Thanks for your post!
> | > You mean your mousemove event of your control or your form is fired
when
> | > you invoke the P/Invoke SendMessage
> | > method?
> | > I made a small program and tried to repro your problem, however I
didn't
> | > get any mouse move event on the user control or on the Form when
> invoking
> | > these two methods.
> | > I pasted my test code after the signature, you may try it on your
> system.
> | > Probably it will be helpful if you could give me a
> | > small sample project to repro this problem.
> | >
> | > Thanks for using MSDN Newsgroup!!
> | >
> | > Best regards,
> | >
> | > Ying-Shen Yu [MSFT]
> | > Microsoft Online Partner Support
> | > Get Secure! - www.microsoft.com/security
> | >
> | > This posting is provided "AS IS" with no warranties and confers no
> rights.
> | > You should not reply this mail directly, "Online" should be removed
> before
> | > sending, Thanks!
> | >
> | > <code file="MyUserControl.cs">
> | > using System;
> | > using System.Collections;
> | > using System.ComponentModel;
> | > using System.Drawing;
> | > using System.Data;
> | > using System.Windows.Forms;
> | > using System.Runtime.InteropServices;
> | >
> | > namespace WinForm_BeginEndUpdate_MouseMove
> | > {
> | > /// <summary>
> | > /// Summary description for MyUserControl.
> | > /// </summary>
> | > public class MyUserControl : System.Windows.Forms.UserControl
> | > {
> | > /// <summary>
> | > /// Required designer variable.
> | > /// </summary>
> | > private System.ComponentModel.Container components = null;
> | >
> | > public MyUserControl()
> | > {
> | > // This call is required by the Windows.Forms Form Designer.
> | > InitializeComponent();
> | >
> | > // TODO: Add any initialization after the InitializeComponent call
> | >
> | > }
> | >
> | > /// <summary>
> | > /// Clean up any resources being used.
> | > /// </summary>
> | > protected override void Dispose( bool disposing )
> | > {
> | > if( disposing )
> | > {
> | > if(components != null)
> | > {
> | > components.Dispose();
> | > }
> | > }
> | > base.Dispose( disposing );
> | > }
> | >
> | > #region Component 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()
> | > {
> | > //
> | > // MyUserControl
> | > //
> | > this.BackColor = System.Drawing.SystemColors.Desktop;
> | > this.Name = "MyUserControl";
> | > this.Size = new System.Drawing.Size(368, 424);
> | >
> | > }
> | > #endregion
> | >
> | > private class NativeMethods
> | > {
> | > [DllImport("user32.dll")]
> | > private extern static int SendMessage(IntPtr hwnd, uint nMsg,
> | > int wParam, int lParam);
> | > private const int WM_SETREDRAW = 0x000B;
> | > public static void BeginUpdate(IntPtr hwnd)
> | > {
> | > SendMessage(hwnd,WM_SETREDRAW,0,0);
> | > }
> | > public static void EndUpdate(IntPtr hwnd)
> | > {
> | > SendMessage(hwnd,WM_SETREDRAW,-1,0);
> | > }
> | >
> | > }
> | >
> | >
> | > public void BeginUpdate()
> | > {
> | > NativeMethods.BeginUpdate(Handle);
> | > }
> | > public void EndUpdate()
> | > {
> | > NativeMethods.EndUpdate(Handle);
> | > }
> | >
> | >
> | > protected override void OnMouseMove(MouseEventArgs e)
> | > {
> | > base.OnMouseMove (e);
> | > System.Diagnostics.Debug.WriteLine("MouseMove received");
> | > }
> | > public void DoUpdate()
> | > {
> | > Graphics g = CreateGraphics();
> | > g.FillRectangle(Brushes.Indigo,this.Bounds);
> | > g.Dispose();
> | > }
> | > }
> | > }
> | > </code>
> | > <code file="Form1.cs">
> | > using System;
> | > using System.Drawing;
> | > using System.Collections;
> | > using System.ComponentModel;
> | > using System.Windows.Forms;
> | > using System.Data;
> | >
> | > namespace WinForm_BeginEndUpdate_MouseMove
> | > {
> | > /// <summary>
> | > /// Summary description for Form1.
> | > /// </summary>
> | > public class Form1 : System.Windows.Forms.Form
> | > {
> | > private WinForm_BeginEndUpdate_MouseMove.MyUserControl myUserControl1;
> | > private System.Timers.Timer timer1;
> | > /// <summary>
> | > /// Required designer variable.
> | > /// </summary>
> | > private System.ComponentModel.Container components = null;
> | >
> | > public Form1()
> | > {
> | > //
> | > // Required for Windows Form Designer support
> | > //
> | > InitializeComponent();
> | >
> | > //
> | > // TODO: Add any constructor code after InitializeComponent call
> | > //
> | > }
> | >
> | > /// <summary>
> | > /// Clean up any resources being used.
> | > /// </summary>
> | > protected override void Dispose( bool disposing )
> | > {
> | > if( disposing )
> | > {
> | > if (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.myUserControl1 = new
> | > WinForm_BeginEndUpdate_MouseMove.MyUserControl();
> | > this.timer1 = new System.Timers.Timer();
> | > ((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
> | > this.SuspendLayout();
> | > //
> | > // myUserControl1
> | > //
> | > this.myUserControl1.BackColor = System.Drawing.SystemColors.Desktop;
> | > this.myUserControl1.Location = new System.Drawing.Point(72, 64);
> | > this.myUserControl1.Name = "myUserControl1";
> | > this.myUserControl1.Size = new System.Drawing.Size(256, 240);
> | > this.myUserControl1.TabIndex = 2;
> | > //
> | > // timer1
> | > //
> | > this.timer1.Enabled = true;
> | > this.timer1.Interval = 500;
> | > this.timer1.SynchronizingObject = this;
> | > this.timer1.Elapsed += new
> | > System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
> | > //
> | > // Form1
> | > //
> | > this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
> | > this.ClientSize = new System.Drawing.Size(408, 421);
> | > this.Controls.Add(this.myUserControl1);
> | > this.Name = "Form1";
> | > this.Text = "Form1";
> | > this.MouseMove += new
> | > System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
> | > ((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
> | > this.ResumeLayout(false);
> | >
> | > }
> | > #endregion
> | >
> | > /// <summary>
> | > /// The main entry point for the application.
> | > /// </summary>
> | > [STAThread]
> | > static void Main()
> | > {
> | > Application.Run(new Form1());
> | > }
> | >
> | > private void Form1_MouseMove(object sender,
> | > System.Windows.Forms.MouseEventArgs e)
> | > {
> | > System.Diagnostics.Debug.WriteLine("MainForm MouseMove received");
> | > }
> | >
> | > private void timer1_Elapsed(object sender,
> System.Timers.ElapsedEventArgs
> | > e)
> | > {
> | > myUserControl1.BeginUpdate();
> | > System.Diagnostics.Debug.WriteLine("BeginUpdate");
> | > myUserControl1.DoUpdate();
> | > myUserControl1.EndUpdate();
> | > System.Diagnostics.Debug.WriteLine("EndUpdate");
> | >
> | > }
> | > }
> | > }
> | >
> | > </code>
> | >
> | >
> | >
> | >
> |
> |
> |
>



Re: BeginUpdate/EndUpdate causing mouse move by v-yiy

v-yiy
Tue Oct 28 01:07:06 CST 2003

Hi abhishek,
In fact, this issue also occurred in native win32 application, it by design.
The system sometimes delivers a WM_MOUSEMOVE message even if the mouse
hasn't moved. Programs which are sensitive to physical mouse movement (such
as screen savers) should compare the coordinates in the WM_MOUSEMOVE
message with the coordinates from the previous mouse message and ignore the
message if they are the same.

The Document didn't make this clear, we already noticed this problem, it
mightbe fixed in the next release of the document.Thanks for your reporting.
If you need handle the real OnMouseMove event you need first check if the
point of the cursor is same as the previous one. the code should be
executed only when the values are different.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!

--------------------
| From: "abhishek ghuwalewala" <abhishekg.nospam@nospam.mail.com>
| References: <uV#BF5bmDHA.2592@TK2MSFTNGP10.phx.gbl>
<mWgycKfmDHA.2808@cpmsftngxa06.phx.gbl>
<#o2aiikmDHA.372@TK2MSFTNGP11.phx.gbl>
<Km#qNuFnDHA.2624@cpmsftngxa06.phx.gbl>
| Subject: Re: BeginUpdate/EndUpdate causing mouse move
| Date: Mon, 27 Oct 2003 10:29:09 -0600
| Lines: 348
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <O8N#zdKnDHA.360@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| NNTP-Posting-Host: client-79-20.natinst.com 130.164.79.20
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:55305
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| As I had mentioned before, this behavior does not reproduce for the
ListBox
| control. Would you happen to know what the ListBox control is doing that
| prevents this from happening?
|
| Abhishek
|
| "Ying-Shen Yu[MSFT]" <v-yiy@online.microsoft.com> wrote in message
| news:Km%23qNuFnDHA.2624@cpmsftngxa06.phx.gbl...
| > Hi abhishek,
| > Thanks for your sample, I reproed your problem now.
| > For now, I haven't found a way to prevent MouseMove method to be called.
| > However, since BeginUpdate/Endupate is called by yourself, could you
add a
| > boolean flag before actually executing your codes in the MouseMove?
| > such as
| > InUpdating = false;
| > void BeginUpdate()
| > {
| > InUpdating = true;
| > SendMessage ....
| > }
| > void EndUpdate()
| > {
| > SendMessage() ...
| > InUpdating = false;
| > }
| > void MouseMove( ....)
| > {
| > if(!IsUpdating)
| > {
| > DoMouseMove();
| > }
| > }
| >
| > Does this work around solve your problem?
| > Please be free to post on the group, if you still have problem on this
| > issue.
| > Thanks!
| >
| > Best regards,
| >
| > Ying-Shen Yu [MSFT]
| > Microsoft Online Partner Support
| > Get Secure! - www.microsoft.com/security
| >
| > This posting is provided "AS IS" with no warranties and confers no
rights.
| > You should not reply this mail directly, "Online" should be removed
before
| > sending, Thanks!
| >
| > --------------------
| > | From: "abhishek ghuwalewala" <abhishekg.nospam@nospam.mail.com>
| > | References: <uV#BF5bmDHA.2592@TK2MSFTNGP10.phx.gbl>
| > <mWgycKfmDHA.2808@cpmsftngxa06.phx.gbl>
| > | Subject: Re: BeginUpdate/EndUpdate causing mouse move
| > | Date: Fri, 24 Oct 2003 11:05:22 -0500
| > | Lines: 638
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| > | Message-ID: <#o2aiikmDHA.372@TK2MSFTNGP11.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.framework.windowsforms
| > | NNTP-Posting-Host: client-64-158.natinst.com 130.164.64.158
| > | Path:
| >
|
cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.
| > phx.gbl
| > | Xref: cpmsftngxa06.phx.gbl
| > microsoft.public.dotnet.framework.windowsforms:55191
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
| > |
| > | Ying-Shen,
| > |
| > | Thanks for your prompt reply. I am attaching a small sample project
that
| > | reproduces the problem. The instructions for reproducing the problem
are
| > | described in the application.
| > |
| > | Thanks,
| > | Abhishek
| > |
| > | "Ying-Shen Yu[MSFT]" <v-yiy@online.microsoft.com> wrote in message
| > | news:mWgycKfmDHA.2808@cpmsftngxa06.phx.gbl...
| > | > Hi abhishek.
| > | > Thanks for your post!
| > | > You mean your mousemove event of your control or your form is fired
| when
| > | > you invoke the P/Invoke SendMessage
| > | > method?
| > | > I made a small program and tried to repro your problem, however I
| didn't
| > | > get any mouse move event on the user control or on the Form when
| > invoking
| > | > these two methods.
| > | > I pasted my test code after the signature, you may try it on your
| > system.
| > | > Probably it will be helpful if you could give me a
| > | > small sample project to repro this problem.
| > | >
| > | > Thanks for using MSDN Newsgroup!!
| > | >
| > | > Best regards,
| > | >
| > | > Ying-Shen Yu [MSFT]
| > | > Microsoft Online Partner Support
| > | > Get Secure! - www.microsoft.com/security
| > | >
| > | > This posting is provided "AS IS" with no warranties and confers no
| > rights.
| > | > You should not reply this mail directly, "Online" should be removed
| > before
| > | > sending, Thanks!
| > | >
| > | > <code file="MyUserControl.cs">
| > | > using System;
| > | > using System.Collections;
| > | > using System.ComponentModel;
| > | > using System.Drawing;
| > | > using System.Data;
| > | > using System.Windows.Forms;
| > | > using System.Runtime.InteropServices;
| > | >
| > | > namespace WinForm_BeginEndUpdate_MouseMove
| > | > {
| > | > /// <summary>
| > | > /// Summary description for MyUserControl.
| > | > /// </summary>
| > | > public class MyUserControl : System.Windows.Forms.UserControl
| > | > {
| > | > /// <summary>
| > | > /// Required designer variable.
| > | > /// </summary>
| > | > private System.ComponentModel.Container components = null;
| > | >
| > | > public MyUserControl()
| > | > {
| > | > // This call is required by the Windows.Forms Form Designer.
| > | > InitializeComponent();
| > | >
| > | > // TODO: Add any initialization after the InitializeComponent call
| > | >
| > | > }
| > | >
| > | > /// <summary>
| > | > /// Clean up any resources being used.
| > | > /// </summary>
| > | > protected override void Dispose( bool disposing )
| > | > {
| > | > if( disposing )
| > | > {
| > | > if(components != null)
| > | > {
| > | > components.Dispose();
| > | > }
| > | > }
| > | > base.Dispose( disposing );
| > | > }
| > | >
| > | > #region Component 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()
| > | > {
| > | > //
| > | > // MyUserControl
| > | > //
| > | > this.BackColor = System.Drawing.SystemColors.Desktop;
| > | > this.Name = "MyUserControl";
| > | > this.Size = new System.Drawing.Size(368, 424);
| > | >
| > | > }
| > | > #endregion
| > | >
| > | > private class NativeMethods
| > | > {
| > | > [DllImport("user32.dll")]
| > | > private extern static int SendMessage(IntPtr hwnd, uint nMsg,
| > | > int wParam, int lParam);
| > | > private const int WM_SETREDRAW = 0x000B;
| > | > public static void BeginUpdate(IntPtr hwnd)
| > | > {
| > | > SendMessage(hwnd,WM_SETREDRAW,0,0);
| > | > }
| > | > public static void EndUpdate(IntPtr hwnd)
| > | > {
| > | > SendMessage(hwnd,WM_SETREDRAW,-1,0);
| > | > }
| > | >
| > | > }
| > | >
| > | >
| > | > public void BeginUpdate()
| > | > {
| > | > NativeMethods.BeginUpdate(Handle);
| > | > }
| > | > public void EndUpdate()
| > | > {
| > | > NativeMethods.EndUpdate(Handle);
| > | > }
| > | >
| > | >
| > | > protected override void OnMouseMove(MouseEventArgs e)
| > | > {
| > | > base.OnMouseMove (e);
| > | > System.Diagnostics.Debug.WriteLine("MouseMove received");
| > | > }
| > | > public void DoUpdate()
| > | > {
| > | > Graphics g = CreateGraphics();
| > | > g.FillRectangle(Brushes.Indigo,this.Bounds);
| > | > g.Dispose();
| > | > }
| > | > }
| > | > }
| > | > </code>
| > | > <code file="Form1.cs">
| > | > using System;
| > | > using System.Drawing;
| > | > using System.Collections;
| > | > using System.ComponentModel;
| > | > using System.Windows.Forms;
| > | > using System.Data;
| > | >
| > | > namespace WinForm_BeginEndUpdate_MouseMove
| > | > {
| > | > /// <summary>
| > | > /// Summary description for Form1.
| > | > /// </summary>
| > | > public class Form1 : System.Windows.Forms.Form
| > | > {
| > | > private WinForm_BeginEndUpdate_MouseMove.MyUserControl
myUserControl1;
| > | > private System.Timers.Timer timer1;
| > | > /// <summary>
| > | > /// Required designer variable.
| > | > /// </summary>
| > | > private System.ComponentModel.Container components = null;
| > | >
| > | > public Form1()
| > | > {
| > | > //
| > | > // Required for Windows Form Designer support
| > | > //
| > | > InitializeComponent();
| > | >
| > | > //
| > | > // TODO: Add any constructor code after InitializeComponent call
| > | > //
| > | > }
| > | >
| > | > /// <summary>
| > | > /// Clean up any resources being used.
| > | > /// </summary>
| > | > protected override void Dispose( bool disposing )
| > | > {
| > | > if( disposing )
| > | > {
| > | > if (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.myUserControl1 = new
| > | > WinForm_BeginEndUpdate_MouseMove.MyUserControl();
| > | > this.timer1 = new System.Timers.Timer();
| > | >
((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
| > | > this.SuspendLayout();
| > | > //
| > | > // myUserControl1
| > | > //
| > | > this.myUserControl1.BackColor = System.Drawing.SystemColors.Desktop;
| > | > this.myUserControl1.Location = new System.Drawing.Point(72, 64);
| > | > this.myUserControl1.Name = "myUserControl1";
| > | > this.myUserControl1.Size = new System.Drawing.Size(256, 240);
| > | > this.myUserControl1.TabIndex = 2;
| > | > //
| > | > // timer1
| > | > //
| > | > this.timer1.Enabled = true;
| > | > this.timer1.Interval = 500;
| > | > this.timer1.SynchronizingObject = this;
| > | > this.timer1.Elapsed += new
| > | > System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
| > | > //
| > | > // Form1
| > | > //
| > | > this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
| > | > this.ClientSize = new System.Drawing.Size(408, 421);
| > | > this.Controls.Add(this.myUserControl1);
| > | > this.Name = "Form1";
| > | > this.Text = "Form1";
| > | > this.MouseMove += new
| > | > System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
| > | > ((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
| > | > this.ResumeLayout(false);
| > | >
| > | > }
| > | > #endregion
| > | >
| > | > /// <summary>
| > | > /// The main entry point for the application.
| > | > /// </summary>
| > | > [STAThread]
| > | > static void Main()
| > | > {
| > | > Application.Run(new Form1());
| > | > }
| > | >
| > | > private void Form1_MouseMove(object sender,
| > | > System.Windows.Forms.MouseEventArgs e)
| > | > {
| > | > System.Diagnostics.Debug.WriteLine("MainForm MouseMove received");
| > | > }
| > | >
| > | > private void timer1_Elapsed(object sender,
| > System.Timers.ElapsedEventArgs
| > | > e)
| > | > {
| > | > myUserControl1.BeginUpdate();
| > | > System.Diagnostics.Debug.WriteLine("BeginUpdate");
| > | > myUserControl1.DoUpdate();
| > | > myUserControl1.EndUpdate();
| > | > System.Diagnostics.Debug.WriteLine("EndUpdate");
| > | >
| > | > }
| > | > }
| > | > }
| > | >
| > | > </code>
| > | >
| > | >
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|


Re: BeginUpdate/EndUpdate causing mouse move by Jack

Jack
Tue Oct 28 01:15:35 CST 2003

So, this BUG is BY DESIGN?


"The system sometimes delivers a WM_MOUSEMOVE message even if the mouse
hasn't moved"


Sounds like a bug to me, a signal fired that the mouse has moved when infact
it hasnt, sory, by design doesn't hide bullssshit
--

Jack Mayhoff
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

"Ying-Shen Yu[MSFT]" <v-yiy@online.microsoft.com> wrote in message
news:urXSeISnDHA.2464@cpmsftngxa06.phx.gbl...
> Hi abhishek,
> In fact, this issue also occurred in native win32 application, it by
design.
> The system sometimes delivers a WM_MOUSEMOVE message even if the mouse
> hasn't moved. Programs which are sensitive to physical mouse movement
(such
> as screen savers) should compare the coordinates in the WM_MOUSEMOVE
> message with the coordinates from the previous mouse message and ignore
the
> message if they are the same.
>
> The Document didn't make this clear, we already noticed this problem, it
> mightbe fixed in the next release of the document.Thanks for your
reporting.
> If you need handle the real OnMouseMove event you need first check if the
> point of the cursor is same as the previous one. the code should be
> executed only when the values are different.
> Thanks!
>
> Best regards,
>
> Ying-Shen Yu [MSFT]
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
>
> This posting is provided "AS IS" with no warranties and confers no rights.
> You should not reply this mail directly, "Online" should be removed before
> sending, Thanks!
>
> --------------------
> | From: "abhishek ghuwalewala" <abhishekg.nospam@nospam.mail.com>
> | References: <uV#BF5bmDHA.2592@TK2MSFTNGP10.phx.gbl>
> <mWgycKfmDHA.2808@cpmsftngxa06.phx.gbl>
> <#o2aiikmDHA.372@TK2MSFTNGP11.phx.gbl>
> <Km#qNuFnDHA.2624@cpmsftngxa06.phx.gbl>
> | Subject: Re: BeginUpdate/EndUpdate causing mouse move
> | Date: Mon, 27 Oct 2003 10:29:09 -0600
> | Lines: 348
> | X-Priority: 3
> | X-MSMail-Priority: Normal
> | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
> | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
> | Message-ID: <O8N#zdKnDHA.360@TK2MSFTNGP12.phx.gbl>
> | Newsgroups: microsoft.public.dotnet.framework.windowsforms
> | NNTP-Posting-Host: client-79-20.natinst.com 130.164.79.20
> | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
> | Xref: cpmsftngxa06.phx.gbl
> microsoft.public.dotnet.framework.windowsforms:55305
> | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
> |
> | As I had mentioned before, this behavior does not reproduce for the
> ListBox
> | control. Would you happen to know what the ListBox control is doing that
> | prevents this from happening?
> |
> | Abhishek
> |
> | "Ying-Shen Yu[MSFT]" <v-yiy@online.microsoft.com> wrote in message
> | news:Km%23qNuFnDHA.2624@cpmsftngxa06.phx.gbl...
> | > Hi abhishek,
> | > Thanks for your sample, I reproed your problem now.
> | > For now, I haven't found a way to prevent MouseMove method to be
called.
> | > However, since BeginUpdate/Endupate is called by yourself, could you
> add a
> | > boolean flag before actually executing your codes in the MouseMove?
> | > such as
> | > InUpdating = false;
> | > void BeginUpdate()
> | > {
> | > InUpdating = true;
> | > SendMessage ....
> | > }
> | > void EndUpdate()
> | > {
> | > SendMessage() ...
> | > InUpdating = false;
> | > }
> | > void MouseMove( ....)
> | > {
> | > if(!IsUpdating)
> | > {
> | > DoMouseMove();
> | > }
> | > }
> | >
> | > Does this work around solve your problem?
> | > Please be free to post on the group, if you still have problem on this
> | > issue.
> | > Thanks!
> | >
> | > Best regards,
> | >
> | > Ying-Shen Yu [MSFT]
> | > Microsoft Online Partner Support
> | > Get Secure! - www.microsoft.com/security
> | >
> | > This posting is provided "AS IS" with no warranties and confers no
> rights.
> | > You should not reply this mail directly, "Online" should be removed
> before
> | > sending, Thanks!
> | >
> | > --------------------
> | > | From: "abhishek ghuwalewala" <abhishekg.nospam@nospam.mail.com>
> | > | References: <uV#BF5bmDHA.2592@TK2MSFTNGP10.phx.gbl>
> | > <mWgycKfmDHA.2808@cpmsftngxa06.phx.gbl>
> | > | Subject: Re: BeginUpdate/EndUpdate causing mouse move
> | > | Date: Fri, 24 Oct 2003 11:05:22 -0500
> | > | Lines: 638
> | > | X-Priority: 3
> | > | X-MSMail-Priority: Normal
> | > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
> | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
> | > | Message-ID: <#o2aiikmDHA.372@TK2MSFTNGP11.phx.gbl>
> | > | Newsgroups: microsoft.public.dotnet.framework.windowsforms
> | > | NNTP-Posting-Host: client-64-158.natinst.com 130.164.64.158
> | > | Path:
> | >
> |
>
cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.
> | > phx.gbl
> | > | Xref: cpmsftngxa06.phx.gbl
> | > microsoft.public.dotnet.framework.windowsforms:55191
> | > | X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
> | > |
> | > | Ying-Shen,
> | > |
> | > | Thanks for your prompt reply. I am attaching a small sample project
> that
> | > | reproduces the problem. The instructions for reproducing the problem
> are
> | > | described in the application.
> | > |
> | > | Thanks,
> | > | Abhishek
> | > |
> | > | "Ying-Shen Yu[MSFT]" <v-yiy@online.microsoft.com> wrote in message
> | > | news:mWgycKfmDHA.2808@cpmsftngxa06.phx.gbl...
> | > | > Hi abhishek.
> | > | > Thanks for your post!
> | > | > You mean your mousemove event of your control or your form is
fired
> | when
> | > | > you invoke the P/Invoke SendMessage
> | > | > method?
> | > | > I made a small program and tried to repro your problem, however I
> | didn't
> | > | > get any mouse move event on the user control or on the Form when
> | > invoking
> | > | > these two methods.
> | > | > I pasted my test code after the signature, you may try it on your
> | > system.
> | > | > Probably it will be helpful if you could give me a
> | > | > small sample project to repro this problem.
> | > | >
> | > | > Thanks for using MSDN Newsgroup!!
> | > | >
> | > | > Best regards,
> | > | >
> | > | > Ying-Shen Yu [MSFT]
> | > | > Microsoft Online Partner Support
> | > | > Get Secure! - www.microsoft.com/security
> | > | >
> | > | > This posting is provided "AS IS" with no warranties and confers no
> | > rights.
> | > | > You should not reply this mail directly, "Online" should be
removed
> | > before
> | > | > sending, Thanks!
> | > | >
> | > | > <code file="MyUserControl.cs">
> | > | > using System;
> | > | > using System.Collections;
> | > | > using System.ComponentModel;
> | > | > using System.Drawing;
> | > | > using System.Data;
> | > | > using System.Windows.Forms;
> | > | > using System.Runtime.InteropServices;
> | > | >
> | > | > namespace WinForm_BeginEndUpdate_MouseMove
> | > | > {
> | > | > /// <summary>
> | > | > /// Summary description for MyUserControl.
> | > | > /// </summary>
> | > | > public class MyUserControl : System.Windows.Forms.UserControl
> | > | > {
> | > | > /// <summary>
> | > | > /// Required designer variable.
> | > | > /// </summary>
> | > | > private System.ComponentModel.Container components = null;
> | > | >
> | > | > public MyUserControl()
> | > | > {
> | > | > // This call is required by the Windows.Forms Form Designer.
> | > | > InitializeComponent();
> | > | >
> | > | > // TODO: Add any initialization after the InitializeComponent call
> | > | >
> | > | > }
> | > | >
> | > | > /// <summary>
> | > | > /// Clean up any resources being used.
> | > | > /// </summary>
> | > | > protected override void Dispose( bool disposing )
> | > | > {
> | > | > if( disposing )
> | > | > {
> | > | > if(components != null)
> | > | > {
> | > | > components.Dispose();
> | > | > }
> | > | > }
> | > | > base.Dispose( disposing );
> | > | > }
> | > | >
> | > | > #region Component 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()
> | > | > {
> | > | > //
> | > | > // MyUserControl
> | > | > //
> | > | > this.BackColor = System.Drawing.SystemColors.Desktop;
> | > | > this.Name = "MyUserControl";
> | > | > this.Size = new System.Drawing.Size(368, 424);
> | > | >
> | > | > }
> | > | > #endregion
> | > | >
> | > | > private class NativeMethods
> | > | > {
> | > | > [DllImport("user32.dll")]
> | > | > private extern static int SendMessage(IntPtr hwnd, uint nMsg,
> | > | > int wParam, int lParam);
> | > | > private const int WM_SETREDRAW = 0x000B;
> | > | > public static void BeginUpdate(IntPtr hwnd)
> | > | > {
> | > | > SendMessage(hwnd,WM_SETREDRAW,0,0);
> | > | > }
> | > | > public static void EndUpdate(IntPtr hwnd)
> | > | > {
> | > | > SendMessage(hwnd,WM_SETREDRAW,-1,0);
> | > | > }
> | > | >
> | > | > }
> | > | >
> | > | >
> | > | > public void BeginUpdate()
> | > | > {
> | > | > NativeMethods.BeginUpdate(Handle);
> | > | > }
> | > | > public void EndUpdate()
> | > | > {
> | > | > NativeMethods.EndUpdate(Handle);
> | > | > }
> | > | >
> | > | >
> | > | > protected override void OnMouseMove(MouseEventArgs e)
> | > | > {
> | > | > base.OnMouseMove (e);
> | > | > System.Diagnostics.Debug.WriteLine("MouseMove received");
> | > | > }
> | > | > public void DoUpdate()
> | > | > {
> | > | > Graphics g = CreateGraphics();
> | > | > g.FillRectangle(Brushes.Indigo,this.Bounds);
> | > | > g.Dispose();
> | > | > }
> | > | > }
> | > | > }
> | > | > </code>
> | > | > <code file="Form1.cs">
> | > | > using System;
> | > | > using System.Drawing;
> | > | > using System.Collections;
> | > | > using System.ComponentModel;
> | > | > using System.Windows.Forms;
> | > | > using System.Data;
> | > | >
> | >