仅在隐藏表单时显示弹出窗口

时间:2018-10-11 11:30:56

标签: c# .net winforms sockets console-application

基本上,我正在使用的程序是一个C#控制台应用程序,它通过套接字监听请求。建立连接后,它将调用并显示一个名为 frmPdfViewer 的Windows窗体。

frmPdfViewer 中,有一个名为 Sign 的ToolStripMenuItem。单击后,它应显示一个签名弹出窗口,供用户签名。

现在,我的问题是,当我单击 Sign ToolStripMenuItem时,表单冻结,并且不显示签名弹出窗口。没有引发任何错误或异常,它只是冻结。但是,当我单击 Sign 后尝试隐藏 frmPdfViewer 时,会出现签名弹出窗口。

为什么会有这种行为?

这是套接字代码的片段(在内部 ProcReq()方法是调用表单的地方):

        var wsURI = ConfigurationManager.AppSettings["wsURI"];
        var id = ConfigurationManager.AppSettings["id"];
        var ns = ConfigurationManager.AppSettings["namespace"];
        var type = ConfigurationManager.AppSettings["type"];

        var socket = IO.Socket(wsURI + "/" + ns);

        socket.On(Socket.EVENT_CONNECT, () =>
        {
            // Construct Push Message for Device Registration
            JObject reg = MessageFactory.CreateRegistrationMessage(id,
            "RR_" + id, type);

            socket.Emit("peripheral/registration", JsonConvert.SerializeObject(reg));

            socket.On(ns + "/RR_" + id, (reqMsg) =>
            {
                JObject req = reqMsg as JObject;
                JObject reqHeader = (JObject)req["header"];

                RespPayload respPayload = TabletTerminal.GetInstance().ProcReq(req);

                JObject resp = new JObject();
                resp.Add("header", reqHeader);
                resp.Add("payload", JObject.FromObject(respPayload));

                var jsonResp = JsonConvert.SerializeObject(resp);

                socket.Emit(ns + "/RR_" + id, jsonResp);
            });
        })

以下是ProcReq方法的代码段(将在此处调用表单):

public SignatureRespPayload ProcReq(JObject req)
        {
            SignatureRespPayload signatureRespPayload = new SignatureRespPayload();

            JObject reqPayload = req.GetValue("payload") as JObject;
            string name = (string)reqPayload["name"];
            string reason = (string)reqPayload["reason"];
            string pdfPath = (string)reqPayload["pdfPath"];

            frmPdfViewer pdfViewer = new frmPdfViewer(name, reason, pdfPath);
            pdfViewer.ShowDialog();
            signatureRespPayload.returnValue = pdfViewer.returnValue;

            if (signatureRespPayload.returnValue)
            {
                signatureRespPayload.signedPdfPath = pdfViewer.signedPdfPath;
            }
            else
            {
                signatureRespPayload.errorMessage = pdfViewer.errorMessage;
            }

            pdfViewer.Dispose();
            return signatureRespPayload;
        }

这是frmPdfViewer中的点击事件的代码段:

注意:,我使用的是第三方叫作Wacom签名SDK的SDK,只能查看其方法的接口而不是实现。显示签名弹出窗口的方法是 Capture()

try
        {
            SigCtl sigCtl = new SigCtl();
            sigCtl.Licence = Properties.Settings.Default.License;
            DynamicCapture dc = new DynamicCaptureClass();
            DynamicCaptureResult res = dc.Capture(sigCtl, name, reason, null, null);

            if (res == DynamicCaptureResult.DynCaptOK)
            {
                SigObj sigObj = (SigObj)sigCtl.Signature;
                String filename = System.IO.Path.GetTempFileName();
                sigObj.RenderBitmap(filename, 400, 200, "image/png", 0.5f, 0xff0000, 0xffffff, 10.0f, 10.0f, RBFlags.RenderOutputFilename | RBFlags.RenderColor32BPP | RBFlags.RenderEncodeData | RBFlags.RenderBackgroundTransparent);
                string newFile = InsertSignatureImageToPdf(filename);
                loadPdf(newFile, false);
            }
        }
        catch (Exception ex)
        {
            Console.Write(ex.StackTrace);
            MessageBox.Show(ex.Message);
        }

注意:当我在Capture()方法之前放置一个断点然后继续运行程序时,也会弹出签名弹出窗口。

1 个答案:

答案 0 :(得分:1)

显示表单后,您可以尝试添加formvariable.BringToFront()