当前位置:主页>销售管理软件> 列表

DateTimePicker是怎样得到焦点时,会自动选择4 找进销存系统安装

仓库管理软件版1楼: 是在什么事件呢?

2楼: 晕,看不懂题目.
猜一下: 是不是要让DateTimePicker的日期只显示为4位年份?!
如果是,可以在Format中设置格式. 如进销存系统安装

3楼: 不是的,就是光标移到日期控件时,会自动根据光标所在的起始位置,选中对应的年份或月份或日期,相当于SelLength,SelStart

4楼: DateTimePicker好像不行,可以试其它的控件.

5楼: 我想知道 DateTimePicker是怎样实现的

6楼: 郁闷,delphi7中,DateTimePicker默认的功能就是,得到焦点时自动会让年份或月份或日期得到焦点.parseInput为true时是另一种状态。试试。

仓库管理软件版7楼: 我想知道DateTimePicker的代码是哪一段实现该功能,我想开发类似功能的控件了,

8楼: procedure TForm1.DateTimePicker1Enter(Sender: TObject);
begin
(Sender as TDateTimePicker).Perform(VK_Left, 0, 0);
end;

9楼: 标准Win32组件就是如此,可能要去问M$了

[b]DateTimePicker.dpr[/b]

[code]program DateTimePicker;

uses
Messages,
Windows,
CommCtrl,
SysUtils,
XPMan;

var
WinClass: TWndClassA;
hIns: HINST;
hMainWnd: HWND;
Msgs: TMsg;
MainWndFont: HFONT;
LogFont: TLogFont;
dtpDateTime, btnClose, edtDate: HWND;



function MainWndProc(hMainWnd: HWnd; Msg, wParam, lParam: Integer): Integer;
stdcall;
var
SysTime: TSYSTEMTIME;
SelDate: String;
begin
Result := 0;

case Msg of
WM_COMMAND: begin
if HWND(lParam) = btnClose then
SendMessage(hMainWnd, WM_DESTROY, 0, 0);

Exit;
end;


WM_NOTIFY: begin
if TNMDATETIMECHANGE(Pointer(lParam)^).nmhdr.hwndFrom =
dtpDateTime then begin
MonthCal_GetCurSel(DateTime_GetMonthCal(dtpDateTime), SysTime);
DateTime_GetSystemtime(dtpDateTime, SysTime);
SelDate := IntToStr(SysTime.wYear) + ''年'' + IntToStr(SysTime.wMonth) +
''月'' + IntToStr(SysTime.wDay) + ''日'';
SetWindowText(edtDate, PChar(SelDate));
end;
end;


WM_DESTROY: begin
DeleteObject(MainWndFont);
PostQuitMessage(0);

Exit;
end;

else
Result := DefWindowProc(hMainWnd, Msg, wParam, lParam);
end;
end;


begin
hIns := hInstance;
with WinClass do begin
style := CS_CLASSDC or CS_PARENTDC;
lpfnWndProc := @MainWndProc;
hInstance := hIns;
hbrBackground := COLOR_BTNFACE + 1;
lpszClassname := ''DateTimePicker'';
hIcon := 0;
hCursor := LoadCursor(0, IDC_ARROW);
end;
RegisterClass(WinClass);

hMainWnd := CreateWindowEx(WS_EX_WINDOWEDGE, ''DateTimePicker'',
PChar(''DateTimePicker''),
WS_MINIMIZEBOX or WS_SYSMENU,
Round((GetSystemMetrics(SM_CXSCREEN) - 300) / 2),
Round((GetSystemMetrics(SM_CYSCREEN) - 300) / 2),
300, 300, 0, 0, hIns, nil);

dtpDateTime := CreateWindow(''SysDateTimePick32'', '''',
WS_VISIBLE or WS_CHILD or WS_TABSTOP,
8, 8, 140, 22, hMainWnd, 0, hIns, nil);

edtDate := CreateWindowEx(WS_EX_CLIENTEDGE, ''Edit'','''',
WS_CHILD or WS_VISIBLE or WS_TABSTOP or ES_AUTOHSCROLL,
8, 36, 96, 20, hMainWnd, 0, hIns, nil);

btnClose := CreateWindow(''Button'', ''&Close'',
WS_VISIBLE or WS_CHILD or WS_TABSTOP or WS_GROUP or BS_PUSHBUTTON,
220, 240, 65, 21, hMainWnd, 0, hIns, nil);

if SystemParametersInfo(SPI_GETICONTITLELOGFONT, SizeOf(LogFont), @LogFont,
0) then
MainWndFont := CreateFontIndirect(LogFont)
else
MainWndFont := CreateFont(-12, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET,
0, 0, 0, 0, ''宋体'');
if MainWndFont <> 0 then begin
SendMessage(dtpDateTime, WM_SETFONT, MainWndFont, 0);
SendMessage(edtDate, WM_SETFONT, MainWndFont, 0);
SendMessage(btnClose, WM_SETFONT, MainWndFont, 0);
end;

ShowWindow(hMainWnd, SW_SHOW);
UpdateWindow(hMainWnd);

while GetMessage(Msgs, 0, 0, 0) do begin
if not IsDialogMessage(hMainWnd, Msgs) then begin
TranslateMessage(Msgs);
DispatchMessage(Msgs);
end;
end;

end.[/code]

10楼: 如果该控件要我来做的话,我会这样实现该功能:在点击DTP后,那么你就已经获得想要时间(或日期,年份等),只是此时得到的是一个比你想要的要多一些,那么你可以用DateTimeFormat()来动态的格式化你点击时获得的时间,就可以得到你想要的时间了.
这就如同格式化now一样.

11楼: 多人接受答案了。