通用下拉选择框

object FormChoose: TFormChoose
  Left = 331
  Top = 269
  BorderStyle = bsDialog
  Caption = #36873#25321
  ClientHeight = 242
  ClientWidth = 439
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnClose = FormClose
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 201
    Width = 439
    Height = 41
    Align = alBottom
    BevelOuter = bvNone
    TabOrder = 0
    object BitBtn2: TRzBitBtn
      Left = 208
      Top = 8
      FrameColor = 7617536
      Caption = #36807#28388
      Color = 15791348
      HotTrack = True
      TabOrder = 1
      OnClick = BitBtn2Click
      Glyph.Data = {
        36040000424D3604000000000000360000002800000010000000100000000100
        2000000000000004000000000000000000000000000000000000FFFFFF00FFFF
        FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
        FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
        FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
        FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00000000000000
        0000000000000000000000000000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
        FF000000000000000000000000000000000000000000FFFFFF0000000000FFFF
        FF00000000000000000000000000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
        FF0000000000FFFFFF00000000000000000000000000FFFFFF0000000000FFFF
        FF00000000000000000000000000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
        FF0000000000FFFFFF00000000000000000000000000FFFFFF00000000000000
        00000000000000000000000000000000000000000000FFFFFF00000000000000
        00000000000000000000000000000000000000000000FFFFFF00000000000000
        0000FFFFFF00000000000000000000000000000000000000000000000000FFFF
        FF000000000000000000000000000000000000000000FFFFFF00000000000000
        0000FFFFFF00000000000000000000000000C6C6C6000000000000000000FFFF
        FF000000000000000000000000000000000000000000FFFFFF00000000000000
        0000FFFFFF00000000000000000000000000C6C6C6000000000000000000FFFF
        FF000000000000000000000000000000000000000000FFFFFF00FFFFFF000000
        0000000000000000000000000000000000000000000000000000000000000000
        000000000000000000000000000000000000FFFFFF00FFFFFF00FFFFFF00FFFF
        FF0000000000FFFFFF00000000000000000000000000FFFFFF0000000000FFFF
        FF00000000000000000000000000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
        FF000000000000000000000000000000000000000000FFFFFF00000000000000
        0000000000000000000000000000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
        FF00FFFFFF00000000000000000000000000FFFFFF00FFFFFF00FFFFFF000000
        00000000000000000000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
        FF00FFFFFF0000000000FFFFFF0000000000FFFFFF00FFFFFF00FFFFFF000000
        0000FFFFFF0000000000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
        FF00FFFFFF00000000000000000000000000FFFFFF00FFFFFF00FFFFFF000000
        00000000000000000000FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
        FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFF
        FF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00FFFFFF00}
    end
    object BitBtn3: TRzBitBtn
      Left = 360
      Top = 8
      FrameColor = 7617536
      Caption = #21462#28040
      Color = 15791348
      HotTrack = True
      TabOrder = 0
      OnClick = BitBtn3Click
      Kind = bkCancel
    end
    object BitBtn1: TRzBitBtn
      Left = 284
      Top = 8
      FrameColor = 7617536
      Caption = #30830#23450
      Color = 15791348
      HotTrack = True
      TabOrder = 2
      OnClick = BitBtn1Click
      Kind = bkOK
    end
  end
  object Panel2: TPanel
    Left = 0
    Top = 0
    Width = 439
    Height = 201
    Align = alClient
    BevelOuter = bvNone
    Caption = 'Panel2'
    TabOrder = 1
  end
  object DataSource1: TDataSource
    Left = 168
    Top = 160
  end
end

//单元设计: 陈新光(CXG)
//设计时间: 2009-10-5 21:11:46
//单元功用: 公用选择窗体

unit uChoose;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Grids, DBGrids, DB, StdCtrls, Buttons
  ,ADODB
  ,remoteudpdataset, GridsEh, DBGridEh, RzButton
  ,EhLibCDS
  ;

type
  TFormChoose = class(TForm)
    Panel1: TPanel;
    DataSource1: TDataSource;
    BitBtn2: TRzBitBtn;
    BitBtn3: TRzBitBtn;
    Panel2: TPanel;
    BitBtn1: TRzBitBtn;
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    FDataSet: TDataSet;
    procedure DBGridKeyPress(Sender: TObject; var Key: Char);
    procedure DBGridDblClick(Sender: TObject);   
  public
    { Public declarations }
  end;

var
  FormChoose: TFormChoose;
  FEdit: boolean;

procedure Execute(ADataSet: TDataSet);
procedure AdjustDropDownForm(AControl: TControl);

implementation

uses
  uPublicQuery
  ,uFunction
  ;

{$R *.dfm}

var
  DBGrid1: TDBGridEh;

procedure AdjustDropDownForm(AControl: TControl);  //设置下拉窗口位置。
var
  WorkArea: TRect;
  HostP, PDelpta: TPoint;
begin
  SystemParametersInfo(SPI_GETWORKAREA, 0, @WorkArea, 0);

  GetCursorPos(HostP); //根据点击的鼠标位置决定显示的位置
  PDelpta := AControl.ClientToScreen(Point(0, 0));

  AControl.Left := HostP.x - 2;
  AControl.Top := HostP.y - 3;

  if (AControl.Width > WorkArea.Right - WorkArea.Left) then
    AControl.Width := WorkArea.Right - WorkArea.Left;

  if (AControl.Left + AControl.Width > WorkArea.Right) then
    AControl.Left := WorkArea.Right - AControl.Width;
  if (AControl.Left < WorkArea.Left) then
    AControl.Left := WorkArea.Left;

  if (AControl.Top + AControl.Height > WorkArea.Bottom) then
  begin
    if (HostP.y - WorkArea.Top > WorkArea.Bottom - HostP.y ) then
      AControl.Top := HostP.y - AControl.Height;
  end;

  if (AControl.Top < WorkArea.Top) then
  begin
    AControl.Height := AControl.Height - (WorkArea.Top - AControl.Top);
    AControl.Top := WorkArea.Top;
  end;

  if (AControl.Top + AControl.Height > WorkArea.Bottom) then
  begin
    AControl.Height := WorkArea.Bottom - AControl.Top;
  end;
end;

procedure Execute(ADataSet: TDataSet);
begin
  if ADataSet = nil then Exit;
  if FormChoose = nil then
    FormChoose := TFormChoose.Create(nil);
  with FormChoose do
  begin
    DBGrid1 := TDBGridEh.Create(FormChoose);
    DBGrid1.Parent := Panel2;
    DBGrid1.ReadOnly := True;
    DBGrid1.Flat := true;
    DBGrid1.Align := alClient;
    DBGrid1.ReadOnly := True;
    uFunction.SetFilter(DBGrid1);
    uFunction.ShowMutiColSort(DBGrid1);
    uFunction.ShowRecno(DBGrid1);
    DBGrid1.Options := DBGrid1.Options + [dgRowSelect];
    DBGrid1.OnKeyPress := DBGridKeyPress;
    DBGrid1.OnDblClick := DBGridDblClick;
    fDataSet := ADataSet;
    DataSource1.DataSet := FDataSet;
    DBGrid1.DataSource := DataSource1;
  end;
  FEdit := False;
  AdjustDropDownForm(FormChoose);
  uFunction.SetDataset(FormChoose.FDataSet);
  try
    FormChoose.ShowModal;
  finally
    FreeAndNil(FormChoose);
  end;
end;

procedure TFormChoose.BitBtn3Click(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

procedure TFormChoose.BitBtn1Click(Sender: TObject);
begin
  if not FDataSet.IsEmpty then
    FEdit := True;
  ModalResult := mrOk;
end;

procedure TFormChoose.DBGridKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    BitBtn1Click(nil);
end;

procedure TFormChoose.DBGridDblClick(Sender: TObject);
begin
  BitBtn1Click(nil);
end;

procedure TFormChoose.BitBtn2Click(Sender: TObject);
begin
  uPublicQuery.Execute(FDataSet);
end;

procedure TFormChoose.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

end.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值