How to fix a System.FormatException on a dateTimePicker while trying to translate with ini file - translation

i'm new to encoding and i'm trying to translate runtime my controls inside several tabs using a ini file. My current culture is French.
According to a comboBox, users can select a language then labels and controls must be translated.
However a System.FormatException error occured when it tries to translate the control text of a dateTimePicker.
Here is the content of control when it crashes : {System.Windows.Forms.DateTimePicker, Value: 01/05/2019 23:34:21} I can use any help !
{
// Translating each control inside each tab
foreach (Control tab in tabControl1.Controls)
{
// Translating the tab name
tab.Text = Languages.GetTranslation(comboBoxLanguages.SelectedItem.ToString(), tab.Name);
// Translating each control (labels, buttons, grid columns...)
// inside each tab
foreach (Control control in tab.Controls)
{
// Translating the control text
control.Text = Languages.GetTranslation(comboBoxLanguages.SelectedItem.ToString(), control.Name);
}
}

Related

Vaadin 14 Grid in non-buffered mode exit editor

I've created a custom field in Vaadin14 that displays a grid and two buttons (add row / clear grid). This custom field is displayed in a CRUD editor, editor that in turn has tabs.
For creating the grid with editor I've used the example shown here https://vaadin.com/docs/v14/ds/components/grid in the "Non-buffered" section.
Everything works as expected except for the addCloseHandler(Component, Editor). In the example shown above the code for the close handler method is this one:
textField.getElement().addEventListener("keydown", e -> editor.cancel()).setFilter("event.code === 'Escape'");
which closes the editor when pressing the Esc key or clicking outside the cell that's in edit mode.
My problem is that, given the grid with the editor are inside a CRUD form when I'm hitting Esc the CRUD discard changes form is being shown instead of the editor closing. Also, when clicking outside the edited cell nothing happens.
I believe this is due to the "event.code" in the setFilter method being incorrect but I'm unsure how to determine what is the proper event code that's being triggered in my case.
I tried changing the event from "keydown" to "focusout" which led to the callback method being called when I clicked outside the cell that was being edited but nonetheless the editor did not close (I.e. the cell was stuck in edit mode). I also tried calling editor.close() inside the callback method but with no success.
From https://vaadin.com/docs/v14/ds/components/grid in the "Non-buffered" section:
In the example below, double-click a row to start editing. Press
Escape, or click on a different row to stop editing.
This kotlin code has exactly the same behavior
var clickRegistration :Registration? = null
fun addCloseHandler(field: Component, editor: Editor<*>) {
field.element.addEventListener("keydown") { event ->
editor.cancel()
clickRegistration?.remove()
}.filter = "event.key === 'Escape'"
}
grid.addItemDoubleClickListener { e: ItemDoubleClickEvent<DataSet?> ->
editor.editItem(e.item)
val editorComponent = e.column.editorComponent
if (editorComponent is Focusable<*>) {
(editorComponent as Focusable<*>).focus()
}
clickRegistration = grid.addItemClickListener { event ->
editor.cancel()
clickRegistration?.remove()
}
}
You must use event.key not event.code:
getElement().addEventListener("keydown", event -> editor.cancel())
.setFilter("event.key === 'Escape' || event.key === 'Esc'");

Change the style of Listview item button at runtime

I want to change the style of an Accessory button in ListView Item. I'm using a Custom style (Jet style) that is shipped with RAD Studio.
The Accessory Button has 2 style objects. The style names as follows : one is normal(accessorymore), and the other is when the item is selected(accessorymoreselected). Now, the style changes if the Listview item is selected. However, I disabled the selection in the Listview. I want to change the style of when I press the Accessory button itself.
I've Added a custom png image named Selected.png for the accessorymoreselected style by utilizing the Bitmap designer using the source link property of the StyleObject.
On the ListViewItemClickEx Event :
TListView(ListView1.Items[ItemIndex].View.FindObject('Acc')).StyleLookup := 'Selected.png';
I get an Access violation. How to properly change the style of the accessory button if clicked ?

Including styles for vaadin-combo-box-item

I am trying to add flag icons in a Vaadin Flow Combobox using a customer ComponentRenderer:
new ComponentRenderer<>(locale -> {
HorizontalLayout item = new HorizontalLayout();
item.setDefaultVerticalComponentAlignment(FlexComponent.Alignment.BASELINE);
Span langIcon = new Span();
langIcon.addClassNames("flag-icon", "flag-icon-" + getTranslation("App.Language.Flag", locale));
item.add(langIcon);
item.add(new Span(locale.getDisplayLanguage(locale)));
return item;
});
The icons come from flag-icon-css (see here) included via gradle compile dependency "org.webjars.bowergithub.lipis:flag-icon-css:3.3.0" and annotation #StyleSheet("frontend://bower_components/flag-icon-css/css/flag-icon.min.css") on my main layout class. In a different place with ListBox component, icons are shown as expected. However, when used via ComponentRenderer in a combobox nothing shows up.
Inspecting the HTML, I see that the <vaadin-combo-box-item> within ComboBox renders everything under its shadow root in contrast to <vaadin-item> within ListBox which renders it as <slot>. Why is that? And how could I use the flag icon CSS styles in combo box items?

Advancing control focus in a VCL TFrame

I have a TFrame on which some TEdits are placed. These edits are
boxes for serial key input, as I'm trying to setup a user experience
where input focus jumps from one edit box to the next, when a certain amount of
characters been entered in each. That is, user do not need to press tab
or click on the next edit in order to advance.
I found an example in the C++ Builder HowTo book (great book) on how to
"simulate" enter press to behave like a tab press in edits and was
trying to employ the same technique. However, something in my app don't
work as in that example.
In the frames KeyPress event, I have the code
void __fastcall TAboutFrame::Edit1KeyPress(TObject *Sender,
System::WideChar &Key)
{
TEdit* theEdit = dynamic_cast<TEdit*>(Sender);
if(!theEdit)
{
return;
}
if(theEdit->Text.Length() >= 6)
{
//jump to next edit
Perform(WM_NEXTDLGCTL, 0, 0);
...
But the 'jump' to next control does not occur.
The main Form, the frames parent, do have key preview == true and I can
set a breakpoint to see that the Perform call is indeed executed.
The tab orders on the edits are 1,2,3,4,5.
I wonder if this has todo with TFrames messaging or?
If the controls you are using descend from TWinControl (Which they should if you are using stock VCL controls), You can also use TWinControl->SetFocus() to explicitly set the focus to the desired control.

usercontrols inside panels

In my project i added a usercontrol to a panel.when i try to add a new usercontrol to
my panel i want to check what is the name of the usercontrol placed in the panel before
how to do it.
i have three different usercontrols, i assign it one by one to panel,before replacing
the new one with the old one ,i want to find what is the old one inside the panel.
You can set the name like this:
Panel pnl= new Panel();
...
UserControl myControl = new UserControl();
myControl.Name = "muUserControl";
pnl.Controls.Add(myControl);
foreach (Control ctrl in pnlUserControlContainer.Controls)
{
if (ctrl is UserControl)
{
Console.WriteLine(ctrl.Name);
}
}

Resources