你click button6 ,焦点不就转移到button6上去了?
解决方案 »
- DELPHI如何利用BHO更改网页内容?
- _______ 恼人的TADOQuery和TADOTable更新问题!请教各位前辈!
- 怎样封装一个数据集成一个DataSet?
- 在创建COM+时,为什么要建立ActiveX DLL应该程序???在线等.
- 关于输入法编程的问题,200分!
- 请问如何能够的到当前运行的exe文件的名称?
- 请问大家在哪可找到关于Delphi中ClientDataSet编程的文章跟技巧!谢谢了!
- 请教:如何判断程序运行过程中一段时间内没有键盘和鼠标的操作。
- 重写一个tpanel,如何能caption属性置为空?
- NMUDP的端口问题?
- 有关delphi和SQL的问题...........在线等待!。。。。。。。。。。
- HELP ME ! 我在A这个OCX控件里调用了B这个OCX控件,我在注册B这个控件时正确,我在注册A这个控件时系统一直报找不到指定的模块,但我发
所以也无法执行其里面的语句!
Edit5.text:=Edit5.text+'l';
有点象计算器上输入数字的感觉!!
var
sTmp : string;
begin
iSel := edtText.SelStart; // iSel為全局變量
sTmp := edtText.Text; edtText.Text := copy(sTmp,1,iSel)
+ (sender as TButton).Caption
+ copy(sTmp,iSel+1,length(sTmp)-iSel+1);
edtText.SelStart := iSel+1;
edtText.SetFocus;
end;
当用户点击BUTTON6,如果光标在EDIT1中则显示在EDIT1中,如果在EDIT2中则显示在EDIT2中...
哦!这样不行,因为还有很多的EDIT,不能确定是哪一个,用户点BUTTON6,如果光标在EDIT1中则显示在EDIT1中,如果在EDIT2中则显示在EDIT2中,
当用户点击BUTTON7,如果光标在EDIT1中则显示在EDIT1中,如果在EDIT2中则显示在EDIT2中...
兩個TButton放在form上,Button1,Button2(共用按下的事件)
edtText,edtDisp的進入事件也是共用的
edtText.Tag := 1; edtDisp.Tag := 2(用來區別當前焦點在哪個Edit上)
有個全局變量 iTag;
我測試過沒有甚麼大問題,我把所有的都貼出來,應該能看懂object Form1: TForm1
Left = 228
Top = 107
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 384
Top = 40
Width = 75
Height = 25
Caption = '1'
TabOrder = 0
OnClick = Button1Click
end
object Button2: TButton
Left = 384
Top = 88
Width = 75
Height = 25
Caption = '2'
TabOrder = 1
OnClick = Button1Click
end
object pnlMain: TPanel
Left = 88
Top = 0
Width = 257
Height = 321
TabOrder = 2
object edtDisp: TEdit
Tag = 2
Left = 64
Top = 80
Width = 121
Height = 21
TabOrder = 0
Text = 'edtDisp'
OnEnter = edtTextEnter
end
object edtText: TEdit
Tag = 1
Left = 64
Top = 24
Width = 121
Height = 21
TabOrder = 1
Text = 'edtText'
OnEnter = edtTextEnter
end
end
endunit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
pnlMain: TPanel;
edtDisp: TEdit;
edtText: TEdit;
procedure Button1Click(Sender: TObject);
procedure edtTextEnter(Sender: TObject);
private
{ Private declarations }
iTag : integer;
function GetMyComponent(Sender: TWinControl; iTag: Integer):TControl;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}
function TForm1.GetMyComponent(Sender: TWinControl; iTag: Integer):TControl;
var
i: integer;
begin
Result := Nil ;
for i := 0 to Sender.ControlCount-1 do
if Sender.Controls[i] is TWinControl then
begin
if (Sender.Controls[i] as TWinControl).tag = iTag then Result := Sender.Controls[i] ;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
sTmp : string;
iSel: integer;
begin
if iTag = 0 then Exit; iSel := (GetMyComponent(pnlMain,iTag) as TEdit).SelStart; // iSel為全局變量
sTmp := (GetMyComponent(pnlMain,iTag) as TEdit).Text; (GetMyComponent(pnlMain,iTag) as TEdit).Text := copy(sTmp,1,iSel)
+ (sender as TButton).Caption
+ copy(sTmp,iSel+1,length(sTmp)-iSel+1);
(GetMyComponent(pnlMain,iTag) as TEdit).SelStart := iSel+1;
(GetMyComponent(pnlMain,iTag) as TEdit).SetFocus;
end;procedure TForm1.edtTextEnter(Sender: TObject);
begin
iTag := ActiveControl.Tag;
end;end.
把你的程序贴出来看看好吗?应该不会有什么错误的