Actiev Form 不能响应 BaskSpace Arrow Left... 的问题。

NND,先写个关键字,省得像我一样的倒霉孩子找不到解决的办法。万一我这块砖头引出何氏璧呢。

关键字:Active Form ,Web,ActiveX,按键,失效,响应,焦点,退格键,箭头键。嘿嘿,多了点。

就是这么个东西,ActiveForm 嵌入 Web 后什么TEdit啦、TMemo啦不能退格。

费劲周折,用拙略的手法写了几行代码,倒是能基本上解决问题,不过还是有问题,等想到再说。

先说说思路。窗体上撇一个定时器Timer1,然后让他不断扫描某几个键是否按下,然后枚举窗体上的所有控件,根据是不是TMemo and TEdit,分别处理。

代码如下:

void __fastcall TSimplyBlogForm::Timer1Timer(TObject *Sender)
{
    bool hasKeyDown;
    hasKeyDown=false;
    AnsiString Key;
    if (GetAsyncKeyState(VK_BACK)!=0)
    {
        Key="BACK";
        hasKeyDown=true;
    }
    if (GetAsyncKeyState(VK_LEFT)!=0)
    {
        Key="LEFT";
        hasKeyDown=true;
    }
    if (GetAsyncKeyState(VK_RIGHT)!=0)
    {
        Key="RIGHT";
        hasKeyDown=true;
    }
    if ( hasKeyDown==true)
    {
        Timer1->Enabled=false;
        Memo1->Lines->Add(Key);
        for (int i=0;i<this->ControlCount;i++)
        {
            AnsiString ClassName;
            ClassName=this->Controls[i]->ClassName();
            if (ClassName=="TbsSkinGroupBox")
            {
                TbsSkinGroupBox * temp;
                temp=(TbsSkinGroupBox *)this->Controls[i];//由于俺的控件都撇到GroupBox里了,所以,从第二层开始判断是不是输入型控件。自己改改吧。

                for (int e=0;e<temp->ControlCount;e++)
                {

                    AnsiString ChildClassName;
                    ChildClassName=temp->Controls[e]->ClassName();

 

                    if (ChildClassName=="TbsSkinEdit"  )
                    {


                        TbsSkinEdit * tempEdit;

                        tempEdit=(TbsSkinEdit*)temp->Controls[e];
                        if (tempEdit->Focused()==true)
                        {

                            int i;

                            i= tempEdit->SelStart;

                            if (Key=="BACK")
                            {
                                tempEdit->Text=tempEdit->Text.SubString(1,tempEdit->SelStart-1)+tempEdit->Text.SubString(tempEdit->SelStart+1,tempEdit->Text.Length()-tempEdit->SelStart+1);
                                tempEdit->SelStart   =i-1;

                            }

                            if (Key=="LEFT")
                            {
                                tempEdit->SelStart   =i-1;

                            }
                            if (Key=="RIGHT")
                            {
                                tempEdit->SelStart   =i+1;
                            }
                            break;
                        }
                    }
                    if (ChildClassName=="TbsSkinMemo2" )
                    {


                        TbsSkinMemo2 * tempMemo;

                        tempMemo=(TbsSkinMemo2*)temp->Controls[e];
                        if (tempMemo->Focused()==true)
                        {

                            int i;

                            i= tempMemo->SelStart;

                            if (Key=="BACK")
                            {
                                tempMemo->Text=tempMemo->Text.SubString(1,tempMemo->SelStart-1)+tempMemo->Text.SubString(tempMemo->SelStart+1,tempMemo->Text.Length()-tempMemo->SelStart+1);

                                tempMemo->SelStart   =i-1;

                            }

                            if (Key=="LEFT")
                            {
                                tempMemo->SelStart   =i-1;

                            }
                            if (Key=="RIGHT")
                            {
                                tempMemo->SelStart   =i+1;
                            }
                               break;
                        }
                    }
                }
            }
        }
       Timer1->Enabled=true;
    }
}
实在看不下去的看官就干脆别看了,我自己看着都头晕。

发表于 2005-10-30 09:48

评论

尚无评论

发表评论

标题:  
署名:  
链接:
内容:
验证码: