PopForm.pas
上传用户:fh681027
上传日期:2022-07-23
资源大小:1959k
文件大小:3k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit PopForm;
  2. interface
  3. uses
  4.   SysUtils, Windows, Classes, Graphics, Forms, Controls,
  5.   StdCtrls, Menus, Dialogs, ExtCtrls;
  6. type
  7.   TFormPopup = class(TForm)
  8.     ColorDialog1: TColorDialog;
  9.     PopupMenu1: TPopupMenu;
  10.     BackColor2: TMenuItem;
  11.     PopupMenu2: TPopupMenu;
  12.     Left2: TMenuItem;
  13.     Center2: TMenuItem;
  14.     Right2: TMenuItem;
  15.     Label1: TLabel;
  16.     Label2: TLabel;
  17.     Label3: TLabel;
  18.     procedure Label3MouseDown(Sender: TObject; Button: TMouseButton;
  19.       Shift: TShiftState; X, Y: Integer);
  20.     procedure Label1ContextPopup(Sender: TObject; MousePos: TPoint;
  21.       var Handled: Boolean);
  22.     procedure Left2Click(Sender: TObject);
  23.     procedure Center2Click(Sender: TObject);
  24.     procedure Right2Click(Sender: TObject);
  25.     procedure BackColor2Click(Sender: TObject);
  26.     procedure Label2ContextPopup(Sender: TObject; MousePos: TPoint;
  27.       var Handled: Boolean);
  28.   end;
  29. var
  30.   FormPopup: TFormPopup;
  31. implementation
  32. {$R *.DFM}
  33. procedure TFormPopup.Label3MouseDown(Sender: TObject;
  34.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  35. var
  36.   ClientPoint, ScreenPoint: TPoint;
  37. begin
  38.   if Button = mbRight then
  39.   begin
  40.     ClientPoint.X := X;
  41.     ClientPoint.Y := Y;
  42.     ScreenPoint := Label3.ClientToScreen (ClientPoint);
  43.     PopupMenu1.Popup (ScreenPoint.X, ScreenPoint.Y)
  44.   end;
  45. end;
  46. procedure TFormPopup.Label1ContextPopup(Sender: TObject;
  47.   MousePos: TPoint; var Handled: Boolean);
  48. var
  49.   ScreenPoint: TPoint;
  50. begin
  51.   // add dynamic items
  52.   PopupMenu2.Items.Add (NewLine);
  53.   PopupMenu2.Items.Add (NewItem (TimeToStr (Now),
  54.     0, False, True, nil, 0, ''));
  55.   // show popup
  56.   ScreenPoint := ClientToScreen (MousePos);
  57.   PopupMenu2.Popup (ScreenPoint.X, ScreenPoint.Y);
  58.   Handled := True;
  59.   // remove dynamic items
  60.   PopupMenu2.Items [4].Free;
  61.   PopupMenu2.Items [3].Free;
  62. end;
  63. procedure TFormPopup.Left2Click(Sender: TObject);
  64. begin
  65.   Label1.Alignment := taLeftJustify;
  66.   (Sender as TMenuItem).Checked := True;
  67. end;
  68. procedure TFormPopup.Center2Click(Sender: TObject);
  69. begin
  70.   Label1.Alignment := taCenter;
  71. end;
  72. procedure TFormPopup.Right2Click(Sender: TObject);
  73. begin
  74.   Label1.Alignment := taRightJustify;
  75. end;
  76. procedure TFormPopup.BackColor2Click(Sender: TObject);
  77. begin
  78.   ColorDialog1.Color := Label3.Color;
  79.   if ColorDialog1.Execute then
  80.     Label3.Color := ColorDialog1.Color;
  81. end;
  82. procedure TFormPopup.Label2ContextPopup(Sender: TObject;
  83.   MousePos: TPoint; var Handled: Boolean);
  84. begin
  85.   ColorDialog1.Color := Label2.Color;
  86.   if ColorDialog1.Execute then
  87.     Label2.Color := ColorDialog1.Color;
  88.   Handled := True;
  89. end;
  90. end.