PDA

View Full Version : سوال: شفاف شدن پنحره هنگام شروع



amir7519
چهارشنبه 01 مهر 1394, 09:52 صبح
سلام،
من توی پروژه ای که ساختم میخوام فرم اصلی وقتی اجرا میشه مقدار شفافیت فرم اضافه بشه.
مثل اجرای یک انمیشین.

محمد رضا فاتحی
چهارشنبه 01 مهر 1394, 09:58 صبح
یه backgroundworker روی فرمت بزار و اینو داخل ایونت اصلیش بنویس

while (Opacity!=1)
{
Opacity += 0.01;
System.Threading.Thread.Sleep(100);
}


و تو هنگام لود فرمت رانش کن

محمد رضا فاتحی
چهارشنبه 01 مهر 1394, 09:59 صبح
اگه نشد بگو نمونه برات بفرستم

drsina
چهارشنبه 01 مهر 1394, 10:02 صبح
اینو به جای فرمتون کپی کنید : اول فایل دیزاینر رو پاک کنید .
using System;using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;




/// <summary>
/// Base form class that provides fading/sliding effects on open/close of the form.
/// </summary>
public class Form1 : Form
{
#region Win32




const int AW_HIDE = 0X10000;
const int AW_ACTIVATE = 0X20000;
const int AW_HOR_POSITIVE = 0X1;
const int AW_HOR_NEGATIVE = 0X2;
const int AW_SLIDE = 0X40000;
const int AW_BLEND = 0X80000;




[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int AnimateWindow
(IntPtr hwand, int dwTime, int dwFlags);




#endregion




#region Variables




private bool _UseSlideAnimation;




#endregion




#region Constructor




/// <summary>
/// Initializes a new instance of the <see cref="FadeForm"/> class.
/// </summary>
public Form1() : this(false) { }


/// <summary>
/// Initializes a new instance of the <see cref="FadeForm"/> class.
/// </summary>
/// <param name="useSlideAnimation">if set to <c>true</c> [use slide animation].</param>
public Form1(bool useSlideAnimation)
{
_UseSlideAnimation = useSlideAnimation;
}




#endregion




#region Overrides




/// <summary>
/// Raises the <see cref="E:System.Windows.Forms.Form.Load"/> event.
/// </summary>
/// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
AnimateWindow(this.Handle, 1000, AW_ACTIVATE | (_UseSlideAnimation ? AW_HOR_POSITIVE | AW_SLIDE : AW_BLEND));
}




/// <summary>
/// Raises the <see cref="E:System.Windows.Forms.Form.Closing"/> event.
/// </summary>
/// <param name="e">A <see cref="T:System.ComponentModel.CancelEventArgs"/> that contains the event data.</param>
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
base.OnClosing(e);
if (e.Cancel == false)
{
AnimateWindow(this.Handle, 1000, AW_HIDE | (_UseSlideAnimation ? AW_HOR_NEGATIVE | AW_SLIDE : AW_BLEND));
}
}




#endregion




}

amir7519
چهارشنبه 01 مهر 1394, 10:41 صبح
واقعا ممنونم.
اما این دو کدی که شما گذاشتین چه تفاوتی دارن در صورتی که هر دو کد یک کار انجام میدن؟
آقا رضا من که نمیتونم از کد دومی که دوست عزیز drsina گذاشتن استفاده کنم اگه لطف کنی نمونه کد بزاری ممنون میشم.
از هردوتون تشکر میکنم.

محمد رضا فاتحی
چهارشنبه 01 مهر 1394, 10:53 صبح
سلام....بفرمایید

amir7519
چهارشنبه 01 مهر 1394, 15:48 عصر
واقعا ممنونم.مرسی