//Adds a scale bar element to the layout and if there is already a map on the form we link it to the first one private void _btnScaleBar_Click(object sender, EventArgs e) { LayoutScaleBar lsb = _layoutControl.CreateScaleBarElement() as LayoutScaleBar; List <LayoutElement> mapElements = _layoutControl.LayoutElements.FindAll(delegate(LayoutElement o) { return(o is LayoutMap); }); if (mapElements.Count > 0) { lsb.Map = mapElements[0] as LayoutMap; } lsb.LayoutControl = _layoutControl; _layoutControl.AddElementWithMouse(lsb); }
/// <summary> /// Edits a value based on some user input which is collected from a character control. /// </summary> /// <param name="context">Contains the scalebar and legend.</param> /// <param name="provider">The service provider.</param> /// <param name="value">The selected item.</param> /// <returns>Returns the selected item.</returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { _dialogProvider = provider?.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService; if (context == null) { return(null); } LayoutScaleBar scaleBar = context.Instance as LayoutScaleBar; LayoutLegend legend = context.Instance as LayoutLegend; LayoutControl lc = null; if (scaleBar?.LayoutControl != null) { lc = scaleBar.LayoutControl; } else if (legend?.LayoutControl != null) { lc = legend.LayoutControl; } ListBox lb = new(); if (lc == null) { return(null); } foreach (LayoutElement le in lc.LayoutElements.FindAll(o => o is LayoutMap)) { lb.Items.Add(le); } lb.SelectedItem = value; lb.SelectedValueChanged += LbSelectedValueChanged; _dialogProvider?.DropDownControl(lb); return(lb.SelectedItem); }