首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

delphi form1根form2的变量批改form1控件的属性

2013-12-04 
delphi form1根form2的变量修改form1控件的属性如题:我在form1里面有一个 panel ,form2 里面有一个index

delphi form1根form2的变量修改form1控件的属性
如题:
  我在form1里面有一个 panel ,form2 里面有一个index 我想当form2 .index =1 的时候
  form1.panel.left -10 现在我可以获取到index 在index =1 的时候 form1.panel.left -10 这个代码也执行了 但是位置没有变化 请问这个要怎么做啊 
[解决办法]
把Index作为Form2的属性来操作
Form1

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    pnl1: TPanel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
uses
Unit2;
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.Show;
end;

end.

Form2
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm2 = class(TForm)
    edt1: TEdit;
    Button1: TButton;
    Edit1: TEdit;
    lbl1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    Findex: Integer;       //储存Index
    function GetIndex: Integer;
    procedure setIndex(i: Integer);
  public
    { Public declarations }
    property index: Integer read GetIndex write setIndex;
  end;

var
  form2: TForm2;

implementation

{$R *.dfm}

uses
  Unit1;

procedure TForm2.setIndex(i: Integer);
begin
  if i > 0 then
  begin
    Findex := i;
    if Findex = 1 then
      Form1.pnl1.Left := Form1.pnl1.Left - 10;
  end;

end;

procedure TForm2.Button1Click(Sender: TObject);
begin
     index:=StrToIntdef(Edit1.Text,0);
end;

function TForm2.GetIndex: Integer;
begin
  Result := Findex;
end;

end.

热点排行