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; } } } }
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()); } }
private void ComponentSelectedHandler(object sender, ComponentEventArgs e) { ComponentSelected?.Invoke(sender, e); }
private void OnClick(object sender, EventArgs e) { ComponentSelected?.Invoke(this, (sender as Button).Tag as ExportFactory <T, TMetaData>); }