Пример #1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            //load available components
            if (!DesignMode)
            {
                new CompositionContainer(new DirectoryCatalog(m_CatalogPath)).ComposeParts(this);
            }
            else
            {
                m_ComponentFactories = new List <ExportFactory <T, TMetaData> >();
            }
            int colIdx = 0;
            int rowIdx = 0;

            if (m_ComponentFactories.Count == 1)
            {
                //only one component, select it!
                ComponentSelected?.Invoke(this, m_ComponentFactories.First());
                return;
            }
            foreach (ExportFactory <T, TMetaData> factory in m_ComponentFactories)
            {
                if (colIdx != 0 && rowIdx == 0)
                {
                    MainLayout.ColumnCount++;
                    MainLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent));
                    //adjust width
                    foreach (ColumnStyle column in MainLayout.ColumnStyles)
                    {
                        column.Width = 1.0f / MainLayout.ColumnCount;
                    }
                }
                Button btn = new Button
                {
                    Text   = factory.Metadata.Name,
                    Anchor = AnchorStyles.None,
                    Width  = 80,
                    Height = 50,
                    Tag    = factory
                };
                btn.Click += OnClick;
                MainLayout.Controls.Add(btn, colIdx, rowIdx);
                if (++colIdx >= c_MaxColumns)
                {
                    colIdx = 0;
                    //TODO: Handle pages!
                    rowIdx++;
                    MainLayout.RowCount++;
                    MainLayout.RowStyles.Add(new RowStyle(SizeType.Percent));
                    //adjust height
                    foreach (RowStyle row in MainLayout.RowStyles)
                    {
                        row.Height = 1.0f / MainLayout.RowCount;
                    }
                }
            }
        }
Пример #2
0
        private void OnButtonClick(object sender, EventArgs e)
        {
            try
            {
                if (!(sender is Button btn))
                {
                    return;
                }
                Guid guid = (Guid)btn.Tag;

                ComponentSelected?.Invoke(this, new PluginEventArgs(guid));
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                _log.Debug(ex.ToString());
            }
        }
Пример #3
0
 private void ComponentSelectedHandler(object sender, ComponentEventArgs e)
 {
     ComponentSelected?.Invoke(sender, e);
 }
Пример #4
0
 private void OnClick(object sender, EventArgs e)
 {
     ComponentSelected?.Invoke(this, (sender as Button).Tag as ExportFactory <T, TMetaData>);
 }