Previous topicNext topic
Help > 开发指南 > 数据处理典型场景 > 表格常规操作 >
手动控制子窗口动态生成的控件

有时候我们需要对弹出的通用子窗口中动态生成的控件进行一些细微的控制,比如修改一些属性,动态绑定一些事件对控件进行一些自定义控制等等。那么我们该如何获得相应的控件,并进行自定义呢?下面我们就介绍一下我们该如何做。

我们只需要到全局窗体事件AfterLoad里面写代码即可。

Vb.Net
'获得当前窗体
Dim frm As SmForm=sender
'判断当前窗体是否我们是我们要处理的窗体
If frm.Name="我的子窗体" AndAlso TypeOf sender Is FormEditSubForm Then
    '转换成FormEditSubForm子窗体类型
    Dim frmSub As FormEditSubForm=sender
    '根据列名称获得指定的Box控件
    Dim boxTime As ICaptionControl= frmSub.GridFieldControls.BoxControls("列名称")
    '根据需要,针对Box控件的BaseControl进行相应属性设置
    If TypeOf boxTime.BaseControl Is C1TextBox Then
        Dim time As C1TextBox= boxTime.BaseControl
        '设置编辑时的格式
        time.EditFormat.FormatType=FormatTypeEnum.CustomFormat
        time.EditFormat.CustomFormat="yyyy-MM-dd HH:mm"
        '设置显示时的格式
        time.DisplayFormat.FormatType=FormatTypeEnum.CustomFormat
        time.DisplayFormat.CustomFormat="yyyy-MM-dd HH:mm"
    End If
End If

C#
// 获得当前窗体
SmForm frm = sender;
// 判断当前窗体是否我们是我们要处理的窗体
if (frm.Name == "我的子窗体" && sender is FormEditSubForm)
{
    // 转换成FormEditSubForm子窗体类型
    FormEditSubForm frmSub = sender;
    // 根据列名称获得指定的Box控件
    ICaptionControl boxTime = frmSub.GridFieldControls.BoxControls["列名称"];
    // 根据需要,针对Box控件的BaseControl进行相应属性设置
    if (boxTime.BaseControl is C1TextBox)
    {
        C1TextBox time = boxTime.BaseControl;
        // 设置编辑时的格式
        time.EditFormat.FormatType = FormatTypeEnum.CustomFormat;
        time.EditFormat.CustomFormat = "yyyy-MM-dd HH:mm";
        // 设置显示时的格式
        time.DisplayFormat.FormatType = FormatTypeEnum.CustomFormat;
        time.DisplayFormat.CustomFormat = "yyyy-MM-dd HH:mm";
    }
}