在多种形式之间切换 [英] switch betwwen multiple form

查看:68
本文介绍了在多种形式之间切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pls帮助....通过Internet搜索,但没有超过2种形式之间切换的示例....

我有3种形式,形式a,b,c;
我想这样,形成一个可以切换到形成b和c的形式,
形式b可以转换为a和c,形式c可以转换为a和b.

因为形式a是我的主要形式..我从其他形式转换成形式a ...没有问题(我使用this-> hide()来显示形式a);
但是当我使用c表格时,我想显示b表格吗?如果我包含b.h表格,那么我
当我想从表单b切换到表单c时遇到了问题.我无法在表单b中包括表单c.h ....

任何使我所有表单都可以自由切换的方法?

pls help....search through internet but no example on switch between more than 2 forms....

i had 3 form ,form a,b,c;
i want to make it like this,form a can switch to form b and c,
form b can switch to form a and c,form c can switch to form a and b.

as form a is my main form..i had no problem to switch from other form to form a...(i use this->hide() to show form a);
but when i in form c,i want to show form b,how?if i include form b.h then i
had problem when i wan to switch to form c from form b..i cant include form c.h in my form b ....

any method to make all my form can freely switch between?

推荐答案

就像一个简单的例子一样.请记住,这只是一个功能性示例,并且代码并非应有的全部.好了,也就是说,这是用于切换表格的类.

As promised a simple example. Remember that it is just a functional example and that the code isn''t all how it should be. Well, that said, here is the class used to toggle the forms.

ref class ToggleForm
{
public:
    ToggleForm(void)
    {
        current = 0;
        //formlist = gcnew ArrayList()
    };
    void addForm(Form^ form)
    {
        formlist.Add(form);
    };
    void next(void)
    {
        moveToForm(1);
    };
    void previous(void)
    {
        moveToForm(-1);
    };
private:
    int current;
    ArrayList formlist;

    void moveToForm(int movement)
    {
        Form^ currentForm = (Form^)formlist[current];
        currentForm->Visible = false;
        current = (formlist.Count + current + movement) % (formlist.Count);
        Form^ nextForm = (Form^)formlist[current];
        nextForm->Visible = true;
    };

};



在第一个表单的负载中,我创建了其他表单,将它们添加到ToggleForm类中,并为每个表单提供对toggleForm的引用.我只是简单地两次使用了所谓的OtherForm,但是它当然可以是任何其他形式.



In the load of the first form I create the other forms, add them to the ToggleForm class and give each a reference of toggleForm. I simply used the so called OtherForm twice but of course it can be any other form.

toggleForm = gcnew ToggleForm();
toggleForm->addForm(this);
OtherForm^ otherFormB = gcnew OtherForm;
otherFormB->Text = "B";
OtherForm^ otherFormC = gcnew OtherForm;
otherFormC->Text = "C";
toggleForm->addForm(otherFormB);
toggleForm->addForm(otherFormC);
otherFormB->toggleForm = toggleForm;
otherFormC->toggleForm = toggleForm;



表单上的按钮仅调用ToggleForm对象的上一个和下一个函数,这将处理表单的隐藏和显示.

您也可以从以下位置下载此简单的示例项目:
http://orion.woelmuis.nl/FormToggleExampleProject.zip [



The buttons on the form simply call the previous and next functions of the ToggleForm object and this handles the hiding and showing of the forms.

You can also download this simple example project at:
http://orion.woelmuis.nl/FormToggleExampleProject.zip[^]

Well, this probably will give you enough idea about how to implement such a mechanism.

Good luck!


您可以简单地创建一个新类,该类是通用类型Form的占位符.然后,您可以简单地用三个表单填充该表单,然后将其传递给所有三个表单.该新创建的类可以简单地以如下方式制作:显示中的表单仅调用某个类函数,该类函数隐藏除作为参数提供的调用表单之外的所有表单.您将获得非常小的代码和高效的代码.您还可以简单地添加下一个/上一个功能,因为您可以使用0、1、2代替数组a,b,c,它们只是要使用的数组索引.

祝你好运!
You could simply create a new class that is the placeholder for the generic type Form. You can then simply fill that with the three forms and pass it to all the three forms. That newly created class can the just simply be crafted in a way that the forms in the on show simply call some class function that hides all forms except the calling form that''s is provided as a parameter. You would get very small code and efficient. You could also simply add next/previous functionality because instead of a, b, c you can use 0, 1, 2 that are simply array indexes to use.

Good luck!


似乎你想实现与属性表非常相似的东西,为什么不看一下 CPropertySheet类 [
It seems like you want to implement something very similar to a property-sheet, why don''t you have a look to the CPropertySheet class[^]?


这篇关于在多种形式之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆