[问题] 动态TForm使用事件处理器

楼主: Leeng (Leeng)   2014-07-10 10:18:35
开发平台(Platform): (Ex: VC++, GCC, Linux, ...)
BCB(XE2)
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
VCL
问题(Question):
我用一个function,一次可动态产生一个TForm;该Form底下会有一个TMemo
我希望Resize该Form时,可同时调整Memo的宽高。
程式码(Code):(请善用置底文网页, 记得排版)
class MemoForm
{
public:
MemoForm(){}
~MemoForm(){}
TForm *_Form;
TMemo *_Memo;
};
MemoForm *CreateMemoForm(String str)
{
MemoForm *mFrm = new MemoForm;
// Implement _Form
mFrm->_Form = new TForm(Form1);
mFrm->_Form->Caption = str;
mFrm->_Form->OnResize = MemoFormResize;
// Implement _Memo
mFrm->_Memo = new TMemo(Frm->_Form);
mFrm->_Memo->Parent = mFrm->_Form;
mFrm->_Memo->ScrollBars = ssBoth;
mFrm->_Memo->Top = 0;
mFrm->_Memo->Left = 0;
mFrm->_Memo->Width = mFrm->_Form->Width - 5;
mFrm->_Memo->Height = mFrm->_Form->Height - 28;
mFrm->_Memo->Lines->Add(str);
mFrm->_Form->Show();
return mFrm;
}
void __fastcall TForm1::MemoFormResize(TObject *Sender)
{
TForm *pForm = dynamic_cast<TForm*>(Sender);
if(pForm)
{
/*pForm->_Memo->Width = _Form->Width-5;
pForm->_Memo->Height = _Form->Height-28;*/
// Compilation failed, for _Memo is not a member of TForm
}
}
有没有办法在事件处理器中,连结到_Memo???
谢谢
作者: scwg ( )   2014-07-10 11:57:00
把 mFrm 存到 _Form->Tag 可以拿到所有元件不过原始程式码有几个地方变量名好像跑掉了 (Form1? Frm?)不是很确定, 可能有更好的方法

Links booklink

Contact Us: admin [ a t ] ucptt.com