Exemplo n.º 1
0
        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.Visible = false;
            objAccess.OpenCurrentDatabase(@"C:\Users\Public\Database1.accdb");
            string formName = "MembersForm";

            Console.WriteLine(String.Format("The form [{0}] contains the following controls:", formName));
            objAccess.DoCmd.OpenForm(formName, Microsoft.Office.Interop.Access.AcFormView.acDesign);
            Microsoft.Office.Interop.Access.Form frm = objAccess.Forms[formName];
            foreach (Microsoft.Office.Interop.Access.Control ctl in frm.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.");
        }
Exemplo n.º 2
0
        private void toolStripDropDownButton1_DropDownOpening(object sender, EventArgs e)
        {
            toolStripDropDownButton1.DropDownItems.Clear();
            Moniker[] keys = ROTUtil.EnumRunning();
            foreach (Moniker key in keys)
            {
                Microsoft.Office.Interop.Access.Application app = (Microsoft.Office.Interop.Access.Application)ROTUtil.GetObjectAs(key, typeof(Microsoft.Office.Interop.Access.Application));
                if (app != null)
                {
                    ToolStripMenuItem subItem = new ToolStripMenuItem(key.GetDisplayName());
                    toolStripDropDownButton1.DropDownItems.Add(subItem);

                    int cx = app.Forms.Count;
                    for (int x = 0; x < cx; x++)
                    {
                        Microsoft.Office.Interop.Access.Form form = app.Forms[x];
                        ToolStripItem subSubItem = subItem.DropDownItems.Add(form.Name);
                        subSubItem.Click += new EventHandler(subSubItem_Click);
                        subSubItem.Tag    = form;
                    }
                }
            }
        }
Exemplo n.º 3
0
        void selectForm(Microsoft.Office.Interop.Access.Form form)
        {
            panelMain.Controls.Clear();
            selec = null;

            if (form.CurrentView != 0)
            {
                if (MessageBox.Show("選択されたフォームは、現在デザインビューの為に起動されていません。デザインビューに切り替えないと、変更は保存されません。\n\nいますぐ切り替えますか。", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    string name = form.Name;
                    form.Application.DoCmd.OpenForm(
                        form.Name,
                        Microsoft.Office.Interop.Access.AcFormView.acDesign,
                        null,
                        null,
                        Microsoft.Office.Interop.Access.AcFormOpenDataMode.acFormPropertySettings,
                        Microsoft.Office.Interop.Access.AcWindowMode.acWindowNormal,
                        null
                        );
                    form = form.Application.Forms[name];
                }
            }

            List <Control> box = new List <Control>();
            SortedDictionary <int, Point> sec2pos = new SortedDictionary <int, Point>();

            if (true)
            {
                Microsoft.Office.Interop.Access._Section sec;
                int si, y = 0;

                try {
                    sec         = form.get_Section(si = (int)Microsoft.Office.Interop.Access.AcSection.acHeader);
                    sec2pos[si] = new Point(0, y);
                    y          += sec.Height;
                }
                catch (COMException err) {
                    if (err.ErrorCode == -2146825826)   // {"セクション番号の指定が正しくありません。"}
                    {
                    }
                    else
                    {
                        throw;
                    }
                }

                sec         = form.get_Section(si = (int)Microsoft.Office.Interop.Access.AcSection.acDetail);
                sec2pos[si] = new Point(0, y);
                y          += sec.Height;

                try {
                    sec         = form.get_Section(si = (int)Microsoft.Office.Interop.Access.AcSection.acFooter);
                    sec2pos[si] = new Point(0, y);
                    y          += sec.Height;
                }
                catch (COMException err) {
                    if (err.ErrorCode == -2146825826)   // {"セクション番号の指定が正しくありません。"}
                    {
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            int cz = form.Controls.Count;

            for (int z = 0; z < cz; z++)
            {
                Microsoft.Office.Interop.Access.Control src = (Microsoft.Office.Interop.Access.Control)form.Controls[z];
                Point pos      = sec2pos[Convert.ToInt32(COMUtil.GetProperty(src, "Section"))];
                int   x        = Convert.ToInt32(COMUtil.GetProperty(src, "Left")) + pos.X;
                int   y        = Convert.ToInt32(COMUtil.GetProperty(src, "Top")) + pos.Y;
                int   cx       = Convert.ToInt32(COMUtil.GetProperty(src, "Width"));
                int   cy       = Convert.ToInt32(COMUtil.GetProperty(src, "Height"));
                int   tabIndex = Convert.ToInt32(COMUtil.GetProperty(src, "TabIndex", -1));
                Label c        = new Label();
                c.Location    = new Point(MeasureUtil.PosToPix(x), MeasureUtil.PosToPix(y));
                c.Size        = new Size(MeasureUtil.PosToPix(cx), MeasureUtil.PosToPix(cy));
                c.Text        = "" + tabIndex;
                c.TextAlign   = ContentAlignment.MiddleCenter;
                c.Visible     = true;
                c.BorderStyle = BorderStyle.FixedSingle;
                c.Tag         = src;
                c.TabIndex    = (tabIndex < 0) ? 10000 : tabIndex;
                c.MouseDown  += new MouseEventHandler(c_MouseDown);
                if (tabIndex >= 0)
                {
                    c.BackColor = clrAvail;
                }
                box.Insert(0, c);
            }
            panelMain.Controls.AddRange(box.ToArray());
        }
Exemplo n.º 4
0
 void subSubItem_Click(object sender, EventArgs e)
 {
     Microsoft.Office.Interop.Access.Form form = (Microsoft.Office.Interop.Access.Form)((ToolStripItem)sender).Tag;
     selectForm(form);
 }