public static ExcelBindingDefinitionPicture CreateInstance(ExcelTemplateDefinition templateDefinition, string definition) { ExcelBindingDefinitionPicture ret = null; if (!string.IsNullOrEmpty(definition)) { try { //ExcelCheckBoxDefinition excelButtonDefinition = definition.Deserialize<ExcelCheckBoxDefinition>(); //BindingDefinitionDescription definitionDescription = BindingDefinitionDescription.CreateBindingDescription(excelButtonDefinition.Value, excelButtonDefinition.Value); //ret = new ExcelBindingDefinitionCheckBox(definitionDescription, templateDefinition, excelButtonDefinition); } catch (Exception ex) { string message = $"Cannot retrieve the checkbox dataAccessor '{definition.EmptyIfNull()}'. {ex.Message}"; throw new EtkException(message); } } return(ret); }
public ExcelContextItemPicture(IBindingContextElement parent, IBindingDefinition bindingDefinition) : base(parent, bindingDefinition) { if (bindingDefinition != null) { CanNotify = bindingDefinition.CanNotify; excelBindingDefinition = bindingDefinition as ExcelBindingDefinitionPicture; if (excelBindingDefinition != null) { objectsToNotify = excelBindingDefinition.GetObjectsToNotify(DataSource); if (objectsToNotify != null) { foreach (INotifyPropertyChanged obj in objectsToNotify) { obj.PropertyChanged += OnPropertyChanged; } } } } }
public ExcelPicture(ExcelInterop.Range range, ExcelBindingDefinitionPicture definition) { OwnerRange = range; OwnerRange.Value2 = null; ExcelInterop.Worksheet worksheet = OwnerRange.Worksheet; Name = $"ExcelCB{Interlocked.Increment(ref cpt)}"; ExcelInterop.OLEObjects oleObjects = worksheet.OLEObjects(); ExcelInterop.OLEObject oleObject = oleObjects.Add("Forms.CheckBox.1", Type.Missing, true, false, Type.Missing, Type.Missing, Type.Missing, OwnerRange.Left + 3, OwnerRange.Top + 1, 12, 12); oleObject.Name = Name; oleObject.Placement = ExcelInterop.XlPlacement.xlMove; CheckBox = worksheet.GetType().InvokeMember(Name, BindingFlags.Default | BindingFlags.GetProperty, null, worksheet, null) as ExcelForms.CheckBox; CheckBox.SpecialEffect = ExcelForms.fmButtonEffect.fmButtonEffectSunken; CheckBox.TripleState = false; CheckBox.Caption = string.Empty; CheckBox.BackColor = (int)OwnerRange.Interior.Color; CheckBox.BackStyle = ExcelForms.fmBackStyle.fmBackStyleTransparent; oleObject.Interior.ColorIndex = -4142; CheckBox.AutoSize = false; ExcelApplication.ReleaseComObject(oleObject); ExcelApplication.ReleaseComObject(oleObjects); ExcelApplication.ReleaseComObject(worksheet); oleObject = null; oleObjects = null; worksheet = null; }