使用 Interop.Access 仅在页眉部分(或正文或页脚)中获取控件 [英] Using Interop.Access to get controls in just Header section (or Body or Footer)

查看:28
本文介绍了使用 Interop.Access 仅在页眉部分(或正文或页脚)中获取控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否建议如何使用 C# 中的 Microsoft.Office.Interop.Access 来获取特定 Access 表单标题部分的所有控件?

Could you advise how to use the Microsoft.Office.Interop.Access in C# to get all controls of just the header section of a specific Access form?

谢谢.

推荐答案

所有表单都会有一个 Detail 部分,并且表单会有额外的部分,例如 FormHeaderFormFooterPageHeaderSectionPageFooterSection 等,如果这些元素存在于表单中.每个部分都将有一个 Controls 集合.下面是一个例子:

All forms will have a Detail Section and forms will have additional Sections like FormHeader, FormFooter, PageHeaderSection, PageFooterSection, etc. if those elements exist in the form. Each of those Sections will have a Controls collection. Here is an example:

static void Main(string[] args)
{
    // this code requires the following COM reference in the project:
    // Microsoft Access 14.0 Object Library
    //
    var objAccess = new Microsoft.Office.Interop.Access.Application();
    objAccess.OpenCurrentDatabase(@"C:\Users\Public\Database1.accdb");

    string formName = "ClientForm";
    objAccess.DoCmd.OpenForm(formName, Microsoft.Office.Interop.Access.AcFormView.acDesign);
    Microsoft.Office.Interop.Access.Form frm = objAccess.Forms[formName];

    Console.WriteLine(String.Format("The FormHeader section of form [{0}] contains the following controls:", formName));
    foreach (Microsoft.Office.Interop.Access.Control ctl in frm.Section["FormHeader"].Controls)
    {
        Console.WriteLine();
        Console.WriteLine(String.Format("    [{0}]", ctl.Name));
        Console.WriteLine(String.Format("        {0}", ctl.GetType()));
    }
    objAccess.DoCmd.Close(Microsoft.Office.Interop.Access.AcObjectType.acForm, formName);
    objAccess.CloseCurrentDatabase();
    objAccess.Quit();

    Console.WriteLine();
    Console.WriteLine("Done.");
    Console.ReadKey();
}

控制台输出:

The FormHeader section of form [ClientForm] contains the following controls:

    [Auto_Logo0]
        Microsoft.Office.Interop.Access.ImageClass

    [Auto_Header0]
        Microsoft.Office.Interop.Access.LabelClass

Done.

这篇关于使用 Interop.Access 仅在页眉部分(或正文或页脚)中获取控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆