G
Guest
I have been racking my brains trying to figure out how to know when you have
scrolled the MdiClient window on an MDI form. (Not an MdiChild Window) I
have tried monitoring the messages for both the MdiClient and the MdiForm
itself..
I put a IFilterMessage as well well as overriding the WndProc on the the
mainform to see all messages going by and Identifiying the MdiClient
Messages..
When you click on the ScrollBar you get..
MdiClient->WM_NCLBUTTONDOWN
There is not a corresponding up button message or a WM_HSCROLL message.
Form that point you get no further messages in the MdiForms WndProc or the
IMessageFilters.PreveiwMessage until you release the mouse and then you get
either:
1) If you are clicked on the scrollbar and move the cursor,either to a
status bar or other neighboring control below it before you release the
mouse the next message appears to be a WM_MOUSEMOVE on the status bar or
other control
2) If you release the mouse in the scroll bar is issue the MdiClient a
WM_Paint but it doesn't always do a complete repaint which results in any
background painting of the MdiClient being messed up when scrolling has
occurred...
3) If you release back into the MdiClient widow you get a WM_SetCursor
message and again it doesn't do a complete repaint which results in any
background painting of the MdiClient being messed up.
Any ideas on you tell when you have scolled the MdiClient on a MdiParent
form?? What I want to be able to do is when the MdiClient has been Scrolled
to completely invalidate it and repaint it so the background is intact...
I found several discussions on various forums including one where they are
saying to Invalidate it completely on the first MdiChild paint attempt,
which cause the background to paint ok but it flickers badly.
I used the code below found on the web to cause painting of the MdiChild
background..
Thanks..
// This code stops the background repainting of the MdiClient from flickering
// as it sets the Double Buffering in MdiClient when doesnt set properly
// .From an Article at
// http://www.codeproject.com/csharp/MdiClientRevisited.asp#xx948448xx
[DefaultValue(false)]
public new bool IsMdiContainer
{
get{ return base.IsMdiContainer; }
set
{
base.IsMdiContainer = value;
if( ! value) return;
for(int i = 0; i < this.Controls.Count; i++)
{
MdiClient mdiClient = this.Controls as MdiClient;
if(mdiClient != null)
{
ControlStyles styles = ControlStyles.DoubleBuffer;
try
{
// Prevent flickering, only if our assembly
// has reflection permission.
Type mdiType = typeof(MdiClient);
System.Reflection.BindingFlags flags =
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance;
System.Reflection.MethodInfo method
= mdiType.GetMethod("SetStyle",flags);
object[] param = {styles, true};
method.Invoke(mdiClient,param);
}
catch ( System.Security.SecurityException)
{
/*Don't do anything!!! This code is running under
partially trusted context*/
}
mdiClient.Paint +=new PaintEventHandler(this.MdiClient_Paint);
mdiClient.Resize +=new EventHandler(MdiClient_Resize);
break;
}
}
}
}
scrolled the MdiClient window on an MDI form. (Not an MdiChild Window) I
have tried monitoring the messages for both the MdiClient and the MdiForm
itself..
I put a IFilterMessage as well well as overriding the WndProc on the the
mainform to see all messages going by and Identifiying the MdiClient
Messages..
When you click on the ScrollBar you get..
MdiClient->WM_NCLBUTTONDOWN
There is not a corresponding up button message or a WM_HSCROLL message.
Form that point you get no further messages in the MdiForms WndProc or the
IMessageFilters.PreveiwMessage until you release the mouse and then you get
either:
1) If you are clicked on the scrollbar and move the cursor,either to a
status bar or other neighboring control below it before you release the
mouse the next message appears to be a WM_MOUSEMOVE on the status bar or
other control
2) If you release the mouse in the scroll bar is issue the MdiClient a
WM_Paint but it doesn't always do a complete repaint which results in any
background painting of the MdiClient being messed up when scrolling has
occurred...
3) If you release back into the MdiClient widow you get a WM_SetCursor
message and again it doesn't do a complete repaint which results in any
background painting of the MdiClient being messed up.
Any ideas on you tell when you have scolled the MdiClient on a MdiParent
form?? What I want to be able to do is when the MdiClient has been Scrolled
to completely invalidate it and repaint it so the background is intact...
I found several discussions on various forums including one where they are
saying to Invalidate it completely on the first MdiChild paint attempt,
which cause the background to paint ok but it flickers badly.
I used the code below found on the web to cause painting of the MdiChild
background..
Thanks..
// This code stops the background repainting of the MdiClient from flickering
// as it sets the Double Buffering in MdiClient when doesnt set properly
// .From an Article at
// http://www.codeproject.com/csharp/MdiClientRevisited.asp#xx948448xx
[DefaultValue(false)]
public new bool IsMdiContainer
{
get{ return base.IsMdiContainer; }
set
{
base.IsMdiContainer = value;
if( ! value) return;
for(int i = 0; i < this.Controls.Count; i++)
{
MdiClient mdiClient = this.Controls as MdiClient;
if(mdiClient != null)
{
ControlStyles styles = ControlStyles.DoubleBuffer;
try
{
// Prevent flickering, only if our assembly
// has reflection permission.
Type mdiType = typeof(MdiClient);
System.Reflection.BindingFlags flags =
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance;
System.Reflection.MethodInfo method
= mdiType.GetMethod("SetStyle",flags);
object[] param = {styles, true};
method.Invoke(mdiClient,param);
}
catch ( System.Security.SecurityException)
{
/*Don't do anything!!! This code is running under
partially trusted context*/
}
mdiClient.Paint +=new PaintEventHandler(this.MdiClient_Paint);
mdiClient.Resize +=new EventHandler(MdiClient_Resize);
break;
}
}
}
}