Jump to content
  • Advertisement
Sign in to follow this  
barakus

[.net] C# Continous Redraw of Child Forms

This topic is 4851 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to get all my child forms to redraw every frame, not just when they are focused. Anyone know of a good way to achieve this?

Share this post


Link to post
Share on other sites
Advertisement
Every frame? Are you using GDI+ or OpenGL/DirectX? I'm guessing GDI+, but the best solution I have ever used is a timer that redraws the form on a constant interval. I'm guessing that there is a much better solution, but I was never able to find it before I started using DirectX anyway.

Share this post


Link to post
Share on other sites
You could always register for the Application.Idle event and Invalidate() each of your child forms on that event. (This will cause OnPaint to be called on each of them, but you probably knew that.)

Application.Idle is fired whenever the application is about to become idle, so it works just like a render/game loop in an opengl/direct3d set up.

For a bulletproof method you could also go for a similar approach, listed at Tom Miller's blog, that is the recommended way for working with Managed DirectX and it should work equally well with GDI+.

Share this post


Link to post
Share on other sites
hmm.. I cant get it to work at all with Tom Miller's method...
It wont even pick up the idle event handler at all unless I close all the child windows, and even then it is reporting it as idle when its not. Any ideas?
Heres the relevant code:

static void Main()
{
RexMapper Rex = new RexMapper();
Rex.MainLoop();
}

public void MainLoop()
{
System.Windows.Forms.Application.Idle +=new EventHandler(Application_Idle);
Application.Run(this);
}

[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("User32.dll", CharSet=CharSet.Auto)]
public static extern bool PeekMessage(out Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);

private bool AppStillIdle
{
get
{
Message msg;
return !RexMapper.PeekMessage(out msg,IntPtr.Zero,
0,0,0);
}
}
[StructLayout(LayoutKind.Sequential)]
public struct Message
{
public IntPtr hWnd;
public int msg;
public IntPtr wParam;
public IntPtr lParam;
public uint time;
public System.Drawing.Point p;
}




This is all on the parent MDI form.

[Edited by - barakus on August 10, 2005 12:34:57 AM]

Share this post


Link to post
Share on other sites
Try creating a new class called Bootrap with something like this in it:


class Bootstrap
{
#region Unmanaged
[SuppressUnmanagedCodeSecurity]
[DllImport( "User32.dll", CharSet=CharSet.Auto )]
public static extern bool PeekMessage( out Message message, IntPtr windowHandle, uint messageFilterMin, uint messageFilterMax, uint flags );

[StructLayout( LayoutKind.Sequential )]
public struct Message
{
public IntPtr windowHandle;
public System.Windows.Forms.Message msg;
public IntPtr wParam;
public IntPtr lParam;
public uint time;
public Point p;
}
#endregion

private RexMapper form;

private static bool Idle
{
get
{
Message msg;
return !PeekMessage( out msg, IntPtr.Zero, 0, 0, 0 );
}
}

[STAThread]
public static void Main()
{
new Bootstrap().Start();
}

public void Start()
{
using ( form = new RexMapper() )
{
form.Show();
Application.Idle += new EventHandler( OnApplicationIdle );
Application.Run( form );
}
}

private void OnApplicationIdle( object sender, EventArgs e )
{
while ( Idle )
{
form.MethodThatInvalidatesChildren();
}
}
}


Share this post


Link to post
Share on other sites
Thanks a lot for the help, but that is quite similar to what I put together before, but my parent form is an mdi container. I think the problem lies somewhere in that.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!