通过插件向应用程序(特别是Ellie Mae Encompass)添加一个面板。

时间:2017-11-13 19:13:33

标签: c# panel

我希望在Encompass应用程序中添加一个右面板菜单,以便在贷款时显示其他数据。我有一个朋友给我以下代码作为起点,但我迷路了(不确定我是否缺少参考文献等)。我是一个非常新手的程序员,从比我更好的人那里查看代码。因此,任何帮助实现这一目标的帮助都将受到赞赏!

using System;
using EllieMae.Encompass.ComponentModel;
using EllieMae.Encompass.Automation;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;


namespace RightPanel
{

    [Plugin]
    public class RightPanel
    {
        private Form mainForm;
        private TabControl _tabs;
        private bool _created;
        private Panel rightPanel;


        public RightPanel()
        {
            EncompassApplication.Login += new EventHandler(EncompassApplication_Login);
        }
        private void EncompassApplication_Login(object sender, EventArgs e)
        {
            foreach (Form form in Application.OpenForms)
            {
                if (form.Text.ToLower().Contains("encompass"))
                {
                    mainForm = form;
                }
            }

            Control[] controlArray = mainForm.Controls.Find("tabControl", true);
            if ((uint)((IEnumerable<Control>)controlArray).Count<Control>() <= 0U)
                return;

            _tabs = controlArray[0] as TabControl;
            _tabs.SelectedIndexChanged += new EventHandler(SelectedIndex_Changed);
        }

        private void SelectedIndex_Changed(object sender, EventArgs e)
        {
            if (_tabs.SelectedIndex < 0)
                return;
            TabPage tabPage = _tabs.TabPages[_tabs.SelectedIndex];
            if (tabPage != null && (tabPage.Name.Contains("loanTabPage")))
                BindToRightPanel();
        }

        private void BindToRightPanel()
        {
            if (_created)
                return;
            Control[] controlArray = mainForm.Controls.Find("rightPanel", `enter code here`true);
            if (((IEnumerable<Control>)controlArray).Count() > 0)
            {
                rightPanel = controlArray[0] as Panel;
                CreateMenu();
            }
        }

        private void CreateMenu()
        {
            if (mainForm == null)
                return;

            RemoveControlById(Settings.MainMenu, rightPanel);
            RemoveControlById(Settings.MenuButtonPanel, rightPanel);

            MenuButton menuButton = GetMenuButton("Open Loan Tools", "MtgMenuButton");
            menuButton.BackColor = Color.White;

            MenuPanel = new MenuPanel(Settings.GetMenu(), menuButton);
            MenuPanel.Name = Settings.MainMenu;
            MenuPanel.Dock = DockStyle.Right;

            Panel panel = new Panel();
            panel.Name = Settings.MenuButtonPanel;
            panel.Width = 27;
            panel.Dock = DockStyle.Right;
            panel.Controls.Add((Control)menuButton);

            rightPanel.Controls.Add((Control)MenuPanel);
            rightPanel.Controls.Add((Control)panel);
            _created = true;
        }

        private List<MenuPanelSection> GetMenu()
        {
            return new List<MenuPanelSection>()
      {  new MenuPanelSection(Utilities.GetHeading("Loan Information"), Utilities.HighestWeightedPersona() == "Loan Officer", new Control[1]
        {
          (Control) new LoanInformation()
        })
      };
        }

        private void RemoveControlById(string controlID, Panel panel)
        {
            Control[] controlArray = panel.Controls.Find(controlID, true);
            if ((uint)((IEnumerable<Control>)controlArray).Count<Control>() <= 0U)
                return;

            for (int i = 0; i < ((IEnumerable<Control>)controlArray).Count<Control>(); ++i)
                controlArray[i].Parent.Controls.Remove(controlArray[i]);
        }

        private MenuButton GetMenuButton(string buttonText, string buttonName)
        {
            MenuButton menuButton = new MenuButton();
            menuButton.AutoSize = true;
            menuButton.FlatAppearance.BorderSize = 0;
            menuButton.FlatStyle = 0;
            menuButton.Height = 100;
            menuButton.Name = buttonName;
            menuButton.VerticalText = buttonText;
            menuButton.Width = 27;

            return menuButton;
        }
    }

1 个答案:

答案 0 :(得分:0)

这行代码在上面的示例中出现了几次:

Control[] controlArray = mainForm.Controls.Find("rightPanel", true);

Controls.Find函数只接受一个参数,即您要查找的控件的名称,它只返回该控件(如果找到),而不是控件数组。

将上述行更改为此将纠正该问题。

Control control = mainForm.Controls.Find("rightPanel");

Ellie Mae提供了自己的表单对象和控件,可以在应用程序中使用。删除对System.Windows.Forms的引用并添加:

using Elliemae.Encompass.Forms;

我没有尝试运行代码,这是我通过您提供的示例查找的内容。如果您有更具体的错误,我可以帮助您完成这些错误。