コード例 #1
0
ファイル: FormEx.cs プロジェクト: umerov1999/CSharpLib
        /// <summary>
        ///     Determines special settings for this <see cref="Form"/>.
        ///     <para>
        ///         Hint: This function should be called before the <see cref="Form"/> is
        ///         created.
        ///     </para>
        /// </summary>
        /// <param name="form">
        ///     The form window to determine the settings.
        /// </param>
        /// <param name="settings">
        ///     The settings to be applied.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     form is null.
        /// </exception>
        public static Form Plus(this Form form, FormExPlusSettings settings = FormExPlusSettings.LogLoadingTime)
        {
            if (form == null)
            {
                throw new ArgumentNullException(nameof(form));
            }
            if (Application.OpenForms.OfType <Form>().Any(f => f == form))
            {
                return(form);
            }
            if (Log.DebugMode > 0 && settings.HasFlag(FormExPlusSettings.LogLoadingTime))
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                form.Shown += OnShown;

                void OnShown(object sender, EventArgs e)
                {
                    stopwatch.Stop();
                    Log.Write($"Stopwatch: {form.Name} loaded in {stopwatch.ElapsedMilliseconds}ms.");
                }
            }
            if (!settings.HasFlag(FormExPlusSettings.FadeIn))
            {
                return(form);
            }
            form.Shown += (sender, e) => FadeIn(form);
            return(form);
        }
コード例 #2
0
        /// <summary>
        ///     Determines special settings for the specified <see cref="Form"/>.
        ///     <para>
        ///         Hint: This function should be called before the <see cref="Form"/> is created.
        ///     </para>
        /// </summary>
        /// <param name="form">
        ///     The form window to determine the settings.
        /// </param>
        /// <param name="settings">
        ///     The settings to be applied.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     form is null.
        /// </exception>
        public static Form Plus(this Form form, FormExPlusSettings settings = FormExPlusSettings.LogLoadingTime)
        {
            if (form == null)
            {
                throw new ArgumentNullException(nameof(form));
            }
            if (Log.DebugMode <= 0 || !settings.HasFlag(FormExPlusSettings.LogLoadingTime))
            {
                return(form);
            }
            try
            {
                if (Application.OpenForms.OfType <Form>().Any(x => x == form))
                {
                    return(form);
                }
            }
            catch (Exception ex) when(ex.IsCaught())
            {
                return(form);
            }
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            form.Shown += delegate
            {
                stopwatch.Stop();
                Log.Write($"Stopwatch: {form.Name} loaded in {stopwatch.ElapsedMilliseconds}ms.");
            };
            return(form);
        }