hi
i have a code that is given effect on forms...
some part of this code is for closing form
but this sample code don't close form in an effect
because it don't run in a thread and i don't know how run that in a thread
please help me
my code is that:
private void btnClose_Click(object sender, System.EventArgs e) { flags -= WinAPI.AW_ACTIVATE; flags += WinAPI.AW_HIDE; WinAPI.AnimateWindow(this.Handle,animationTime,flags); this.Dispose(); }
|
and ApiClass is here :
using System; using System.Runtime.InteropServices;
namespace formAnimation { /// /// Win32 implementation to show / hide a window with animation. ///
public class WinAPI { /// /// Animates the window from left to right. This flag can be used with roll or slide animation. /// public const int AW_HOR_POSITIVE = 0X1; /// /// Animates the window from right to left. This flag can be used with roll or slide animation. /// public const int AW_HOR_NEGATIVE = 0X2; /// /// Animates the window from top to bottom. This flag can be used with roll or slide animation. /// public const int AW_VER_POSITIVE = 0X4; /// /// Animates the window from bottom to top. This flag can be used with roll or slide animation. /// public const int AW_VER_NEGATIVE = 0X8; /// /// Makes the window appear to collapse inward if AW_HIDE is used or expand outward if the AW_HIDE is not used. /// public const int AW_CENTER = 0X10; /// /// Hides the window. By default, the window is shown. /// public const int AW_HIDE = 0X10000; /// /// Activates the window. /// public const int AW_ACTIVATE = 0X20000; /// /// Uses slide animation. By default, roll animation is used. /// public const int AW_SLIDE = 0X40000; /// /// Uses a fade effect. This flag can be used only if hwnd is a top-level window. /// public const int AW_BLEND = 0X80000;
/// /// Animates a window. /// [DllImport("user32.dll", CharSet=CharSet.Auto)] public static extern int AnimateWindow (IntPtr hwand , int dwTime , int dwFlags) ; } }
|
thanks
Nilanka DharmadasaPosted Nov 10, 2009, 5:46 AM
Try this code. Please test it and let me know if you find any issue. I could not test this code.
private void MyThreadFunction()
{
WinAPI.AnimateWindow(this.Handle, animationTime, flags);
this.ThreadFinished();
}
private void btnClose_Click(object sender, System.EventArgs e)
{
flags -= WinAPI.AW_ACTIVATE;
flags += WinAPI.AW_HIDE;
Thread mythread = new Thread(new ThreadStart(this.MyThreadFunction));
mythread.Start();
}
public delegate void disposeform();
public void ThreadFinished()
{
if (this.InvokeRequired)
{
this.Invoke(new disposeform(ThreadFinished), new object[] { });
return;
}
this.Dispose();
}
Do not forget this also on the top of the class.
using System.Threading;
If this helps, please accept my answer.
Nilanka DharmadasaPosted Nov 10, 2009, 7:48 AM
My code works for me without any issue.
We use delegates to avoid the mentioned cross thread issue. Don;t remove the delegate. Without directly disposing the form you should do it via a delegate. Use my code. It works.
Bahar JalaliPosted Nov 10, 2009, 7:42 AM
thanks my good friend
success
Bahar JalaliPosted Nov 10, 2009, 7:23 AM