Camera.Display.DisplayForm.CloseForm(sender, args) added, no conflict with other modeless forms, ver. 2.14.613
This commit is contained in:
@@ -8,6 +8,5 @@ namespace TBF.BenchControl.GenericDevices
|
|||||||
interface IHasCompleted
|
interface IHasCompleted
|
||||||
{
|
{
|
||||||
bool Completed { get; }
|
bool Completed { get; }
|
||||||
void StartForceCloseHandler();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,20 +55,20 @@ namespace TBF.BenchControl.Network.Camera.Display
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
System.Windows.Forms.Form modelessDlg;
|
DisplayForm displayForm;
|
||||||
///
|
///
|
||||||
delegate void DisplayFormDlgt(Display myRef);
|
delegate void DisplayFormDlgt(Display myRef);
|
||||||
///
|
///
|
||||||
void OpenStaticImageDisplay(Display myRef)
|
void OpenStaticImageDisplay(Display myRef)
|
||||||
{
|
{
|
||||||
myRef.modelessDlg = new DisplayForm(imageFileNames, title);
|
myRef.displayForm = new DisplayForm(imageFileNames, title);
|
||||||
modelessDlg.Show();
|
displayForm.Show();
|
||||||
}
|
}
|
||||||
///
|
///
|
||||||
void OpenLiveStreamDisplay(Display myRef)
|
void OpenLiveStreamDisplay(Display myRef)
|
||||||
{
|
{
|
||||||
myRef.modelessDlg = new DisplayForm(imageFileNames, title);
|
myRef.displayForm = new DisplayForm(imageFileNames, title);
|
||||||
modelessDlg.Show();
|
displayForm.Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -120,17 +120,17 @@ namespace TBF.BenchControl.Network.Camera.Display
|
|||||||
/// <returns>Event.None</returns>
|
/// <returns>Event.None</returns>
|
||||||
public Event Run()
|
public Event Run()
|
||||||
{
|
{
|
||||||
if ((modelessDlg is IHasCompleted) && !(modelessDlg as IHasCompleted).Completed)
|
if (displayForm.Completed)
|
||||||
{
|
{
|
||||||
return Event.ModelessFormIsOpen;
|
return Event.ModelessFormIsOpen;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((result == DialogResult.None) && modelessDlg is DisplayForm)
|
if (result == DialogResult.None)
|
||||||
{
|
{
|
||||||
/// Save the result (once)
|
/// Save the result (once)
|
||||||
selectedImages = (modelessDlg as DisplayForm).SelectedImages;
|
selectedImages = displayForm.SelectedImages;
|
||||||
result = (modelessDlg as DisplayForm).Result;
|
result = displayForm.Result;
|
||||||
modelessDlg = null;
|
displayForm = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result == DialogResult.OK) return Event.OK;
|
if (result == DialogResult.OK) return Event.OK;
|
||||||
@@ -142,10 +142,10 @@ namespace TBF.BenchControl.Network.Camera.Display
|
|||||||
/// <summary>Stop this operation</summary>
|
/// <summary>Stop this operation</summary>
|
||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
if (modelessDlg is IHasCompleted)
|
if (displayForm != null)
|
||||||
{
|
{
|
||||||
UiBridge.Bridge.OnCloseModelessForm(this, null);
|
displayForm.CloseForm(this, null);
|
||||||
modelessDlg = null;
|
displayForm = null;
|
||||||
}
|
}
|
||||||
currentOp = CurrentOp.None;
|
currentOp = CurrentOp.None;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,36 @@ namespace TBF.BenchControl.Network.Camera.Display
|
|||||||
{
|
{
|
||||||
private static readonly ILog log = LogManager.GetLogger(typeof(DisplayForm));
|
private static readonly ILog log = LogManager.GetLogger(typeof(DisplayForm));
|
||||||
|
|
||||||
|
#region Closing this display from another thread
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called from the state machine when an operation forces a modeless dialog close.
|
||||||
|
/// </summary>
|
||||||
|
public void CloseForm(object sender, EventArgs args)
|
||||||
|
{
|
||||||
|
if (CloseFormHandler == null) return;
|
||||||
|
try { CloseFormHandler(sender, null); }
|
||||||
|
catch (Exception e) { log.Error("CloseFormHandler(...) failed", e); }
|
||||||
|
}
|
||||||
|
public event EventHandler<EventArgs> CloseFormHandler;
|
||||||
|
|
||||||
|
public void StartCloseFormHandler()
|
||||||
|
{
|
||||||
|
CloseFormHandler += delegate(object sender, EventArgs args)
|
||||||
|
{
|
||||||
|
if (InvokeRequired) { Invoke(new EventHandler<EventArgs>(OnCloseForm), sender, args); }
|
||||||
|
else OnCloseForm(sender, args);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCloseForm(object sender, EventArgs args)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
/// <summary> Number of text boxes for serial numbers </summary>
|
/// <summary> Number of text boxes for serial numbers </summary>
|
||||||
readonly string[] imageFileNames;
|
readonly string[] imageFileNames;
|
||||||
readonly int imagesCount;
|
readonly int imagesCount;
|
||||||
@@ -75,7 +105,7 @@ namespace TBF.BenchControl.Network.Camera.Display
|
|||||||
|
|
||||||
Result = DialogResult.None;
|
Result = DialogResult.None;
|
||||||
completed = false;
|
completed = false;
|
||||||
StartForceCloseHandler();
|
StartCloseFormHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Parameterless constructor for all watermeters </summary>
|
/// <summary> Parameterless constructor for all watermeters </summary>
|
||||||
@@ -91,7 +121,7 @@ namespace TBF.BenchControl.Network.Camera.Display
|
|||||||
abortButton.Text = Strings.Abort;
|
abortButton.Text = Strings.Abort;
|
||||||
|
|
||||||
myTimer = new Timer();
|
myTimer = new Timer();
|
||||||
myTimer.Interval = (500); // 45 mins
|
myTimer.Interval = (500);
|
||||||
myTimer.Tick += new EventHandler(MyTimer_Tick);
|
myTimer.Tick += new EventHandler(MyTimer_Tick);
|
||||||
myTimer.Start();
|
myTimer.Start();
|
||||||
}
|
}
|
||||||
@@ -112,6 +142,32 @@ namespace TBF.BenchControl.Network.Camera.Display
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void okButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Result = DialogResult.OK;
|
||||||
|
CloseAfterButtonClick();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void abortButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Result = DialogResult.Abort;
|
||||||
|
CloseAfterButtonClick();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void retryButton_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Result = DialogResult.Retry;
|
||||||
|
CloseAfterButtonClick();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CloseAfterButtonClick()
|
||||||
|
{
|
||||||
|
if (myTimer != null) myTimer.Stop();
|
||||||
|
UpdateData();
|
||||||
|
completed = true;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
|
||||||
void UpdateData()
|
void UpdateData()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < Math.Min(imagesCount, boxesCount); i++)
|
for (int i = 0; i < Math.Min(imagesCount, boxesCount); i++)
|
||||||
@@ -119,53 +175,5 @@ namespace TBF.BenchControl.Network.Camera.Display
|
|||||||
SelectedImages[i] = checkBoxes[i].Checked;
|
SelectedImages[i] = checkBoxes[i].Checked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void okButton_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (myTimer != null) myTimer.Stop();
|
|
||||||
UpdateData();
|
|
||||||
Result = DialogResult.OK;
|
|
||||||
completed = true;
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void abortButton_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (myTimer != null) myTimer.Stop();
|
|
||||||
UpdateData();
|
|
||||||
Result = DialogResult.Abort;
|
|
||||||
completed = true;
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void retryButton_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (myTimer != null) myTimer.Stop();
|
|
||||||
UpdateData();
|
|
||||||
Result = DialogResult.Retry;
|
|
||||||
completed = true;
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#region Forced close handling
|
|
||||||
|
|
||||||
public void StartForceCloseHandler()
|
|
||||||
{
|
|
||||||
UiBridge.Bridge.CloseModelessFormHandler += delegate(object sender, EventArgs args)
|
|
||||||
{
|
|
||||||
if (InvokeRequired) { Invoke(new EventHandler<EventArgs>(OnForceClose), sender, args); }
|
|
||||||
else OnForceClose(sender, args);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnForceClose(object sender, EventArgs args)
|
|
||||||
{
|
|
||||||
DialogResult = DialogResult.Cancel;
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
|||||||
// Build Number
|
// Build Number
|
||||||
// Revision
|
// Revision
|
||||||
//
|
//
|
||||||
[assembly: AssemblyVersion("2.14.612.1")]
|
[assembly: AssemblyVersion("2.14.613.1")]
|
||||||
[assembly: AssemblyFileVersion("2.14.612.1")]
|
[assembly: AssemblyFileVersion("2.14.613.1")]
|
||||||
|
|||||||
Reference in New Issue
Block a user