请问有谁知道,我在对动态创建的combobox与Label进行拖动,拖动任何一个时另一个也一起动,就像是Label与Combobox是捆在一起的一样?(200分

  • 主题发起人 主题发起人 zengyixun
  • 开始时间 开始时间
Z

zengyixun

Unregistered / Unconfirmed
GUEST, unregistred user!
请问有谁知道,我在对动态创建的combobox与Label进行拖动,拖动任何一个时另一个也一起动,就像是Label与Combobox是捆在一起的一样?(200分)<br />请问有谁知道,我在对动态创建的combobox与Label进行拖动,
拖动任何一个时另一个也一起动,就像是Label与Combobox是捆在一起的一样?
还有一个问题就是,我对多个用动态数级建立的combobox与edit,我想在对一个combobox或
edit填写时,它的Text也能在另一个combobox与edit的框中反应出来?
 
把你怎么动态产生的代码贴出来看一看,这样很难知道问题出在那里!
 
使用下面方法试试:

procedure TForm1.ComboBox1DropDown(Sender: TObject);
const
SC_DragMove = $F012;
begin
ReleaseCapture;
ComboBox1.Perform(WM_SysCommand, SC_DragMove, 0);
Label1.Left:=ComboBox1.Left-Label1.Width ;
Label1.Top :=ComboBox1.Top ;
end;
 
还有个办法,将Label和ComboBox放到Panel中,定义Panel的动作就可以了,代码如下:
先声明
var
myPanel:Tpanel;

procedure TForm1.PanelMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
const
SC_DragMove = $F012;
begin
ReleaseCapture;
myPanel.Perform(WM_SysCommand, SC_DragMove, 0);

end;

procedure TForm1.FormCreate(Sender: TObject);
var
OldPanel:TPanel;
myLabel:TLabel;
myComboBox:TComboBox;
begin
myPanel:=Tpanel.Create(self);
myPanel.Parent :=Form1;
MyPanel.Top :=20;
MyPanel.Left :=20;
MyPanel.Width :=225;
MyPanel.Height :=33;
myPanel.BevelOuter :=bvNone;
MyPanel.Color :=clblue;

OldPanel:=TPanel.Create(self) ;
OldPanel.Parent :=myPanel;
OldPanel.Top :=10;
OldPanel.Left :=0;
OldPanel.Height :=23;
OldPanel.Width :=MyPanel.Width;

myLabel:=TLabel.Create(self);
myLabel.Parent :=OldPanel;
MyComboBox:=TComboBox.Create(self);
myComboBox.Parent :=OldPanel;
myLabel.Top :=1;
myLabel.Left :=1;
myLabel.Width :=60;
myLabel.Height :=20;
myLabel.Caption :='我的测试:';
myComboBox.Top:=1;
myComboBox.Left :=MyLabel.Width+1 ;
myComboBox.Width :=160;
myComboBox.Height :=20;
myComboBox.Items.Add('1aerqwe');
myComboBox.Items.Add('2aerqwe');
myComboBox.Items.Add('3aerqwe');
myPanel.OnMouseDown :=PanelMouseDown ;
myLabel.OnMouseDown :=PanelMouseDown ;
end;

上面代码动态创建,界面上拖动Lable和蓝色的标题栏时就可以实现了。
 
to Block_K_E
我想你的方法要好一些,不过不用combobox的拖动,我只用edit 与 Label一起动。
我的edit的拖动用的是mouseDown,mousemove,mouseup,所以我在mousemove一个动太
生成的edit的时候,怎么对另一个动态生成的label也跟着动?
 
to 李逍遥_神仙居

SetLength(mainform.vlmmc,dm.ADOQ2.RecordCount);
for i:=0 to dm.ADOQ2.RecordCount-1 do
begin
mainform.vlmmc:=TRxLabel.Create(Self);
Try
mainform.vlmmc.Name:='myvlmmc'+inttostr(i);
mainform.vlmmc.Parent:=mainform.ole1;
mainform.vlmmc.Caption:=trim(dm.ADOQ2.fieldbyname('lmmc').asstring);
//mainform.vlmmc.Cursor:=crSizeAll;
mainform.vlmmc.Font.Name:='宋体';
mainform.vlmmc.Font.Size:=10;
mainform.vlmmc.Font.Style:=[fsBold];
mainform.vlmmc.Left:=round(dm.ADOQ2.fieldbyname('left1').asinteger/10*3.78);
mainform.vlmmc.Top:=round(dm.ADOQ2.fieldbyname('top1').asinteger/10*3.78);
mainform.vlmmc.Transparent:=true;
mainform.vlmmc.OnMouseDown := mainform.RxLabellMouseDown;

mainform.vlmmc.OnMouseMove := mainform.RxLabellMouseMove;

mainform.vlmmc.OnMouseUp := mainform.RxLabellMouseUp;

Except
mainform.vlmmc.Free;
mainform.vlmmc:=nil;
end;
dm.ADOQ2.Next;
end;
SetLength(mainform.vEdit,dm.ADOQ2.RecordCount);
for i:=0 to dm.ADOQ2.RecordCount-1 do
begin
mainform.vEdit:=TFlatEdit.Create(Self);
Try
mainform.vEdit.Name:='myedit1'+inttostr(i);
mainform.vEdit.Parent:=mainform.ole1;
if trim(dm.ADOQ2.fieldbyname('text1').asstring)&lt;&gt;'-1' then
mainform.vEdit.Text:=trim(dm.ADOQ2.fieldbyname('text1').asstring)
else mainform.vEdit.Text:='';
mainform.vEdit.Font.Name:='宋体';
mainform.vEdit.Font.Size:=10;
mainform.vEdit.Font.Style:=[fsBold];
mainform.vEdit.Width:=round(dm.ADOQ2.fieldbyname('width1').asinteger/10*3.78);
mainform.vEdit.Left:=round(dm.ADOQ2.fieldbyname('left1').asinteger/10*3.78);
mainform.vEdit.top:=round(dm.ADOQ2.fieldbyname('top1').asinteger/10*3.78);
mainform.vEdit.ReadOnly:=true;
mainform.vEdit.OnMouseDown:=Mainform.editMouseDown;
mainform.vEdit.OnMouseMove:=Mainform.editMouseMove;
mainform.vEdit.OnMouseUp:=Mainform.editMouseUp;
//mainform.Cursor:=crSizeAll;
Except
mainform.vEdit.Free;
mainform.vEdit:=nil;
end;
dm.ADOQ2.Next;
end;

to Block_K_E

你的第二个方法,会把问题复杂化。我要创建的太多了。
 
你的代码原来如此!何必这样呢?你不是就要Label和Edit在一起吗?
使用Delphi 6 的Additional中的TLabeledEdit就可以了,没有必要建两次!
具体的控制你看看属性就知道了。
 
忘了一点。补充一下:

procedure TForm1.LabeledEdit1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
const
SC_DragMove = $F012;
begin
ReleaseCapture;
LabeledEdit1.Perform(WM_SysCommand, SC_DragMove, 0);
LabeledEdit1.LabelSpacing :=0; //这句必须要,否则不能跟着跑。
end;
 
不能用D6,我用的第用的RX控件没有D6的,谁有?最好有D5的解决办法。
 
RXLib2.75就可以,我这里就有!
或者你看看delphi6.0的LabeledEdit的源代码,自己在delphi5.0中编写一个就行了。
delphi6.0的LabeledEdit源代码在delphi6/source/vcl/Extctrls.pas中。
 
把Combox和Label放到Panel里。
然后一起
ReleaseCapture;
Panel1.Perform(WM_SYSCOMMAND, $F012, 0);
 
to zengyixun:
你的第一个问题已经解决。
对于第二个问题,你可以combobox或edit的onchange事件中,
将对方的text 赋值为自己的text。
另外,可以sendmessage(edit1.handle,wm_settext,0,integer(pchar(s)));
将文本copy.
 
我做的好象没这个问题
 
unit main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ImgList, ToolWin, Menus, StdCtrls, jpeg, ExtCtrls;

type
TForm1 = class(TForm)
CoolBar1: TCoolBar;
ImageList1: TImageList;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton7: TToolButton;
ToolButton8: TToolButton;
ScrollBox1: TScrollBox;
StatusBar1: TStatusBar;
Image1: TImage;
ToolButton3: TToolButton;
procedure ToolButton1Click(Sender: TObject);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ToolButton2Click(Sender: TObject);
procedure ToolButton4Click(Sender: TObject);
procedure ToolButton5Click(Sender: TObject);
procedure ToolButton6Click(Sender: TObject);
procedure ToolButton7Click(Sender: TObject);
procedure ToolButton8Click(Sender: TObject);
procedure ToolButton3Click(Sender: TObject);
private
{ Private declarations }
PX,PY:Integer;
IsMove:boolean;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses About;

{$R *.dfm}

procedure TForm1.ToolButton1Click(Sender: TObject);
begin
with TButton.Create(ScrollBox1) do
begin
Caption:='新按钮';
Parent :=ScrollBox1;
OnMouseDown:=Image1.OnMouseDown;
OnMouseMove:=Image1.OnMouseMove;
OnMouseUp:=Image1.OnMouseUp;
end;
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
PX:=X;
PY:=Y;
IsMove:=true;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
PX:=0;
PY:=0;
IsMove:=false;
end;

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if IsMove=false then exit;
with (Sender as TControl) do
begin
Left :=Left +X-PX;
Top :=Top +Y-Py;
end;
end;

procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
IsMove:=false;
end;

procedure TForm1.ToolButton2Click(Sender: TObject);
begin
with TCheckBox.Create(ScrollBox1) do
begin
Caption:='新复选按钮';
Parent :=ScrollBox1;
OnMouseDown:=Image1.OnMouseDown;
OnMouseMove:=Image1.OnMouseMove;
OnMouseUp:=Image1.OnMouseUp;
end;
end;

procedure TForm1.ToolButton4Click(Sender: TObject);
begin
with TEdit.Create(ScrollBox1) do
begin
Text:='新编辑框';
Parent :=ScrollBox1;
OnMouseDown:=Image1.OnMouseDown;
OnMouseMove:=Image1.OnMouseMove;
OnMouseUp:=Image1.OnMouseUp;
end;
end;

procedure TForm1.ToolButton5Click(Sender: TObject);
begin
with TLabel.Create(ScrollBox1) do
begin
Caption:='新标签';
Parent :=ScrollBox1;
OnMouseDown:=Image1.OnMouseDown;
OnMouseMove:=Image1.OnMouseMove;
OnMouseUp:=Image1.OnMouseUp;
end;
end;

procedure TForm1.ToolButton6Click(Sender: TObject);
begin
with TListBox.Create(ScrollBox1) do
begin
Parent :=ScrollBox1;
Items.Add('新列表框');
OnMouseDown:=Image1.OnMouseDown;
OnMouseMove:=Image1.OnMouseMove;
OnMouseUp:=Image1.OnMouseUp;
end;
end;

procedure TForm1.ToolButton7Click(Sender: TObject);
begin
with TMemo.Create(ScrollBox1) do
begin
Text:='新文本框';
Parent :=ScrollBox1;
OnMouseDown:=Image1.OnMouseDown;
OnMouseMove:=Image1.OnMouseMove;
OnMouseUp:=Image1.OnMouseUp;
end;
end;

procedure TForm1.ToolButton8Click(Sender: TObject);
begin
with TRadioButton.Create(ScrollBox1) do
begin
Caption:='新选择框';
Parent :=ScrollBox1;
OnMouseDown:=Image1.OnMouseDown;
OnMouseMove:=Image1.OnMouseMove;
OnMouseUp:=Image1.OnMouseUp;
end;
end;

procedure TForm1.ToolButton3Click(Sender: TObject);
begin
Form_About.ShowModal;
end;

end.

贴一段代码,自己看看,应该很简单的
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部