Click here to Skip to main content
13,507,984 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a simple visual c++ windows forms application, at the moment there is only one form in this project say the form is FormA, i want to add another form FormB to the current project.

Now it is required that there is a button titled as "Show FormB" on FormA.
Upon clicking this button the FormB should be visible to the user and
FormA should be disabled,
Next when the user closes the FormB, FormA should be available to the user again,
On FormB there is also some interaction with Sql-Lite database.

Any ideas/solutions will be welcomed warmly.


[Edit] question rearranged for readability by Jibesh[/Edit]
Posted 8-Feb-13 1:28am
Updated 8-Feb-13 12:48pm
Matthew Faithfull 8-Feb-13 7:35am
You might want to clarify whether these 'forms' are .Net WinForms or MFC FormViews or completely custom Windows types you've written from scratch because the answer will depend heavily on what your 'forms' are.
partner99 8-Feb-13 7:37am
the forms are .Net WinForms
Matthew Faithfull 8-Feb-13 7:49am
Ok that's not my bag but others will now be able to help more easily. You might even want to add C# to your tag list as .Net people who monitor that list may be more likely to know even if you're implementation is in C++/CLI.
partner99 8-Feb-13 7:42am
the forms are .Net WinForms
Argonia 8-Feb-13 8:36am
Check the handler for the button click event and see if the member of the second CDialog [derived] class (assuming you mean dialog with form)calls DoModal()
Richard MacCutchan 8-Feb-13 12:15pm
You have described the sequence of events you want, so what exactly is your problem? If you turn the above steps into code then it should work as you require.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This is a really bad idea. It looks like you want to show some sequence of forms, one at a time, like with a wizard. It can be something else. In any case, use only one form, just replace its content.

It the simplest form of it, it would be having a set of instanced of Panel filling the whole form and populated with controls you initially planned to have on each form. So a panel will represent a form content. Show only one form at a time, hide all others. Moving from one form to another one (for example, "Next") will be just hiding a visible panel and showing another one. You can design any more complex scenario.

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

It's not that tough to follow the steps you explained into code.

If you are displaying your FormB as Modal dialog { Form.ShowDialog() } from FormA,

just make the FormA.Visible = false;
Display Your FormB using ShowDialog
when you are done with Form
then call FormA.Visible = true;

There are other ways you can manage this UI behaviour. Its up to you and to choose whats best for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180417.1 | Last Updated 8 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100