原創(chuàng)|其它|編輯:郝浩|2013-02-04 11:07:56.000|閱讀 722 次
概述:本文的兩個實例演示了如何在DXperience Winforms Subscription文本編輯器中自定義字符格式,如大小寫轉(zhuǎn)換和十進(jìn)制轉(zhuǎn)二進(jìn)制。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
今天跟大家講一下如何在DXperience Winforms Subscription文本編輯器中自定義字符格式。一個是字符串格式的大小寫轉(zhuǎn)換,一個是將十進(jìn)制的值以二進(jìn)制的形式顯示。
本示例創(chuàng)建一個自定義格式化,以修改編輯器的文本。編輯器的顯示文本遵循指定的格式字符串,這個字符串傳遞給Format方法作為格式參數(shù)。如果這個參數(shù)值為"u",顯示值會轉(zhuǎn)換為大寫,如果格式字符串為"l",顯示值將轉(zhuǎn)換為小寫。示例代碼如下:
// A custom formatter object. class CustomFormatter : IFormatProvider, ICustomFormatter{ // The GetFormat method of the IFormatProvider interface. // This must return an object that provides formatting services for the specified type. public object GetFormat(System.Type type){ return this; } // The Format method of the ICustomFormatter interface. // This must format the specified value according to the specified format settings. public string Format(string format, object arg, IFormatProvider formatProvider){ string formatValue = arg.ToString(); if (format == "u") return formatValue.ToUpper(); else if (format == "l") return formatValue.ToLower(); else return formatValue; } } // ... // Assign the custom formatter to the editors. textEdit1.Properties.DisplayFormat.FormatType = FormatType.Custom; textEdit1.Properties.DisplayFormat.FormatString = "u"; textEdit1.Properties.DisplayFormat.Format = new CustomFormatter(); textEdit2.Properties.DisplayFormat.FormatType = FormatType.Custom; textEdit2.Properties.DisplayFormat.FormatString = "l"; textEdit2.Properties.DisplayFormat.Format = new CustomFormatter();
轉(zhuǎn)換前和轉(zhuǎn)換后的文本編輯器字符串:
本示例演示如何創(chuàng)建自定義格式化對象,用二進(jìn)制顯示十進(jìn)制的值。如圖:
示例代碼如下:
// A custom formatter object. public class BaseFormatter : IFormatProvider, ICustomFormatter { // The GetFormat method of the IFormatProvider interface. // This must return an object that provides formatting services for the specified type. public object GetFormat(Type format) { if (format == typeof (ICustomFormatter)) return this; else return null; } // The Format method of the ICustomFormatter interface. // This must format the specified value according to the specified format settings. public string Format (string format, object arg, IFormatProvider provider) { if (format == null) { if (arg is IFormattable) return ((IFormattable)arg).ToString(format, provider); else return arg.ToString(); } if (format == "B") return Convert.ToString(Convert.ToInt32(arg), 2); else return arg.ToString(); } } // ... // Assign the custom formatter to the editor. spinEdit1.Properties.DisplayFormat.FormatType = FormatType.Custom; spinEdit1.Properties.DisplayFormat.FormatString = "B"; spinEdit1.Properties.DisplayFormat.Format = new BaseFormatter(); spinEdit1.Properties.IsFloatValue = false; spinEdit1.EditValue = 10;
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件