From 04ff92a964a83af11d2f8e35e52021fb095bf8b9 Mon Sep 17 00:00:00 2001 From: yibo <361071264@qq.com> Date: Thu, 29 Mar 2018 23:35:32 +0800 Subject: [PATCH] little change --- WinFormControl/UScanPanel.cs | 11 ++++++++--- WinFormControl/UWeightControl.cs | 15 ++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/WinFormControl/UScanPanel.cs b/WinFormControl/UScanPanel.cs index 4930267..df4d160 100644 --- a/WinFormControl/UScanPanel.cs +++ b/WinFormControl/UScanPanel.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using WinFormControl.Converter; namespace WinFormControl { @@ -32,9 +33,13 @@ namespace WinFormControl protected override void OnLoad(EventArgs e) { base.OnLoad(e); - if (!ParentForm.KeyPreview) - ParentForm.KeyPreview = true; - ParentForm.KeyPress += ParentForm_KeyPress; + var parentForm = ControlUtil.GetParentFormm(this); + if (parentForm != null) + { + if (!parentForm.KeyPreview) + parentForm.KeyPreview = true; + parentForm.KeyPress += ParentForm_KeyPress; + } } bool reading = false; diff --git a/WinFormControl/UWeightControl.cs b/WinFormControl/UWeightControl.cs index 5107448..a6f3d53 100644 --- a/WinFormControl/UWeightControl.cs +++ b/WinFormControl/UWeightControl.cs @@ -11,6 +11,7 @@ using WinFormControl.Properties; using System.Threading; using System.IO.Ports; using System.Collections.Concurrent; +using WinFormControl.Converter; namespace WinFormControl { @@ -42,13 +43,17 @@ namespace WinFormControl protected override void OnLoad(EventArgs e) { base.OnLoad(e); - ParentForm.FormClosing += delegate + var parentForm = ControlUtil.GetParentFormm(this); + if (parentForm != null) { - if (_inQueryThread != null && _inQueryThread.IsAlive) + parentForm.FormClosing += delegate { - DisableWeight(); - } - }; + if (_inQueryThread != null && _inQueryThread.IsAlive) + { + DisableWeight(); + } + }; + } } private void settingBtn_Click(object sender, EventArgs e)