I am creating charts programmatically in a manner similiar to this example on the DevExpress website. I see where you can identify series data to be formatted as currency, but the reporting tool is globally based and needs to be able to format the various chart labels using a passed in currency.
Here is an example of code used to generate a typical SeriesView:
private void FormatBarSeries (SideBySideBarSeriesView bar)
{
bar.AxisY.NumericOptions.Format = NumericFormat.Currency;
bar.AxisY.NumericOptions.Precision = 0;
bar.AxisY.Title.Text = "Sample Bar";
bar.AxisY.Title.Font = new Font(GetChartFontFamily(), 10.0f, FontStyle.Regular);
bar.AxisY.Title.Visible = true;
bar.AxisY.Tickmarks.Visible = false;
bar.AxisY.Tickmarks.MinorVisible = false;
bar.AxisX.Tickmarks.MinorVisible = false;
}
I cannot seem to find any manner of defining the culture for the specific chart. Each report may contain multiple charts, but all the charts on a report would be the same currency format.
Can this perhaps be set at the report level and have all charts inherit it? Or how can I set this on a chart by chart basis?
Found the answer, as demonstrated here:
You have to hook into a CustomDrawAxisLabel event:
Chart.CustomDrawAxisLabel += Chart_CustomDrawAxisLabel;
where you can override the code with a function like this:
void Chart_CustomDrawAxisLabel (object sender, CustomDrawAxisLabelEventArgs e)
{
AxisBase axis = e.Item.Axis;
if(axis.NumericOptions.Format == NumericFormat.Currency)
{
decimal value = 0.00M;
e.Item.Text = decimal.TryParse(e.Item.AxisValue.ToString(),
out value)
? value.ToString("C0", _culture)
: e.Item.AxisValue.ToString();
}
}
using a culture variable defined elsewhere in the class.
Related
currently I am facing the following problem.
In my application (which is a plugin for AutoCAD/BricksCAD), i am using a DataGrid with a custom Column, that ensures the input to be in a float-format.
The code for the column looks something like that:
public class DataGridFloatColumn : DataGridTextColumn
{
protected override object PrepareCellForEdit(FrameworkElement editingElement, RoutedEventArgs editingEventArgs)
{
TextBox edit = editingElement as TextBox;
edit.PreviewTextInput += OnPreviewTextInput;
return base.PrepareCellForEdit(editingElement, editingEventArgs);
}
void OnPreviewTextInput(object sender, TextCompositionEventArgs e)
{
string txt = ((TextBox)sender).Text + e.Text;
float _;
e.Handled = !float.TryParse(txt, out _);
}
}
This part works as expected. I am only allowed to input float numbers, separated by a comma. The problem however is, that the DataGrid expects a dot as decimal separator.
Due to this, initial values are represented with a dot, and If I type something with a comma, it simply gets removed when hitting enter... for example 123,4 --> 1234
What I have already tried:
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-DE");
But when printing Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator, i am getting a comma...
Any suggestions?
Thank you ind advance!
I dont know if it covers your issue, but if I want culture-specific number/datetime formatting in XAML, I put this "hack" into the constructor of my "App.xaml.cs"
public App()
{
FrameworkElement.LanguageProperty.OverrideMetadata(
typeof(FrameworkElement),
new FrameworkPropertyMetadata(XmlLanguage.GetLanguage("de-DE")));
}
Thread.CurrentThread.CurrentCulture = myCulture somehow does not do the trick.
In my Form I have this code to open my report on a click of Button:
private void btnGroupOther_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
LayoutControl lc = new LayoutControl();
lc.Dock = DockStyle.Fill;
DateEdit FirstDate = new DateEdit();
DateEdit LastDate = new DateEdit();
lc.AddItem(Resources.firstdate, FirstDate).TextVisible = true;
lc.AddItem(Resources.seconddate, LastDate).TextVisible = true;
lc.Height = 70;
this.Controls.Add(lc);
this.Dock = DockStyle.Top;
if (DevExpress.XtraEditors.XtraDialog.Show(lc, " ", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
RepProductionGroupOther report = new RepProductionGroupOther();
report.DataSource = paint.RepProductionGroupOther(Convert.ToDateTime(FirstDate.EditValue).ToString("MM/dd/yyyy"),
Convert.ToDateTime(LastDate.EditValue).ToString("MM/dd/yyyy"));
report.ShowRibbonPreviewDialog();
}
}
In my header report I have two xrLabel; the first one txtFirstDate and the second one txtLastDate. I want to show the value of FirstDate DateEdit control in txtFirstDate and the value of LastDate DateEdit control in txtLastDate.
How can I do that, the DataSource of the report is sql stored procedure.
It has two Parameters: #FirstDate and #LastDate.
Thanks in advance
I suggest you to go through XtraReport documentation:
Request and Pass Report Parameter Values
private void button1_Click(object sender, EventArgs e) {
// Create a report instance.
XtraReport1 report = new XtraReport1();
// Obtain a parameter and set its value.
report.Parameters["parameter1"].Value = 30;
// Hide the Parameters' UI from end-users (if you did not hide it at design time).
report.Parameters["parameter1"].Visible = false;
// Show the report's print preview depending on your target platform.
// ...
}
Check the "Custom Parameter Editors" section in above documentation
Custom editor implementation for parameters varies depending on your application's platform:
Windows Forms
In Windows Forms applications, you can provide custom parameter editors in the XtraReport.ParametersRequestBeforeShow event handler.
For a code sample, see Provide Custom Editors for Report Parameters.
Below are similar implementation as you are trying to do.. Check these, hope this will help you resolve the issue.
How to pass parameters to devexpress XtraReport from combobox
DevExpress XtraReport Setting a DateTime Parameter to Today
Passing parameters to Xtrareports repx file
Currently i set Y axis of my chart using N2 format like this
chart.ChartAreas[0].AxisY.LabelStyle.Format = "{0:N2}";
What i want to achieve is that N2 is using Indonesian format, i know how to do it in object conversion just like below
sum.ToString("N2", CultureInfo.GetCultureInfo("id-ID"));
How to apply CultureInfo in formatting chart axis?
You can use the FormatNumber event of the chart.
private readonly CultureInfo indonesiaCulture = CultureInfo.GetCultureInfo("id-ID");
void chart1_FormatNumber(object sender, FormatNumberEventArgs e)
{
if (e.ElementType == ChartElementType.AxisLabels)
{
e.LocalizedValue = e.Value.ToString("N2", indonesiaCulture);
}
}
Or you can change the Thread.CurrentUICulture for the UI thread and set LabelStyle.Format property. I've not tested it, I believe that should also work.
In addition to Sriram Sakthivel's answer.
You can use Format property this way:
chart.ChartAreas[0].AxisY.LabelStyle.Format = "IndonesianNumericFormat";
void chart_FormatNumber(object sender, FormatNumberEventArgs e)
{
switch (e.Format)
{
case "IndonesianNumericFormat":
e.LocalizedValue = e.Value.ToString("N2", new CultureInfo("id-ID"));
break;
}
}
So, you can set different formats to different columns and incapsulate logic of string conversion to a class \ factory etc.
My Question is to how to extend a TextBox such that it may start behaving like RichTextBox?
There can be various properties that RichTextBox may add: appearance mainly.
Should I use this kind of method where I extend the TextBox class and create a basic TextBox which would contain several other textboxes which would behave like a big container node containing small specialized nodes?
For starters, to have texts with alternate color after '+', I ve used this way:
class CustomTextBox : TextBox
{
List<TextBox> _textboxes = new List<TextBox>();
string _Text="";
List<Color> colorlist = new List<Color>();
public override string Text
{
get{return this._Text;}
set{this._Text = value;}
}
public CustomTextBox()
{
foreach(Color color in (Color[]) Enum.GetValues(typeOf(Color)))
{
colorlist.add(color);
}
this.KeyUp+= new KeyUpEventHandler(TextChangedCheck);
}
int i=0;
private void TextChangedCheck(object sender, KeyUpEventArgs e)
{
if(e.KeyData == Keys.Add)
{
TextBox Temp = new TextBox();
Temp.Text = this.Text;
this.Text = "";
Temp.ForeColor = colorlist[i];
i++;
this._textboxes.Add(Temp);
this.Controls.Add(_textboxes[i]);
e.Handled = true;
}
}
}
EDIT:
The MAIN purpose of this question is to extend a TextBox using its own properties to have a RTB like behavior and not using Graphics or related.
I'd have to guess what you really want to achieve here.
But if you want a Control with formatted text (FT) and really really really don't want a RichTextBox, I think you shouldn't create a new, embedded TextBox for every piece of FT.
Instead you should write the FT yourself, maybe on a panel with DrawString and use only one Textbox for text entry. Interesting project, really, once one accepts the challenge. Of course you must think your format through and also consider all sorts of interface questions..
Last week I have avoided a RTF for a tiny help system by using a ListView; it formats by line only, using the first character to indicate the format from a list of a dozen or so.. Works fine, but only one format per line.
I have project and it supports 4 languages but now customer wants one more language. It is Arabic. I have no idea how to display Arabic in Labels and TextBoxes.
I know Arabic is written from right to left and its starting point is the right side of the label ord textview.
here is my sample code. this code show english,german and arabic....
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedItem.ToString().Equals("en-GB"))
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-GB");
label1.Text= FormLabels.test1;
label2.Text = FormLabels.test2;
}
else if (comboBox1.SelectedItem.ToString().Equals("de-DE"))
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE");
label1.Text = FormLabels.test1;
label2.Text = FormLabels.test2;
}
else if (comboBox1.SelectedItem.ToString().Equals("ar"))
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("ar");
label1.Text = FormLabels.test1;
label2.Text = FormLabels.test2;
}
}
How am I supposed to display Arabic characters and display the test from right to left?
//...
else if (comboBox1.SelectedItem.ToString().Equals("ar"))
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("ar");
label1.RightToLeft = label2.RightToLeft = RightToLeft.Yes;
label1.Text = FormLabels.test1;
label2.Text = FormLabels.test2;
}
UPDATE
if you have many many labels, there are some solutions here:
You can define a class such as called RighToLeftLabel and use it to declare all your labels:
public class RightToLeftLabel : Label {
public RightToLeftLabel(){
RightToLeft = RightToLeft.Yes;
}
}
//Then declare your labels:
RightToLeftLabel label1 = new RightToLeftLabel();
RightToLeftLabel label2 = new RightToLeftLabel();
RightToLeftLabel label3 = new RightToLeftLabel();
//you can also drag-n-drop this custom Label from the ToolBox (remember to place the class in your project namespace and build first, after that you will see there is a RightToLeftLabel control at the very top in the ToolBox)
You can loop though the collection of your Labels and change RightToLeft to Yes for each one:
foreach(Label lbl in yourLabels)
lbl.RightToLeft = RightToLeft.Yes;
//I think this is right for you because the project language may change...
i want to add on kingKing answer, which is excellent as always, that you should consider making all the form RightToLeft, because when you read the form you can't read the form RightToLeft and have the control in a reverse way.
here is an example of what i mean: if it was an arabic form translated to english: