示例#1
0
        /// <summary>
        /// マイナス数値の記号表現を設定するためのユーザーコントロールを表示します。
        /// </summary>
        /// <param name="context">ITypeDescriptorContext オブジェクト。</param>
        /// <param name="provider">IServiceProvider オブジェクト。</param>
        /// <param name="value">object オブジェクト。</param>
        /// <returns>プロパティ値。</returns>
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context,
                                         IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService editorService = null;

            // MSDN UI 型エディターの実装 に基づいた記述
            if (provider != null)
            {
                editorService = provider.GetService(
                    typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
            }

            // MSDN UI 型エディターの実装 に基づいた記述
            if (editorService == null)
            {
                return(value);
            }

            using (NumericNegativePatternControl nnpc = new NumericNegativePatternControl(
                       (NumericNegativePattern)value))
            {
                var curentNumberPattern    = nnpc.NumericNegativePattern.NumberNegativePattern;
                var currentCurrencyPattern = nnpc.NumericNegativePattern.CurrencyNegativePattern;
                var currentPercentPattern  = nnpc.NumericNegativePattern.PercentNegativePattern;

                editorService.DropDownControl(nnpc);

                // 呼び出し前と値が変更なければそのまま返却
                if (nnpc.NumericNegativePattern.NumberNegativePattern == curentNumberPattern &&
                    nnpc.NumericNegativePattern.CurrencyNegativePattern == currentCurrencyPattern &&
                    nnpc.NumericNegativePattern.PercentNegativePattern == currentPercentPattern)
                {
                    return(nnpc.NumericNegativePattern);
                }

                // 呼び出し前と値の変更があった場合、新規オブジェクトとして返却
                var result = new NumericNegativePattern();
                result.NumberNegativePattern   = nnpc.NumericNegativePattern.NumberNegativePattern;
                result.CurrencyNegativePattern = nnpc.NumericNegativePattern.CurrencyNegativePattern;
                result.PercentNegativePattern  = nnpc.NumericNegativePattern.PercentNegativePattern;
                return(result);
            }
        }
        /// <summary>
        /// NumericNegativePatternControl クラスの新しいインスタンスを初期化します。
        /// </summary>
        /// <param name="nnp">NumericNegativePattern オブジェクト。</param>
        public NumericNegativePatternControl(NumericNegativePattern nnp)
            : this()
        {
            NumericNegativePattern = nnp;

            // コンボボックスのリストを設定するとNumericNegativePatternオブジェクト内の設定値も
            // 変わってしまうため、表示直後のパターンを保持して、リスト設定後に差し替える
            var currentNumberPattern   = nnp.NumberNegativePattern;
            var currentCurrencyPattern = nnp.CurrencyNegativePattern;
            var currentPpercentPattern = nnp.PercentNegativePattern;

            setNumberList();
            setCurrencyList();
            setPercentList();

            comboNPattern.SelectedValue = currentNumberPattern;
            comboCPattern.SelectedValue = currentCurrencyPattern;
            comboPPattern.SelectedValue = currentPpercentPattern;
        }