[英]Modal dialog button clicks won't respond for long time
我們有一個奇怪的客戶問題,無法通過開發環境重現。 我們看到它發生在客戶環境中,但我們無法在我們擁有的任何其他環境中重現它。 這使得解決問題變得困難,這就是我需要一些幫助的原因。
問題是,只要有一個帶有“確定”/“取消”按鈕的模態對話框,並且當用戶點擊其中任何一個時,該對話框需要很長時間才能響應並消失。 第二次顯示相同的對話框,點擊響應更快。 我們觀察到這主要是模態對話而不是非模態對話。
在顯示模態對話框之前我們做的一件特別的事情是我們創建一個位於主窗體和模態對話框之間的新窗體。 創建此新表單是為了提供模糊效果,以清楚地表明您必須先對模態對話框執行某些操作,然后才能返回主窗體。 這是為UI效果完成的,這里是代碼,
private void BaseModalForm_Load(object sender, EventArgs e)
{
// Some dialogs are not modal (For example Options Dialog ), still derived from BaseModalForm .. Give the blur effect only when its a modal dialog.
if (this.Modal)
{
Global.ModalDialogCount += 1;
if (Global.MainForm != null && !Global.MainForm.IsDisposed)
{
// Create the white layer which would be rendered on top of the Main Window once the modal dialog appears, to give prominence to the modal dialog
// Show the white layer only when first modal dialog is shown
if (Global.MainForm.Visible && Global.ModalDialogCount == 1)
{
CreateWhiteLayerForm();
whiteLayerForm.Show(Global.MainForm);
whiteLayerForm.Enabled = false;
}
}
}
}
private void CreateWhiteLayerForm()
{
whiteLayerForm = new Form();
int titleHeight = SystemInformation.CaptionHeight;
int borderHeight = SystemInformation.FrameBorderSize.Height;
int borderWidth = SystemInformation.FrameBorderSize.Width;
// The white layer should not cover the title bar
whiteLayerForm.Size = new System.Drawing.Size(Global.MainForm.Size.Width, Global.MainForm.Size.Height - titleHeight);
whiteLayerForm.Location = new System.Drawing.Point(Global.MainForm.Location.X , Global.MainForm.Location.Y + borderHeight + titleHeight);
whiteLayerForm.StartPosition = FormStartPosition.Manual;
whiteLayerForm.AutoScaleMode = AutoScaleMode.None;
whiteLayerForm.ShowInTaskbar = false;
whiteLayerForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
whiteLayerForm.BackColor = System.Drawing.Color.White;
whiteLayerForm.Opacity = 0.5;
}
private void BaseModalForm_FormClosed(object sender, FormClosedEventArgs e)
{
if(whiteLayerForm != null)
whiteLayerForm.Dispose();
if(this.Modal)
Global.ModalDialogCount -= 1;
}
這段代碼一直有效,直到我們在客戶環境中遇到這個奇怪的問題。 我懷疑這可能會導致點擊不響應。
但這可能是錯的。 客戶環境中的某些反病毒程序是否可能阻止點擊? 這個問題發生在那個環境中的很多人身上。
還有其他原因嗎? 有沒有人偶然遇到過這個? 任何幫助表示贊賞。 如果您需要任何其他細節,請告訴我。
原因可能是在其他應用程序中,不加區分地錯誤地設置其他應用程序的窗口對象上的掛鈎。
我在安裝了Punto Switcher的工作站上看到了同樣的情況。 嘗試擺脫鍵盤切換器,托盤內的詞典,調試工具,鍵盤記錄器,不要忘記病毒:)。
盡管使用相同的代碼,圖形渲染將花費不同的時間長度,具體取決於運行的機器和渲染應用程序,您不能假設任何圖形代碼部分將在所有設備上以最佳方式運行。
因此,此代碼非常可疑,並且應該能夠通過詢問有關已部署環境圖形系統的詳細問題來重現它。
private void CreateWhiteLayerForm()
{
whiteLayerForm = new Form();
int titleHeight = SystemInformation.CaptionHeight;
int borderHeight = SystemInformation.FrameBorderSize.Height;
int borderWidth = SystemInformation.FrameBorderSize.Width;
// The white layer should not cover the title bar
whiteLayerForm.Size = new System.Drawing.Size(Global.MainForm.Size.Width, Global.MainForm.Size.Height - titleHeight);
whiteLayerForm.Location = new System.Drawing.Point(Global.MainForm.Location.X , Global.MainForm.Location.Y + borderHeight + titleHeight);
whiteLayerForm.StartPosition = FormStartPosition.Manual;
whiteLayerForm.AutoScaleMode = AutoScaleMode.None;
whiteLayerForm.ShowInTaskbar = false;
whiteLayerForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
whiteLayerForm.BackColor = System.Drawing.Color.White;
whiteLayerForm.Opacity = 0.5;
}
您應該能夠通過將對此和其他類似方法的任何調用移動到后台線程來恢復對用戶操作的響應性,例如點擊。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.