Click here to Skip to main content
12,303,190 members (80,508 online)

Windows Forms

 
QuestionEditingPanel Erasing Top Cell Border Pin
Mark Regal13-Aug-12 19:06
memberMark Regal13-Aug-12 19:06 
AnswerRe: EditingPanel Erasing Top Cell Border Pin
Mark Regal14-Aug-12 3:14
memberMark Regal14-Aug-12 3:14 
QuestionVS2010 Setup and Deployment Project - CommonAppDataFolder for XP Pin
Member 269415310-Aug-12 9:05
memberMember 269415310-Aug-12 9:05 
AnswerRe: VS2010 Setup and Deployment Project - CommonAppDataFolder for XP Pin
Dave Kreskowiak10-Aug-12 14:19
mvpDave Kreskowiak10-Aug-12 14:19 
GeneralRe: VS2010 Setup and Deployment Project - CommonAppDataFolder for XP Pin
Member 269415313-Aug-12 2:18
memberMember 269415313-Aug-12 2:18 
AnswerRe: VS2010 Setup and Deployment Project - CommonAppDataFolder for XP Pin
ictxiangxin13-Aug-12 4:03
memberictxiangxin13-Aug-12 4:03 
QuestionWrapping of Data Grid View column Pin
ukraju5-Aug-12 20:58
memberukraju5-Aug-12 20:58 
AnswerRe: Wrapping of Data Grid View column Pin
Member 908236510-Aug-12 12:59
memberMember 908236510-Aug-12 12:59 
QuestionWindows Form Pin
DSPNEOqqq3-Aug-12 9:15
memberDSPNEOqqq3-Aug-12 9:15 
RantRe: Windows Form Pin
Eddy Vluggen3-Aug-12 9:30
memberEddy Vluggen3-Aug-12 9:30 
GeneralRe: Windows Form OT Pin
Wes Aday3-Aug-12 9:41
memberWes Aday3-Aug-12 9:41 
GeneralRe: Windows Form OT Pin
Eddy Vluggen3-Aug-12 10:01
memberEddy Vluggen3-Aug-12 10:01 
AnswerRe: Windows Form Pin
Christian Amado6-Aug-12 10:47
memberChristian Amado6-Aug-12 10:47 
AnswerRe: Windows Form Pin
BillWoodruff11-Aug-12 15:27
memberBillWoodruff11-Aug-12 15:27 
Hi,

First, I believe that Child Forms should never be used, that they lead to awkward user-interfaces, and the old MDI-architecture, which supported MDIChildForms with "special features," deserves the status of a "dinosaur" skeleton: to be looked at, but not re-animated Smile | :)

I think you can get better responses to this scenario if you describe what the function of your proposed use of "Child Forms" are, in relation to their "Parent" Form.

Is it possible a Dialog can fit your needs here ?

Consider that you create a "Child Form" with code like this in response to some event:
Form form2 = new Form();
form2.TopLevel = false; // mandatory for Child Forms
form2.ShowInTaskbar = false;
form2.Parent = this;
form2.Name = "form2";
form2.Text = "form2";
form2.Size = new Size(300, 200);
form2.Show();
form2.BringToFront();
You now have a Form that is in front of your MainForm, and that, depending on FormBorderStyle, can be moved around so parts of it are invisible, as they extend beyond the DisplayRectangle of the MainForm. Depending on its z-order within the Form ... that is if some other control on the Form has been brought-to-the-front: it could appear "behind" other Controls on the Form.

Consider that you create a Form which is not a ChildForm: like this:
Form form2 = new Form();
form2.ShowInTaskbar = false;
form2.Name = "form2";
form2.Text = "form2";
form2.Size = new Size(300, 200);
form2.Show();
form2.BringToFront();
Now you have a Form you can move anywhere on the screen, depending on the setting of FormBorderStyle, and it will always be visible ... unless you activate the MainForm and bring it to the front, and the MainForm covers part of the second Form.

If you wanted this new Form to always remain on top, no matter whether the MainForm was activated, or not: just set the new Form's TopMost property to 'true, while making the sure the MainForm's TopMost property is set to 'false.

Another area to investigate, if you are concerned with your new Form always appearing on top, is the use of 'ShowModal(), in contrast to 'Show().

Keep in mind that: if your WinForms project opens in the rather standard way by creating an instance of the MainForm in the Program.cs class: that closing the MainForm will always automatically close any secondary Forms created.

In either case, if you need to exchange information between the MainForm and ChildForm, or MainForm and/or new, "independent" Form, the issues will be exactly the same: you'll need to keep a reference to the newly created Form in the MainForm ... assuming that's where you'll always create this new Form, whether Child, or "independent;" so: make sure that outside the method that creates the Form (i.e., at Form level scope) you create a reference you can access, like:
private Form form2;
 
private void SomeButton_Click(object sender, EventArgs e)
{
    form2 = new Form();
    form2.ShowInTaskbar = false;
    form2.TopMost = true;
    form2.Name = "form2";
    form2.Text = "form2 within Form class scope";
    form2.Size = new Size(300, 200);
    form2.Show();
    form2.BringToFront();
}
If you do need access to whatever in the MainForm to whatever in new Form, or vice-versa (data, contents, position, state, etc.): then there are plenty of solutions for how to do that here on CP in the QA forum (it's one of the most frequent questions asked). Hint: expose public properties.

... edit 1 ...

For example:

In the MainForm, create a Public Property that will "expose" the instance of the MainForm you create:
// in the definition of the MainForm Class
//
public static MainForm TheMainForm { get; set; }
//
// then in the MainForm Load event, or after the call to InitializeComponent: set the instance:
ThisMainForm = this;
Once you have done this, you can access anything declared Public on the MainForm, from outside the MainForm, by simply using: "MainForm.ThisMainForm."

Warning: this technique should only be used on Forms where you create one instance only ! Why: because a Form-level public static Property is always going to point to one, and only one, instance: if you had multiple instances (heaven help you) of your MainForm, changing some public variable's value there would also change it "globally:" so in all other instances: it would have the same value !

For your secondary Forms, you do not wish to use this same technique of a static Form-level Property to enable access to their "public stuff:" because, after all, each instance of a secondary Form is going to have the same controls, the same Public Form-scoped variables, etc., and, at run-time these may take on unique values.

But, your MainForm can access every instance of a secondary Form it creates (and everything scoped Public on it) by simply putting it in a unique public variable when it is created.

Finally, note there are other "models" for passing information between Forms, including using custom Events, and EventArg data structures: you'll find examples of other approaches, and lots of debate about the different ways of enabling Form to Form interaction in the QA section here on CP.

... end edit 1 ...

best, Bill
"Everything we call real is made of things that cannot be regarded as real." Niels Bohr


modified 12-Aug-12 23:35pm.

GeneralRe: Windows Form Pin
Eddy Vluggen12-Aug-12 3:43
memberEddy Vluggen12-Aug-12 3:43 
QuestionWindows Form Application Size Issue Pin
ukraju29-Jul-12 19:45
memberukraju29-Jul-12 19:45 
AnswerRe: Windows Form Application Size Issue Pin
Simon_Whale29-Jul-12 20:11
memberSimon_Whale29-Jul-12 20:11 
AnswerRe: Windows Form Application Size Issue Pin
Bernhard Hiller29-Jul-12 22:07
memberBernhard Hiller29-Jul-12 22:07 
AnswerRe: Windows Form Application Size Issue Pin
BillWoodruff11-Aug-12 15:31
memberBillWoodruff11-Aug-12 15:31 
GeneralWindows Forms Application With Collapsible Panel Pin
ukraju20-Jul-12 20:15
memberukraju20-Jul-12 20:15 
AnswerRe: Windows Forms Application With Collapsible Panel Pin
Eddy Vluggen21-Jul-12 8:16
memberEddy Vluggen21-Jul-12 8:16 
GeneralRe: Windows Forms Application With Collapsible Panel Pin
BillWoodruff29-Jul-12 17:01
memberBillWoodruff29-Jul-12 17:01 
GeneralRe: Windows Forms Application With Collapsible Panel Pin
Ger Hayden1-Aug-12 19:45
memberGer Hayden1-Aug-12 19:45 
GeneralRe: Windows Forms Application With Collapsible Panel Pin
BillWoodruff12-Aug-12 1:15
memberBillWoodruff12-Aug-12 1:15 
Questionopen web page with out address bar from win forms Pin
vikaskardode6-Jul-12 6:32
membervikaskardode6-Jul-12 6:32 
AnswerRe: open web page with out address bar from win forms Pin
Dave Kreskowiak6-Jul-12 9:46
mvpDave Kreskowiak6-Jul-12 9:46 
JokeRe: open web page with out address bar from win forms Pin
Mycroft Holmes6-Jul-12 23:15
memberMycroft Holmes6-Jul-12 23:15 
AnswerRe: open web page with out address bar from win forms Pin
Eddy Vluggen21-Jul-12 13:10
memberEddy Vluggen21-Jul-12 13:10 
Questionat this point in time would a series of tutorials on WinForms be useful ? Pin
BillWoodruff30-Jun-12 18:34
memberBillWoodruff30-Jun-12 18:34 
AnswerRe: at this point in time would a series of tutorials on WinForms be useful ? Pin
Paul Conrad30-Jun-12 19:18
memberPaul Conrad30-Jun-12 19:18 
AnswerRe: at this point in time would a series of tutorials on WinForms be useful ? Pin
Richard MacCutchan30-Jun-12 21:32
mvpRichard MacCutchan30-Jun-12 21:32 
AnswerRe: at this point in time would a series of tutorials on WinForms be useful ? Pin
Eddy Vluggen30-Jun-12 23:10
memberEddy Vluggen30-Jun-12 23:10 
QuestionDisplay large content in windows application Pin
Rajeev_8721-Jun-12 13:18
memberRajeev_8721-Jun-12 13:18 
AnswerRe: Display large content in windows application Pin
Mycroft Holmes21-Jun-12 16:36
memberMycroft Holmes21-Jun-12 16:36 
GeneralRe: Display large content in windows application Pin
Richard MacCutchan21-Jun-12 22:47
mvpRichard MacCutchan21-Jun-12 22:47 
Questionupdating, deleting adn adding rows in superlist control Pin
Kandepu Rajesh12-Jun-12 23:37
memberKandepu Rajesh12-Jun-12 23:37 
AnswerRe: updating, deleting adn adding rows in superlist control Pin
Pete O'Hanlon13-Jun-12 0:01
protectorPete O'Hanlon13-Jun-12 0:01 
QuestionError while binding the datatable to a superlist control Pin
Kandepu Rajesh8-Jun-12 0:07
memberKandepu Rajesh8-Jun-12 0:07 
AnswerRe: Error while binding the datatable to a superlist control Pin
Eddy Vluggen8-Jun-12 0:33
memberEddy Vluggen8-Jun-12 0:33 
Questionerrro while binding datatable to asuperlist control Pin
Kandepu Rajesh5-Jun-12 21:16
memberKandepu Rajesh5-Jun-12 21:16 
AnswerRe: errro while binding datatable to asuperlist control Pin
Eddy Vluggen6-Jun-12 3:28
memberEddy Vluggen6-Jun-12 3:28 
QuestionError while binding datatable to the superlist control Pin
Kandepu Rajesh5-Jun-12 21:12
memberKandepu Rajesh5-Jun-12 21:12 
AnswerRe: Error while binding datatable to the superlist control Pin
Dave Kreskowiak6-Jun-12 1:50
mvpDave Kreskowiak6-Jun-12 1:50 
GeneralRe: Error while binding datatable to the superlist control Pin
Kandepu Rajesh8-Jun-12 2:51
memberKandepu Rajesh8-Jun-12 2:51 
GeneralRe: Error while binding datatable to the superlist control Pin
Dave Kreskowiak8-Jun-12 3:21
mvpDave Kreskowiak8-Jun-12 3:21 
QuestionThe code of closing X and opening new form Pin
Iamateur27-May-12 22:11
memberIamateur27-May-12 22:11 
AnswerRe: The code of closing X and opening new form Pin
Eddy Vluggen5-Jun-12 1:08
memberEddy Vluggen5-Jun-12 1:08 
QuestionC# code problem Pin
nitish_0726-May-12 20:53
membernitish_0726-May-12 20:53 
AnswerRe: C# code problem repost Pin
Richard MacCutchan26-May-12 21:35
mvpRichard MacCutchan26-May-12 21:35 
GeneralRe: C# code problem repost Pin
nitish_0726-May-12 21:46
membernitish_0726-May-12 21:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.160530.1 | Last Updated 12 May 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid