예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="provider"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService editorService = null;

            if (provider != null)
            {
                editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
            }

            if (editorService == null)
            {
                return(value);
            }

            EnvelopeEditorAttribute env = (EnvelopeEditorAttribute)context.PropertyDescriptor.Attributes[typeof(EnvelopeEditorAttribute)];

            // CurrencyValueEditorForm を使用したプロパティエディタの表示
            using (FormEnvelopeEditor frm = new FormEnvelopeEditor((string)value, env.Min, env.Max))
            {
                frm.ValueChanged += Frm_ValueChangedByte;
                frm.Tag           = context;

                DialogResult dr = editorService.ShowDialog(frm);
                if (dr == DialogResult.OK)
                {
                    value = frm.EnvelopeValuesText;
                }
                else if (value != null)
                {
                    value = new StringBuilder((string)value).ToString();
                }

                return(value);
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Frm_ValueChangedByte(object sender, EventArgs e)
        {
            FormEnvelopeEditor     editor = (FormEnvelopeEditor)sender;
            ITypeDescriptorContext ctx    = (ITypeDescriptorContext)editor.Tag;

            if (ctx != null)
            {
                var value = editor.EnvelopeValuesText;
                try
                {
                    //InstrumentManager.ExclusiveLockObject.EnterWriteLock();

                    ctx.PropertyDescriptor.SetValue(ctx.Instance, value);
                }
                finally
                {
                    //InstrumentManager.ExclusiveLockObject.ExitWriteLock();
                }
            }
        }