コード例 #1
0
 public void Close()
 {
     var control = Control;
     if (control == null)
         return;
     Control = null;
     ServiceProvider.ThreadManager.Invoke(ExecutionMode.AsynchronousOnUiThread, control, control, (messageControl, toastMessageControl) => ClearControl(messageControl));
 }
コード例 #2
0
 private static void ClearControl(ToastMessageControl control)
 {
     control.TaskCompletionSource.TrySetResult(null);
     if (control.Parent != null)
         control.Parent.Controls.Remove(control);
     ((Timer)control.Tag).Dispose();
     control.Dispose();
 }
コード例 #3
0
 protected virtual ToastMessageControl GetToastControl(Form form, object content)
 {
     string msg = content == null ? "(null)" : content.ToString();
     var control = new ToastMessageControl(msg, Background, Foreground, Glow)
     {
         IsTransparent = true
     };
     Font font = Font;
     if (font == null)
         font = form.Font;
     else
         control.Font = font;
     using (Graphics gr = control.CreateGraphics())
     {
         SizeF textSize = gr.MeasureString(msg, font);
         control.Height = (int)textSize.Height + 25;
         control.Width = (int)textSize.Width + 35;
         if (textSize.Width > form.Width - 100)
         {
             control.Width = form.Width - 100;
             var hf = textSize.Width / control.Width;
             control.Height += (int)(textSize.Height * hf);
         }
         if (control.Height > form.Height)
             control.Height = form.Height;
     }
     return control;
 }