DateTimePicker tab between fields - delphi

Is there anyway to allow the user to tab between the fields in the TDateTimePicker.
Having to use arrow keys or the mouse to position is very slow.

No, there is no way.
Interception of the TAB and sending a right arrow key -> instead is easy, but then you have to decide when to let (SHIFT-)TAB trough, which should be done when standing on the first or last field in order to preserve normal user experience.
Now, all the selection changes from cursor and mouse events are internally handled within the Windows DTM control, and the Windows API does not support retrieving the separate fields. All you can acquire is the entire text of this very special edit control.
In theory you could intercept and save áll keyboard and mouse input, and calculate whether the first or last field is selected, but it will be a daunting and an error-prone task, and you should not want to.
Thus no. You just have to get yourself familiarized with it.

Related

When typing at the end of the editmask, it will pass the number to the left side until it reaches the last one

Good afternoon,
I'm doing a project in delphi that uses editmask. I'm using the phone mask.
When clicking on edit to write the phone number, it goes to the last field on the right, so it is necessary to go back with the backspace to the beginning of the edit on the left.
i would like to find a way that when the user typed the number in the last field on the right, it was passed to the left. So on until you complete the phone field. It would be possible?
Using an example of what it would look like:
I couldn't think of a way to do it
The component is called TMaskEdit.
Just like anything that bases on TEdit putting the focus onto the control will by default put the text cursor at the end of its content
via keyboard, should .AutoSelect be FALSE and
via mouse if clicking behind any text (by default the text is aligned to the left).
You should have experienced this with the other components already. If you want the text cursor to always be at a certain position upon focusing the control, then do that in such an event handler:
for keyboard use OnEnter:
procedure TForm1.MaskEdit1Enter(Sender: TObject);
begin
(Sender as TMaskEdit).SelStart:= 1; // Second position
end;
and for mouse use OnClick with the same code.
It even works unbound to how the property .AutoSelect is set.
Using Backspace is the worst choice input wise, as it always deletes potential content and needs to be pressed several times to go to the first position. Why not using the Home key instead?

how to respond to a key press when focused on a radiogroup in delphi

In delphi:
How can you respond to a key press when the current focus is on a radiogroup which does not have an onkeypress event. I was hoping to use the forms onkeypress event but it doesnt see to fire.
You can make this possible by setting the form's KeyPreview property to True.
However, I'm not sure you are actually doing things right, since this is a fairly uncommon problem.
You didn't write what keyboard shortcut you want to respond to. But please remember that
Letters are used to navigate the GUI. For instance, pressing A might select the &All radio button or click the &Add push button. Similarly, Alt+A does the same if the current control allows character input, allows you to open the &Add-ons menu item, etc.
If you want to add a proper shortcut like Ctrl+O, it is much better to use a TActionList with an action having this shortcut. This action can be mapped to menu items, buttons, etc., or simply exist in the background not being attached to any visual control. In very simple applications, you might want to use a stand-alone menu item with such a shortcut instead.

How to implement a special indicator in a single- or multi-line edit control

I've occasionally come across examples of edit controls that have a special indicator to assist the user, like so:
and I'd like to be able to implement similar in my own code.
The screen-scrap is actually from the property editor for the TIBQuery Sql property and isn't quite what I'm after (otherwise I'd just look in the IBX code) because it disappears as soon as the user types anything. There are others where the indicator moves so as to keep its place as the user types something, but doesn't replace the caret, otherwise I'd just do that.
So my question is, how to implement a special indicator of the type I've tried to describe, that can be positioned and turned on/off in code? The simplest thing I could think of would be to somehow temporarily add a special glyph to the edit control's character set, but I have no idea how to do that, nor how to colour it differently than the control's text content.

Disable keyboard shortcut (delphi)

I created a form in Delphi.
Say I have a Form with a speedbutton with label "&Add" (underline A, as a keyboard shortcut), and a dbgrid (read-only state) (or other control like TButton).
Then I changed the focus to Dbgrid (dbgrid got a focus) (or to TButton).
Every time I press the a key on the dbgrid, the onClick method on the speedbutton triggers.
Sometime I need to disable it for a while for a reason, and then i enable it again.
How to disable the speedbutton shortcut?
And then how to enable it again?
The form is pressing the button when you press A because the button has expressed interest in that key, and nothing else on your form is accepting keystrokes. If you had an edit box on your form, and it had the input focus, then the button would not be triggered.
You can make a control indicate that it wants to receive keystrokes when it has the focus, but that generally happens when writing a custom control, where you have some idea of what the new control class should do when it receives keyboard input.
If you don't want the button to be triggered, you can disable it. Another option is to alter the OnClick event handler to check other conditions (such as whether the grid has focus) before performing the usual click-handling code.
You could disable the shortcut by changing the speed button's label from &Add to Add. Change it back when you need to enable the shortcut again.
Please note that specifying an accelerator character like that enables two shortcuts, one is just the key prefaced with the & and the other the same key with Alt. So, in your case they would be A and Alt+A. In the same way, eliminating the accelerator disables both shortcuts. So, keep in mind that with this method of disabling the shortcut you would be unable to trigger the button neither with A nor with Alt+A.

read-only Textbox

The form window(chat window) that i am creating for a lan messenger is similar to the one in google talk with two textboxes. What i need to do is to transfer characters typed in the lower textbox(textbox2) to the upper textbox(textbox1 which is read-only) when i click the submit button without showing that textbox1 is read-only because the characters are appearing in grey.please help with code if possible.
Use a label for this instead of a textbox. If the only thing it is doing is display the characters and not a direct edit, you won't lose any functionality and the text would not be greyed out...
If you're going to use a Texbox, set it to Locked. That shouldn't gray the characters out. Otherwise in KeyDown/KeyUp events, set the e.Handled property to true (which will tell the box that you want to handle the input yourself and don't want the message to filter down).
That oughta do it for you.

Resources