/// <summary> /// Show progress message /// </summary> /// <param name="caption"></param> /// <param name="title"></param> /// <param name="allowCancel"></param> /// <param name="cancellingMessage"></param> void ShowInstance( string caption, string title, bool allowCancel, string cancellingMessage) { LastUpdateTime = TimeOfDay.Milliseconds(); //SystemUtil.Beep(); // debug if (Debug) { ClientLog.Message("Progress - Show: " + caption); } //bool disabled = true; // debug //if (disabled) return; if (!SS.I.Attended) { ClientLog.Message("Show: " + caption); return; } if (!Lex.IsNullOrEmpty(ScriptLog.FileName)) { ScriptLog.Message("Progress.Show: " + caption); } if (Lex.IsNullOrEmpty(caption)) // hide if no caption { Progress.Hide(); return; } bool sameMessage = Visible && Text == title && Caption.Text == caption && Cancel.Enabled == allowCancel && CancellingMessage.Text == cancellingMessage; //if (sameMessage) return; if (Debug) { ClientLog.Message("Progress - Show 2"); } // Adjust size of form to fit number of lines Size s2 = new Size(OriginalFormSize.Width, OriginalFormSize.Height); LexLineMetrics llm = Lex.AnalyzeLines(caption); int lineCnt = (llm.LineCnt > OriginalLines) ? llm.LineCnt : OriginalLines; // lines to display? int newCaptionHeight = (int)(lineCnt * (OriginalCaptionSize.Height / (OriginalLines * 1.0) + .5)); s2.Height = OriginalFormSize.Height + (newCaptionHeight - OriginalCaptionSize.Height); int lineLength = (llm.LongestLine > OriginalCharsPerLine) ? llm.LongestLine : OriginalCharsPerLine; // longer lines? int newCaptionWidth = (int)(llm.LongestLine * (OriginalCaptionSize.Width / (OriginalCharsPerLine * 1.0) + .5)); s2.Width = OriginalFormSize.Width + (newCaptionWidth - OriginalCaptionSize.Width); if (Height < s2.Height) { Height = s2.Height; // enlarge if necessary } if (Width < s2.Width) { Width = s2.Width; } // Fill in the form Text = title; Caption.Text = caption; Cancel.Enabled = allowCancel; CancellingMessage.Text = cancellingMessage; Refresh(); // force update of dialog if (SessionManager.ActiveForm == GetInstance()) // if this progress form is the active form then be sure it's visible { try { BringToFront(); Activate(); Focus(); //Application.DoEvents(); Showing = true; } catch (Exception ex) { ClientLog.Message("Show exception: " + DebugLog.FormatExceptionMessage(ex)); } } else if (!Showing) { try { //CenterToScreen(); Form owner = OwnerFormToUse; if (owner == null) { owner = SessionManager.ActiveForm; // if not defined get from session manager } Show(owner); // show the form, note: non-modal so we can return immediately to caller Showing = true; } catch (InvalidOperationException opEx) { ClientLog.Message("Show exception 1: " + DebugLog.FormatExceptionMessage(opEx)); // apparently something strange happened with focus... Try to recover gracefully Form shellForm = null; foreach (Form form in Application.OpenForms) { Type type = form.GetType(); if (type.FullName == "Mobius.Client.Shell") { shellForm = form; break; } } if (shellForm != null && !shellForm.Visible) { try { //Instance.CenterToScreen(); GetInstance().Show(shellForm); } catch (Exception ex) { ClientLog.Message("Instance.Show exception: " + DebugLog.FormatExceptionMessage(ex)); } } } catch (Exception ex) // some other error { string msg = "Show exception 2: "; if (SessionManager.ActiveForm != null) { msg += "ActiveForm: " + SessionManager.ActiveForm.Text + " "; } msg += DebugLog.FormatExceptionMessage(ex); ClientLog.Message(msg); } PerShowCancelRequestedFlag = false; } return; }