谢谢。

解决方案 »

  1.   

    要怎么样的?Delphi上的就已经很好了。不行的话,再自己改改,写一个吧。。
    下面是我写的两个
    unit wMonthCalendar;interfaceuses
      Windows, Messages, SysUtils, Classes, Controls,ExtCtrls,ComCtrls,StdCtrls,
      Spin,Graphics,Forms;type
      TtwMonthCalendar = class(twinControl)
      private
        FPanel:TPanel;
        FMonthCalendar: TMonthCalendar;
        Flb_hour,Flb_min,Flb_sec:TLabel;
        FSpe_hour,Fspe_min,FSpe_sec:TSpinEdit;
        FDateTime:TDateTime;
        FDate:TDate;
        FTime:TTime;
        PopupForm:TForm;
        FOnChange:TNotifyEvent;
        Procedure FrmDeactivate(Sender: TObject);
        Procedure SpEKeyDown(Sender: TObject; var Key: Word;Shift: TShiftState);
        Procedure MCDblClick(Sender: TObject);
      protected
        procedure WMSize(var Message: TWMSize); message WM_SIZE;
      public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
        Function Execute(X, Y: integer): Boolean;
        procedure SetInit(DateTime:TDateTime);
      published
        property DateTime:TDateTime read FDateTime write FDateTime;
        property OnChange:TNotifyEvent  read FOnChange write FOnChange;
        property Visible;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('TW Control', [TtwMonthCalendar]);
    end;procedure TtwMonthCalendar.WMSize(var Message: TWMSize);
    begin
      inherited;
       self.Width:=267;
       self.Height:=185;
    end;procedure TtwMonthCalendar.SetInit(DateTime:TDateTime);
    var
      Hour, Min, Sec, MSec: Word;
    begin
      FMonthCalendar.date:=TDatetime(DateTime);
      DecodeTime(DateTime, Hour, Min, Sec, MSec);
      FSpe_hour.Value:=Hour;
      FSpe_min.Value:=min;
      FSpe_sec.Value:=sec;
    end;Procedure TtwMonthCalendar.SpEKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
       if Key=13 then
       begin
         if (Sender as TSpinEdit).Tag=1 then
         begin
              Fspe_min.SetFocus;
              Key:=0;
              exit;
         end;
         if (Sender as TSpinEdit).Tag=2 then
         begin
              Fspe_sec.SetFocus;
              Key:=0;
              exit;
         end;
         Fspe_hour.SetFocus;
         FrmDeactivate(nil);
         Key:=0;
       end;
    end;Procedure TtwMonthCalendar.MCDblClick(Sender: TObject);
    begin
       FrmDeactivate(nil);
    end;Procedure TtwMonthCalendar.FrmDeactivate(Sender: TObject);
    begin
       self.DateTime:=strtoDatetime(DateTostr(FMonthCalendar.Date)+' '+inttostr(Fspe_hour.Value)+':'+inttostr(Fspe_min.Value)+':'+inttostr(Fspe_sec.Value));
       if PopupForm<>nil then
       begin
           PopupForm.Visible:=false;
           popupForm:=nil;
           PopupForm.Free;
       end;
       if Assigned(FOnChange) then FOnChange(Self);
    end;Function TtwMonthCalendar.Execute(X, Y: integer): Boolean;
    begin
      Result := False;
      PopupForm := TForm.Create(nil);
        Parent := PopupForm;
        Left := 1;
        Top := 1;
        Visible := True;
        with PopupForm do
        begin
          OnDeactivate:=FrmDeactivate;
          AutoScroll := False;
          Width := Self.Width+2;
          Height := Self.Height+2;
          Color:=clBlack;
          BorderStyle := bsNone;
          KeyPreview := True;
          if X + Self.Width > Screen.Width then
            X := Screen.Width - Self.Width;
          if Y + Self.Height > Screen.Height then
            Y := Screen.Height - Self.Height;
          Left := X;
          Top := Y;
          Visible := False;
          Show;
        end;
    end;constructor TtwMonthCalendar.Create(AOwner: TComponent);
    begin
       inherited Create(AOwner);
       self.Color:=clWindow;
       self.Width:=267;
       self.Height:=185;   FPanel:=TPanel.Create(self);
       FPanel.Parent:=self;
       Fpanel.Caption:='';
       Fpanel.Left:=0;
       Fpanel.top:=0;
       Fpanel.Color:=clwindow;
       Fpanel.Width:=267;
       Fpanel.Height:=185;
       Fpanel.BevelInner:=bvNone;
       Fpanel.BevelOuter:=bvNone;    FMonthCalendar:=TMonthCalendar.Create(Fpanel);
       FMonthCalendar.Parent:=Fpanel;
       FMonthCalendar.Left:=0;
       FMonthCalendar.Top:=0;
       FMonthCalendar.AutoSize:=true;   Flb_hour:=TLabel.Create(Fpanel);
       Flb_hour.Parent:=Fpanel;
       Flb_hour.Caption:='小时:';
       Flb_hour.Left:=16;
       Flb_hour.top:=164;
       Flb_hour.AutoSize:=true;   Flb_min:=Tlabel.Create(Fpanel);
       Flb_min.Parent:=Fpanel;
       Flb_min.Caption:='分钟:';
       Flb_min.Left:=103;
       Flb_min.top:=164;
       Flb_min.AutoSize:=true;   Flb_sec:=TLabel.Create(Fpanel);
       Flb_sec.Parent:=Fpanel;
       Flb_sec.Caption:='秒  :';
       Flb_sec.Left:=189;
       Flb_sec.top:=164;
       Flb_sec.AutoSize:=true;   FSpe_hour:=TSpinEdit.Create(Fpanel);
       Fspe_hour.Parent:=Fpanel;
       Fspe_hour.MinValue:=0;
       Fspe_hour.MaxValue:=23;
       Fspe_hour.Left:=48;
       Fspe_hour.Top:=159;
       Fspe_hour.Width:=38;
       Fspe_hour.tag:=1;   Fspe_min:=TSpinEdit.Create(Fpanel);
       Fspe_min.Parent:=Fpanel;
       Fspe_min.MinValue:=0;
       Fspe_min.MaxValue:=59;
       Fspe_min.Left:=138;
       Fspe_min.Top:=159;
       Fspe_min.Width:=38;
       Fspe_min.tag:=2;   FSpe_sec:=TSpinEdit.Create(Fpanel);
       Fspe_sec.Parent:=Fpanel;
       Fspe_sec.MinValue:=0;
       Fspe_sec.MaxValue:=59;
       Fspe_sec.Left:=216;
       Fspe_sec.Top:=159;
       Fspe_sec.Width:=38;
       Fspe_sec.tag:=3;   Fspe_Hour.OnKeyDown:=SpEKeyDown;
       Fspe_min.OnKeyDown:=SpEKeyDown;
       Fspe_sec.OnKeyDown:=SpEKeyDown;   FMonthCalendar.OnDblClick:=MCDblClick;   //默认时间
       FDateTime:=now;
       FDate:=TDate(now);
       FTime:=TTime(now);
    end;
    destructor TtwMonthCalendar.Destroy;
    begin
      FMonthCalendar.Free;
      Flb_hour.Free;
      Flb_min.Free;
      Flb_sec.Free;
      FSpe_hour.Free;
      Fspe_min.Free;
      FSpe_sec.Free;
      Fpanel.Free;
      inherited Destroy;
    end;end.
      

  2.   

    unit twDateTimePicker;interfaceuses
      Windows, Messages, SysUtils, Classes, Controls, StdCtrls, DBCtrls,
      db,wMonthCalendar;type
      TtwDateTimePicker = class(TwinControl)
      private
        FDataLink: TFieldDataLink;
        FTwMonthCalendar:TtwMonthCalendar;
        FDBComboBox:TDBComboBox;
        procedure DCDropDown(Sender: TObject);
        procedure DateChange(Sender: TObject);
        function GetDataField: string;
        function GetDataSource: TDataSource;
        procedure SetDataField(Value: string);
        procedure SetDataSource(Value: TDataSource);
      protected
        procedure WMSize(var Message: TWMSize); message WM_SIZE;
      public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
      published
        property DataSource: TDataSource read GetDataSource write SetDataSource;
        property DataField: string read GetDataField write SetDataField;
      end;procedure Register;implementation
    procedure Register;
    begin
       RegisterComponents('TW Control', [TtwDateTimePicker]);
    end;procedure TtwDateTimePicker.WMSize(var Message: TWMSize);
    begin
      inherited;
      FDBComboBox.Height:=self.height;
      FDBComboBox.width:=self.width;
    end;function TtwDateTimePicker.GetDataField: string;
    begin
      Result:=FDataLink.FieldName;
    end;procedure TtwDateTimePicker.SetDataField(Value: string);
    begin
      FDataLink.FieldName:=value;
      FDBComboBox.DataField:=value;
    end;function TtwDateTimePicker.GetDataSource: TDatasource;
    begin
      Result := FDataLink.DataSource;
    end;procedure TtwDateTimePicker.SetDataSource(Value: TDataSource);
    begin
      if Value <> nil then
      begin
        if not (FDataLink.DataSourceFixed and (csLoading in ComponentState)) then
            FDataLink.DataSource := Value;
        FDBComboBox.DataSource:=value;
      end;
    end;
    procedure TtwDateTimePicker.DateChange(Sender: TObject);
    begin
     try
          FDBComboBox.Text:=Datetimetostr(FTwMonthCalendar.DateTime);
          if FDBComboBox.DataSource=nil then exit;
          if FDBComboBox.DataField='' then exit;
          if not FDBComboBox.DataSource.DataSet.Active then exit;
          if not (FDBComboBox.DataSource.DataSet.State in [dsedit,dsinsert]) then FDBComboBox.DataSource.DataSet.Edit;
          FDBComboBox.DataSource.DataSet.FieldByName(FDBComboBox.DataField).AsDateTime:=FTwMonthCalendar.DateTime;
     except
     end;
    end;procedure TtwDateTimePicker.DCDropDown(Sender: TObject);
    var p:TPoint;
    begin
       p := FDBComboBox.ClientToScreen(Point(0, FDBComboBox.Height));
       if (FDBComboBox.DataSource<>nil) and (FDBComboBox.DataField<>'') and (FDBComboBox.DataSource.DataSet.Active) then
          FTwMonthCalendar.SetInit(FDBComboBox.DataSource.DataSet.fieldbyname(FDBComboBox.DataField).AsDateTime);
       FTwMonthCalendar.Execute(p.X,p.Y);
    end;constructor TtwDateTimePicker.Create(AOwner: TComponent);
    begin
       inherited Create(AOwner);
       FTwMonthCalendar:=TtwMonthCalendar.Create(self);
       FTwMonthCalendar.Visible:=false;
       FTwMonthCalendar.Parent:=self;
       FtwMonthCalendar.OnChange:=DateChange;   FDBComboBox:=TDBComboBox.Create(self);
       FDBComboBox.Parent:=self;
       self.Width:=FDBComboBox.Width;
       self.Height:=FDBComboBox.Height;
       FDBcomboBox.OnDropDown:=DCDropDown;  FDataLink := TFieldDataLink.Create;
      FDataLink.Control := Self;end;destructor TtwDateTimePicker.Destroy;
    begin
      FTwMonthCalendar.free;
      FDBComboBox.Free;
      FDataLink.Free;
      inherited Destroy;
    end;end.