简体   繁体   English

WinForms&Infragistics控件的readonly属性不适用于单击的控件

[英]WinForms & Infragistics controls readonly property does not work for clicked control

I wrote this code to make all controls readonly. 我编写了这段代码,使所有控件变为只读状态。

makeReadOnly(Control control, bool bIsReadOnly)
{
   for(int i=0; i< control.Controls.Count; i++)
   {
        if(control.Controls[i].Controls.Count > 0)
        {
           makeReadOnly(control.Controls[i], bIsReadOnly);
        }
        else if(control.Controls[i].GetType() == typeof(UltraTextEditor))
        {
           (control.Controls[i] as UltraTextEditor).ReadOnly = bIsReadOnly;
        }
        else if(control.Controls[i].GetType() == typeof(UltraNumericEditor))
        {
           (control.Controls[i] as UltraNumericEditor).ReadOnly = bIsReadOnly;
        }
        else if(control.Controls[i].GetType() == typeof(ListBox))
        {
           (control.Controls[i] as ListBox).Enable = !bIsReadOnly;
        }
   }
}

It works but if user clicks one control such as a textbox, then click edit button(call makeReadOnly function). 它可以工作,但是如果用户单击一个控件(例如文本框),然后单击“编辑”按钮(调用makeReadOnly函数)。 Function does not work for the clicked textbox. 该功能不适用于单击的文本框。 (It works for the other controls only). (仅适用于其他控件)。

Private void EditButton_Click()
{
     foreach(Controls control in this.controls)
     {
          makeReadOnly(control, false);
     }
}

"this" represents parent form."EditButton_Click()" is button event. “ this”表示父窗体。“ EditButton_Click()”是按钮事件。 Why it is not working for the clicked ones? 为什么对单击的人不起作用? How can I solve this problem? 我怎么解决这个问题?

I think, I found the answer. 我想,我找到了答案。 The problem is in Infragistics controls. 问题出在基础设施控件中。 When a user clicks an UltraTextEditor or UltraComboEditor controls, Infragistics changes its type to something like "EmbeddableUIText..." and its parent type becomes UltraTextEditor or UltraComboEditor. 当用户单击UltraTextEditor或UltraComboEditor控件时,Infragistics会将其类型更改为“ EmbeddableUIText ...”之类,并且其父类型将变为UltraTextEditor或UltraComboEditor。 So, I have to check this types or controls' parent types to solve it. 因此,我必须检查这种类型或控件的父类型来解决它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 水平滚动条在winforms用户控件中不起作用 - Horizontal Scrollbar does not work in winforms user control WinForms - Form.DoubleBuffered属性是否会影响对该表单的控制? - WinForms - Does the Form.DoubleBuffered property influence controls placed on that form? c#文本框ReadOnly属性有时有效,有时无效 - c# Textbox ReadOnly Property sometimes work, sometimes does not work Control.Controls属性是否以递归方式返回嵌套控件? - Does Control.Controls property return recursively nested controls? 使用C#中的滚动条获取(Infragistics Winforms 10.2)控件的内部大小 - Get internal size of an (infragistics Winforms 10.2) control with scrollbars in C# 如何在用于Winforms的Infragistics UltraGrid控件中按索引删除行? - How can I delete a row by index in an Infragistics UltraGrid control for Winforms? 绑定属性以在 Winforms 中进行控制 - Binding property to control in Winforms 在DevExpress控件中,BandedGridColumn的属性VisibleIndex不起作用 - In DevExpress Controls, the Property VisibleIndex of BandedGridColumn does not work 为什么我的属性在winforms编辑器中是只读的? - Why is my property readonly in winforms editor? 如何在Infragistics Tab控件中找出Windows窗体控件? - How to find out windows form controls inside infragistics Tab Control?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM