Solved

Open new form in a child of an MDI form or MDI control in an MDI child form

Posted on 2007-04-11
6
625 Views
Last Modified: 2013-12-17
In my C# Winforms app I have a main form that is a mdi form.  in that form I open other forms as children to the main from.  Within one of the child forms open I need to show a numneric keypad control at a specific location (217, 0 which is relative to the inside of the child form)  .  I also need this numeric keypad control to be modal.  Currently, I have placed this control on the child form at an off screen location (900, 0).  When I click a button I would like to the numeric keypad control to moved from 900,0 to 217,0 and be modal in the sence that only the numeric keypad is the only control that can accept user input.  I would also like to be able to catch keystrokes 0-9 to simulate the user clicking on the numeric keypad buttons.  I have the MDI mainform keypreview property set to true and the same for the child form.
0
Comment
Question by:wenyonk
  • 3
  • 3
6 Comments
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 18891311
Hi...

There are some parts of your description that I sisn't understood right but I think I can help you.

First of all, the MDI logic doesn't allow MDIParents to be inside MDIChilds or even MDIParents inside each other.

What you can do id to make a form appear inside a form like it was any other control.
For this you must use a Form hidden property called TopLevel.
Setting this property to false (the default is true) you can do something like:

this.Form1.Controls.Add(this.Form2);

Where Form2 is the Form you've previously set the TopLevel Property to false.
You must still set it's location, size and call the Show() method.

As you can test, the result is a form inside another and you can move it around, maximizse it, minimize it, resize... whatever...
You can still set the borderstyle to none to make it look like a control... there are infinite possibilities here.


To simulate the keystrokes, enable the KeyPreview property of the form and handle the keydown event. Use the event to run your code to simulate the pressed key.


I think this is your best option... if not your only option...

Alex
0
 

Author Comment

by:wenyonk
ID: 18894704
AlexCode:

Thank you for your response.  I have added the following lines of code inside a button_click event
frmPOSNumberPad fPOSNumberPad = new frmPOSNumberPad();
                    //uccPOSNumberPad uccPOSNumberPad1 = new uccPOSNumberPad();
                    if (tstbse.TouchScreenToggleButton.Checked)
                    {
                        // Add Code Here.
                        fPOSNumberPad.uccPOSNumberPad1.POSNumberPadType = CA.RetailBeerSystems.Info.CommonEnumerations.POSNumberPadTypeEnum.Quantity;
                        fPOSNumberPad.StartPosition = FormStartPosition.Manual;
                        fPOSNumberPad.Height = this.Height;
                        fPOSNumberPad.Width = 290;
                        System.Drawing.Point placeAtLocation = this.Location;
                        placeAtLocation.X += 217;
                        //fPOSNumberPad.Location = new System.Drawing.Point(placeAtLocation.X, placeAtLocation.Y);
                        fPOSNumberPad.Location = new System.Drawing.Point(217,0);
                        //fPOSNumberPad.MdiParent = this;
                        fPOSNumberPad.TopLevel = false;
                        if (!this.Controls.Contains(fPOSNumberPad))
                        {
                            this.Controls.Add(fPOSNumberPad);
                        }
                        fPOSNumberPad.Show();
0
 

Author Comment

by:wenyonk
ID: 18894738
AlexCode:

Thank you for your response.  I have added the following lines of code inside a button_click event

    frmPOSNumberPad fPOSNumberPad = new frmPOSNumberPad();
    fPOSNumberPad.StartPosition = FormStartPosition.Manual;
    fPOSNumberPad.Height = this.Height;
    fPOSNumberPad.Width = 290;
    fPOSNumberPad.Location = new System.Drawing.Point(217,0);
    fPOSNumberPad.TopLevel = false;
    if (!this.Controls.Contains(fPOSNumberPad))
    {
        this.Controls.Add(fPOSNumberPad);
    }
    fPOSNumberPad.Show();

the result is that the fPOSNumberPad form is not visible on the form.  At the above location is an array
of button controls.  The fPOSNumberPad maybe behind the buttons?  Any suggestions on how I can bring it to the foreground?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 18896347
If that's the problem, you can simply call the fPOSNumberPad.BringToFront() method.
0
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 500 total points
ID: 18896351
Just to add... call that method after the fPOSNumberPad.Show();
0
 

Author Comment

by:wenyonk
ID: 18898039
Please see my new question if you are interested?

C#, Key Preview, KeyDown, KeyPress
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question