模拟delphi编辑窗体操作控件

2016-02-19 19:57 38 1 收藏

get新技能是需要付出行动的,即使看得再多也还是要动手试一试。今天图老师小编跟大家分享的是模拟delphi编辑窗体操作控件,一起来学习了解下吧!

【 tulaoshi.com - 编程语言 】

 

  unit Unit1;

  interface

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

  uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, ExtCtrls, StdCtrls, jpeg;
  const LMouseDown=False;
  type
    TForm1 = class(TForm)
      Edit1: TEdit;
      Panel2: TPanel;
      Panel1: TPanel;
      Panel3: TPanel;
      Panel4: TPanel;
      Panel5: TPanel;
      Panel6: TPanel;
      Panel7: TPanel;
      Panel8: TPanel;
      Panel11: TPanel;
      Panel22: TPanel;
      Panel33: TPanel;
      Panel44: TPanel;
      Panel55: TPanel;
      Panel66: TPanel;
      Panel77: TPanel;
      Panel88: TPanel;
      Button1: TButton;
      procedure Edit1MouseMove(Sender: TObject; Shift: TShiftState; X,
        Y: Integer);
      procedure Edit1MouseDown(Sender: TObject; Button: TMouseButton;
        Shift: TShiftState; X, Y: Integer);
      procedure Edit1MouseUp(Sender: TObject; Button: TMouseButton;
        Shift: TShiftState; X, Y: Integer);
      procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
        Shift: TShiftState; X, Y: Integer);
      procedure Button1MouseDown(Sender: TObject; Button: TMouseButton;
        Shift: TShiftState; X, Y: Integer);
      procedure Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
        Y: Integer);
      procedure Button1MouseUp(Sender: TObject; Button: TMouseButton;
        Shift: TShiftState; X, Y: Integer);
    private
      { Private declarations }
    public
      { Public declarations }
    end;

  var
    Form1: TForm1;
    s,a:boolean;
  implementation

  {$R *.dfm}

   procedure ManipulateControl(Control: TControl; Shift: TShiftState; X, Y, Precision: integer);
  var SC_MANIPULATE: Word;
  begin
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //光标在控件的最左侧**********************************************************
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         if (X=Precision) and (YPrecision) and (YControl.Height-Precision)
    then begin
           SC_MANIPULATE  := $F001;
           Control.Cursor := crSizeWE;
         end
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //光标在控件的最右侧**********************************************************
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    else if (X=Control.Width-Precision) and (YPrecision) and (YControl.Height-Precision)
    then begin
           SC_MANIPULATE  := $F002;
           Control.Cursor := crSizeWE;
         end
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //光标在控件的最上侧**********************************************************
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    else if (XPrecision) and (XControl.Width-Precision) and (Y=Precision)
    then begin
           SC_MANIPULATE  := $F003;
           Control.Cursor := crSizeNS;
         end
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //光标在控件的左上角**********************************************************
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    else if (X=Precision) and (Y=Precision)
    then begin
           SC_MANIPULATE  := $F004;
           Control.Cursor := crSizeNWSE;
         end
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //光标在控件的右上角**********************************************************
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    else if (X=Control.Width-Precision) and (Y=Precision)
    then begin
           SC_MANIPULATE  := $F005;
           Control.Cursor := crSizeNESW    ;
         end
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //光标在控件的最下侧**********************************************************
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    else if (XPrecision) and (XControl.Width-Precision) and (Y=Control.Height-Precision)
    then begin
           SC_MANIPULATE  := $F006;
           Control.Cursor := crSizeNS;
         end
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //光标在控件的左下角**********************************************************
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    else if (X=Precision) and (Y=Control.Height-Precision)
    then begin
           SC_MANIPULATE  := $F007;
           Control.Cursor := crSizeNESW;
         end
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //光标在控件的右下角**********************************************************
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    else if (X=Control.Width-Precision) and (Y=Control.Height-Precision)
    then begin
           SC_MANIPULATE  := $F008;
           Control.Cursor := crSizeNWSE;
         end
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //光标在控件的客户区(移动整个控件)******************************************
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    else if (X5) and (Y5) and (XControl.Width-5) and (YControl.Height-5)
    then begin
           SC_MANIPULATE  := $F009;
           Control.Cursor := crSizeAll;
         end
    else begin
           SC_MANIPULATE := $F000;
           Control.Cursor := crDefault;
         end;
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    if Shift=[ssLeft] then
    begin
      ReleaseCapture;
      Control.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0);
    end;
    end;
  procedure TForm1.Edit1MouseMove(Sender: TObject; Shift: TShiftState; X,
    Y: Integer);
  begin
    ManipulateControl((Sender as TControl), Shift, X, Y, 9);
    edit1.Hint:='Edit1:TEdit'+chr(13)+'Origin:'+IntToStr(edit1.Top)+','
    +IntToStr(edit1.Left)+';'+'Size:'+IntToStr(edit1.Width)+IntToStr(edit1.Height)+chr(13)+'Tab Stop:Ture;Order:0';
          if s=true then
          begin
          a:=false;
          panel1.Visible:=true;      panel2.Visible:=true;     panel3.Visible:=true;
          panel4.Visible:=true;      panel5.Visible:=true;
          panel6.Visible:=true;      panel7.Visible:=true;     panel8.Visible:=true;
          panel1.top:=edit1.Top-6;
          panel1.Left:=edit1.Left-6;
          panel2.Top:=edit1.Top+(edit1.Height div 2)-3;
          panel2.Left:=edit1.Left-6;
          panel3.Top:=edit1.Top+edit1.Height;
          panel3.Left:=edit1.Left-6;
          panel4.Top:=edit1.top-6;
          panel4.Left:=edit1.Left+(edit1.Width div 2);
          panel5.Top:=edit1.Top+edit1.Height;
          panel5.Left:=edit1.Left+(edit1.Width div 2);
          panel6.Top:=edit1.Top-6;
          panel6.Left:=edit1.Left+edit1.Width;
          panel7.Top:=edit1.Top+(edit1.Height div 2)-3;
          panel7.Left:=edit1.Left+edit1.Width;
          panel8.top:=edit1.Top+edit1.Height;
          panel8.Left:=edit1.Left+edit1.Width;
          end;
  end;

  procedure TForm1.Edit1MouseDown(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
  begin

          panel11.Visible:=false;      panel22.Visible:=false;     panel33.Visible:=false;
          panel44.Visible:=false;      panel55.Visible:=false;
          panel66.Visible:=false;      panel77.Visible:=false;     panel88.Visible:=false;

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

    s:=true;
    a:=false;
          panel1.Visible:=true;      panel2.Visible:=true;     panel3.Visible:=true;
          panel4.Visible:=true;      panel5.Visible:=true;
          panel6.Visible:=true;      panel7.Visible:=true;     panel8.Visible:=true;
          panel1.top:=edit1.Top-6;
          panel1.Left:=edit1.Left-6;
          panel2.Top:=edit1.Top+(edit1.Height div 2)-3;
          panel2.Left:=edit1.Left-6;
          panel3.Top:=edit1.Top+edit1.Height;
          panel3.Left:=edit1.Left-6;
          panel4.Top:=edit1.top-6;
          panel4.Left:=edit1.Left+(edit1.Width div 2);
          panel5.Top:=edit1.Top+edit1.Height;
          panel5.Left:=edit1.Left+(edit1.Width div 2);
          panel6.Top:=edit1.Top-6;
          panel6.Left:=edit1.Left+edit1.Width;
          panel7.Top:=edit1.Top+(edit1.Height div 2)-3;
          panel7.Left:=edit1.Left+edit1.Width;
          panel8.top:=edit1.Top+edit1.Height;
          panel8.Left:=edit1.Left+edit1.Width;
  end;

  procedure TForm1.Edit1MouseUp(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
  begin
          if s=true then
          begin
          a:=false;
          s:=false;
          panel1.Visible:=true;      panel2.Visible:=true;     panel3.Visible:=true;
          panel4.Visible:=true;      panel5.Visible:=true;
          panel6.Visible:=true;      panel7.Visible:=true;     panel8.Visible:=true;
          panel1.top:=edit1.Top-6;
          panel1.Left:=edit1.Left-6;
          panel2.Top:=edit1.Top+(edit1.Height div 2)-3;
          panel2.Left:=edit1.Left-6;
          panel3.Top:=edit1.Top+edit1.Height;
          panel3.Left:=edit1.Left-6;
          panel4.Top:=edit1.top-6;
          panel4.Left:=edit1.Left+(edit1.Width div 2);
          panel5.Top:=edit1.Top+edit1.Height;
          panel5.Left:=edit1.Left+(edit1.Width div 2);
          panel6.Top:=edit1.Top-6;
          panel6.Left:=edit1.Left+edit1.Width;
          panel7.Top:=edit1.Top+(edit1.Height div 2)-3;
          panel7.Left:=edit1.Left+edit1.Width;
          panel8.top:=edit1.Top+edit1.Height;
          panel8.Left:=edit1.Left+edit1.Width;
          end;
  end;
  procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
  begin
  a:=false;
  s:=false;
          panel1.Visible:=false;      panel2.Visible:=false;     panel3.Visible:=false;
          panel4.Visible:=false;      panel5.Visible:=false;
          panel6.Visible:=false;      panel7.Visible:=false;     panel8.Visible:=false;
         //**********
          panel11.Visible:=false;      panel22.Visible:=false;     panel33.Visible:=false;
          panel44.Visible:=false;      panel55.Visible:=false;
          panel66.Visible:=false;      panel77.Visible:=false;     panel88.Visible:=false;

  end;
  procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);
  begin if a=true then
          begin
          a:=false;
          s:=false;
          panel1.Visible:=false;      panel2.Visible:=false;     panel3.Visible:=false;
          panel4.Visible:=false;      panel5.Visible:=false;
          panel6.Visible:=false;      panel7.Visible:=false;     panel8.Visible:=false;

          panel11.Visible:=true;
          panel22.Visible:=true;
          panel33.Visible:=true;
          panel44.Visible:=true;
          panel55.Visible:=true;
          panel66.Visible:=true;
          panel77.Visible:=true;
          panel88.Visible:=true;
          panel11.top:=Button1.Top-6;
          panel11.Left:=Button1.Left-6;
          panel22.Top:=Button1.Top+(Button1.Height div 2)-3;
          panel22.Left:=Button1.Left-6;
          panel33.Top:=Button1.Top+Button1.Height;
          panel33.Left:=Button1.Left-6;
          panel44.Top:=Button1.top-6;
          panel44.Left:=Button1.Left+(Button1.Width div 2);
          panel55.Top:=Button1.Top+Button1.Height;
          panel55.Left:=Button1.Left+(Button1.Width div 2);
          panel66.Top:=Button1.Top-6;
          panel66.Left:=Button1.Left+Button1.Width;
          panel77.Top:=Button1.Top+(Button1.Height div 2)-3;
          panel77.Left:=Button1.Left+Button1.Width;
          panel88.top:=Button1.Top+Button1.Height;
          panel88.Left:=Button1.Left+Button1.Width;
          end;
  end;
   procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
  begin
      a:=true;
      s:=false;
          panel1.Visible:=false;      panel2.Visible:=false;     panel3.Visible:=false;
          panel4.Visible:=false;      panel5.Visible:=false;
          panel6.Visible:=false;      panel7.Visible:=false;     panel8.Visible:=false;

          panel11.Visible:=true;      panel22.Visible:=true;     panel33.Visible:=true;
          panel44.Visible:=true;      panel55.Visible:=true;
          panel66.Visible:=true;      panel77.Visible:=true;     panel88.Visible:=true;
          panel11.top:=Button1.Top-6;
          panel11.Left:=Button1.Left-6;
          panel22.Top:=Button1.Top+(Button1.Height div 2)-3;
          panel22.Left:=Button1.Left-6;
          panel33.Top:=Button1.Top+Button1.Height;
          panel33.Left:=Button1.Left-6;
          panel44.Top:=Button1.top-6;
          panel44.Left:=Button1.Left+(Button1.Width div 2);
          panel55.Top:=Button1.Top+Button1.Height;
          panel55.Left:=Button1.Left+(Button1.Width div 2);
          panel66.Top:=Button1.Top-6;
          panel66.Left:=Button1.Left+Button1.Width;
          panel77.Top:=Button1.Top+(Button1.Height div 2)-3;
          panel77.Left:=Button1.Left+Button1.Width;
          panel88.top:=Button1.Top+Button1.Height;
          panel88.Left:=Button1.Left+Button1.Width;
  end;

   procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
    Y: Integer);
  begin
    ManipulateControl((Sender as TControl), Shift, X, Y, 9);
    edit1.Hint:='Button1:TButton'+chr(13)+'Origin:'+IntToStr(Button1.Top)+','
    +IntToStr(Button1.Left)+';'+'Size:'+IntToStr(Button1.Width)+IntToStr(Button1.Height)+chr(13)+'Tab Stop:Ture;Order:0';
        
       
         if a=true then
          begin
          s:=false;
          panel1.Visible:=false;      panel2.Visible:=false;     panel3.Visible:=false;
          panel4.Visible:=false;      panel5.Visible:=false;
          panel6.Visible:=false;      panel7.Visible:=false;     panel8.Visible:=false;

          panel11.Visible:=true;      panel22.Visible:=true;     panel33.Visible:=true;
          panel44.Visible:=true;      panel55.Visible:=true;
          panel66.Visible:=true;      panel77.Visible:=true;     panel88.Visible:=true;
          panel11.top:=Button1.Top-6;
          panel11.Left:=Button1.Left-6;
          panel22.Top:=Button1.Top+(Button1.Height div 2)-3;
          panel22.Left:=Button1.Left-6;
          panel33.Top:=Button1.Top+Button1.Height;
          panel33.Left:=Button1.Left-6;
          panel44.Top:=Button1.top-6;
          panel44.Left:=Button1.Left+(Button1.Width div 2);
          panel55.Top:=Button1.Top+Button1.Height;
          panel55.Left:=Button1.Left+(Button1.Width div 2);
          panel66.Top:=Button1.Top-6;
          panel66.Left:=Button1.Left+Button1.Width;
          panel77.Top:=Button1.Top+(Button1.Height div 2)-3;
          panel77.Left:=Button1.Left+Button1.Width;
          panel88.top:=Button1.Top+Button1.Height;
          panel88.Left:=Button1.Left+Button1.Width;
          end;
  end;

  end.

来源:https://www.tulaoshi.com/n/20160219/1622354.html

延伸阅读
  unit USWLMSelectDa; {$S-,W-,R-}                                             ...
摘要:讲述了如何向 TreeView 控件添加数据绑定功能,它是一系列 Microsoft Windows 控件开发示例之一。您可以将本文与相关的概述文章结合起来阅读。 简介 在可能的情况下,您应该先使用些现成的控件;因为提供的 Microsoft® Windows® 窗体控件中包含大量编码和测试成果,如果您要放弃它们从头开始,无疑是一种巨大的浪费...
一、引入Dialog技术 下面介绍在制作ActiveX控件时引入有模式对话框技术,制作步骤如下: 创建一新的MFC ActiveX ControlWizard项目,取名为Hello,其他用缺省选项; 在ResourceView页中新增一对话框资源,命名为IDD_HELLODIALOG,可以在对话框上放自己的控件; 为对话框资源IDD_HELLODIALOG创建新...
标签: Delphi
  实践第一步——分析和设计 Delphi为我们提供的组件中,有一个Label控件,它完成了最基本的单行文本标签功能。不过它的功能实在是太有限啦,总是在那里灰不溜秋地趴着。现在我们给它增加点动态效果,让它成为一个可以在鼠标经过时改变外表的标签——TouchLabel。也就是说,在Label的基础上,我们要给它添加几个属性,使鼠标经...
标签: Delphi
我还是一个半瓢水的程序员,因此目前为止我所能努力达到的境界是: 一个半瓢水的程序员,管他会不会写控件,只要能拿来改就可以了。 使用过Delphi的朋友都知道,我们在设计Delphi应用程序的某一功能时总是希望能够有现成的第三方免费控件可以拿来使用。但实际情况往往是,网上的控件确实种类繁多,优秀作品也数不胜数,但真正完...

经验教程

141

收藏

47
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部