问题解决了-谁进来就拿分结贴!-为什么D5下文字拖到RichEdit 可以鼠标指针跟随,D7下就不可以?还是什么地方设置错了? ( 积分: 50 )

  • 主题发起人 主题发起人 avbb4cat
  • 开始时间 开始时间
A

avbb4cat

Unregistered / Unconfirmed
GUEST, unregistred user!
D5下可以实现,但是D7下就看不到那个Bean!
望各位大侠解惑!
procedure TForm1.ListBox1MouseDown(Sender: TObject
Button: TMouseButton;
Shift: TShiftState
X, Y: Integer);
begin
inherited;
if(Button=mbLeft)and(not (ssDouble in Shift))then
with Sender as TCustomListBox do
begin
if(ItemAtPos(Point(X, Y), True)=ItemIndex)and(ItemIndex>=0)then begin
BeginDrag(False);
end;
end;
end;

procedure TForm1.RichEdit1DragOver(Sender, Source: TObject
X, Y: Integer;
State: TDragState
var Accept: Boolean);
var
P: TPoint;
Idx: Integer;
RichEdit:TRichEdit;
begin
RichEdit := TRichEdit(Sender);
if (TWinControl(Source).ClassName='TListBox') then
Accept := True;

if Accept then
begin
if not RichEdit.Focused then RichEdit.SetFocus;
P := Point(X,Y);
Idx := SendMEssage(RichEdit.Handle,EM_CHARFROMPOS,0,Integer(@P));
if Idx>=0 then
RichEdit.SelStart := Idx;
end;
end;

procedure TForm1.RichEdit1DragDrop(Sender, Source: TObject
X, Y: Integer);
var
ListBox: TListBox;
RichEdit: TRichEdit;
begin
RichEdit := TRichEdit(Sender);
if Source.ClassName='TListBox' then
begin
ListBox := TListBox(Source);
RichEdit.SetSelTextBuf(PChar(' ' + ListBox.Items[ListBox.ItemIndex] + ' '));
end;
end;
 
D5下可以实现,但是D7下就看不到那个Bean!
望各位大侠解惑!
procedure TForm1.ListBox1MouseDown(Sender: TObject
Button: TMouseButton;
Shift: TShiftState
X, Y: Integer);
begin
inherited;
if(Button=mbLeft)and(not (ssDouble in Shift))then
with Sender as TCustomListBox do
begin
if(ItemAtPos(Point(X, Y), True)=ItemIndex)and(ItemIndex>=0)then begin
BeginDrag(False);
end;
end;
end;

procedure TForm1.RichEdit1DragOver(Sender, Source: TObject
X, Y: Integer;
State: TDragState
var Accept: Boolean);
var
P: TPoint;
Idx: Integer;
RichEdit:TRichEdit;
begin
RichEdit := TRichEdit(Sender);
if (TWinControl(Source).ClassName='TListBox') then
Accept := True;

if Accept then
begin
if not RichEdit.Focused then RichEdit.SetFocus;
P := Point(X,Y);
Idx := SendMEssage(RichEdit.Handle,EM_CHARFROMPOS,0,Integer(@P));
if Idx>=0 then
RichEdit.SelStart := Idx;
end;
end;

procedure TForm1.RichEdit1DragDrop(Sender, Source: TObject
X, Y: Integer);
var
ListBox: TListBox;
RichEdit: TRichEdit;
begin
RichEdit := TRichEdit(Sender);
if Source.ClassName='TListBox' then
begin
ListBox := TListBox(Source);
RichEdit.SetSelTextBuf(PChar(' ' + ListBox.Items[ListBox.ItemIndex] + ' '));
end;
end;
 
问题找到了: 在同一个From上是没有问题的,可以正常显示,但是如果是两个MdiChildFrm,相互拖动就不能在文字间出现那个竖线,不知道应什么办法可以解决!
 
自己解决问题了:
if not RichEdit.Focused then
begin
if Application.MainForm.ActiveMDIChild<>Self then
Self.BringToFront;
Windows.SetFocus(RichEdit.Handle);
end;
随便哪位大侠过来拿分吧!
祝进来看的大侠们新年快乐!
没有进来的帮助过我和其他菜鸟的大侠们也新年快乐!
呵呵!
 
[red]恭喜[/red][:D]
 

Similar threads

后退
顶部