English 中文(简体)
将所有RichTextBoxes打成一个表格(VB.NET)
原标题:Clearing all RichTextBoxes on a form (VB.NET)
  • 时间:2009-11-17 09:10:39
  •  标签:
  • .net

我设立了由25个RichTextBox控制的表格。 我需要把他们全部放在一个 but子点上(在座所有案文中删除)。

我试图从方案上获得控制,但可以这样做。 我只需要每个RichTextBox填写表格。

任何代码样本都会是巨大的,感谢你。

最新资料:我写道:

    For Each oControl As Control In Me.Controls
        If TypeOf oControl Is RichTextBox Then
            oControl.Clear()
        End If
    Next

但出于某种原因,它没有工作。

问题回答

RichTextBox.Clear(?

您能以您的形式对每一项控制进行调节(使用<条码>)。 MyBase.Controls,并检查其是否为,然后称作Clear()

表格的控制可以通过控制财产进行。 问题在于,其中一些管制可以是集装箱管制,而后者又可以控制其他管制。

在C#中,就是一个大致的例子(在VB中,我不会流利;我希望你能找到想法):

void ClearRichTextBoxes(ContainerControlcontainer)
{
    foreach(var control in Controls) {
        if(control is ContainerControl) {
            ClearRichTextBoxes(control);
        } else if(control is RichTextBox) {
            ((RichTextBox)control).Clear();
        }
    }
}

您将引用<代码>ClearRichTextBoxes(form)。

www.un.org/Depts/DGACM/index_spanish.htm 这是错误的。 你们不需要修复被nes塞的集装箱。 http://msdn.microsoft.com/en-us/library/system.windows.forms.controls.aspx”rel=“nofollow noreferer”>MSDN:

Use the Controls property to iterate through all controls of a form, including nested controls.

因此,上述代码应当删除<代码>(如果控制是集装箱管制”){......}其他部分。

你们用什么代码来逐字利用RichTextBox控制方案? 上文提到的Johannes的回答应当奏效。 你们可以控制收集和检查“Of”(Of)类,并使用明确的()方法。

这是非常令人厌恶的,我刚刚尝试以简单的形式复制这一问题,其中包括3个RichTextBoxes。 其中一个箱子生活在一个小组内,另一个箱子是doesn t。 对照方法的每项控制,见<代码>。

这是奇怪的,因为正如其他人已经说过的那样,它应当发挥作用。

在此,我的解决办法是:明确重新控制表格中的所有控制(本身也是控制)。 表格是控制。

执行:

 If a control has a collection of sub-controls, it s a container.
 In this case: recurse over its children until you hit a child without sub-controls.
 Then check if it s a (rich)TextBox and clear.
Private Sub ClearControl(ByVal ctrl As Control)

    If ctrl.Controls.Count > 0 Then
        For Each subCtrl As Control In ctrl.Controls
            ClearControl(subCtrl)
        Next
    End If

    If TypeOf ctrl Is RichTextBox Then
        DirectCast(ctrl, RichTextBox).Clear()
    End If

     You can clear other types of controls in here as well
    If TypeOf ctrl Is TextBox Then
       DirectCast(ctrl, TextBox).Clear()
    End If
     etcetera...

End Sub

我希望你能这样做。





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签