Adding TextFormat at runtime
Adding TextFormat at runtime
Hi,
is it possible to register a text format? F.e. I would like to declare a text format called "VarDec" (#,##0.##) at startup and use it in the Designer.
Regards
is it possible to register a text format? F.e. I would like to declare a text format called "VarDec" (#,##0.##) at startup and use it in the Designer.
Regards
Adding TextFormat at runtime
Hello,
You can do this, but this is complex task. At first you need create new class which inherited from StiFormatService:
After then you need add type converter:
Also you need specify editor for custom service. I have attached editor for StiCustomFormat. After then you need register new service in services collection:
Thank you.
You can do this, but this is complex task. At first you need create new class which inherited from StiFormatService:
Code: Select all
[TypeConverter(typeof(Stimulsoft.Report.Components.TextFormats.Design.StiCustomFormatConverter))]
[StiFormatEditor("Stimulsoft.Report.Components.TextFormats.Design.StiCustomEditor, Stimulsoft.Report.Design, " + StiVersion.VersionInfo)]
[StiWpfFormatEditor("Stimulsoft.Report.WpfDesign.StiCustomEditor, Stimulsoft.Report.WpfDesign, " + StiVersion.VersionInfo)]
[StiServiceBitmap(typeof(StiCurrencyFormatService), "Stimulsoft.Report.Images.TextFormats.FormatCustom.png")]
public class StiCustomFormatService : StiFormatService
{
///
/// Gets a service name.
///
public override string ServiceName
{
get
{
return StiLocalization.Get("FormFormatEditor", "Custom");
}
}
public override int Position
{
get
{
return 100;
}
}
///
/// Gets value to show a sample of formatting.
///
public override object Sample
{
get
{
return string.Empty;
}
}
///
/// Gets or sets string of formatting.
///
[DefaultValue("")]
public override string StringFormat
{
get
{
return base.StringFormat;
}
set
{
base.StringFormat = value;
}
}
///
/// Creates a new format of the type StiCustomFormatService.
///
public StiCustomFormatService() : this(string.Empty)
{
}
///
/// Creates a new format of the type StiCustomFormatService.
///
/// String of formatting
public StiCustomFormatService(string stringFormat)
{
this.StringFormat = stringFormat;
}
}
Code: Select all
public class StiCustomFormatConverter : TypeConverter
{
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context,
object value, Attribute[] attributes)
{
return TypeDescriptor.GetProperties(value, attributes);
}
public override bool CanConvertTo(ITypeDescriptorContext context,
Type destinationType)
{
if (destinationType == typeof(InstanceDescriptor))return true;
return base.CanConvertTo(context, destinationType);
}
public override bool GetPropertiesSupported(ITypeDescriptorContext context)
{
return true;
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture,
object value, Type destinationType)
{
if (destinationType == typeof(InstanceDescriptor) && value != null)
{
StiCustomFormatService service = (StiCustomFormatService)value;
Type[] types = new Type[]{ typeof(string)
};
ConstructorInfo info = typeof(StiCustomFormatService).GetConstructor(types);
if (info != null)
{
object[] objs = new object[] {
service.StringFormat
};
return new InstanceDescriptor(info, objs);
}
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
Code: Select all
StiCustomFormatService myCustomFormatService = new StiCustomFormatService();
StiConfig.Services.Add(myCustomFormatService);
Thank you.
- Attachments
-
- 243.StiCustomFormatConverter.cs
- (2.87 KiB) Downloaded 256 times
-
- 242.StiCustomFormatService.cs
- (3.42 KiB) Downloaded 245 times
-
- 241.StiCustomEditor.cs
- (8.97 KiB) Downloaded 350 times
-
[The extension resx has been deactivated and can no longer be displayed.]
Adding TextFormat at runtime
Thank you Jan!
It works fine, but it's a bit too risky for me. If there will be major class changes I have to adopt them and that's something i don't want. I am going to use an user defined mask in the dictionary.
Best Regards
It works fine, but it's a bit too risky for me. If there will be major class changes I have to adopt them and that's something i don't want. I am going to use an user defined mask in the dictionary.
Best Regards
Adding TextFormat at runtime
Hello,
You can use Custom format mark in text formating. Please check attached image. You can use variable to provide format mask.
Thank you.
You can use Custom format mark in text formating. Please check attached image. You can use variable to provide format mask.
Thank you.
- Attachments
-
- 244.Sample.png (182.79 KiB) Viewed 2116 times
Adding TextFormat at runtime
ya, solved it that way. :feelgood:
Thanks.
Thanks.
Adding TextFormat at runtime
Hello,
Please contact us if you need any help.
Thank you.
Please contact us if you need any help.
Thank you.