[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 634
  • Last Modified:

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

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
wenyonk
Asked:
wenyonk
  • 3
  • 3
1 Solution
 
Alexandre SimõesManager / Technology SpecialistCommented:
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
 
wenyonkAuthor Commented:
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
 
wenyonkAuthor Commented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Alexandre SimõesManager / Technology SpecialistCommented:
If that's the problem, you can simply call the fPOSNumberPad.BringToFront() method.
0
 
Alexandre SimõesManager / Technology SpecialistCommented:
Just to add... call that method after the fPOSNumberPad.Show();
0
 
wenyonkAuthor Commented:
Please see my new question if you are interested?

C#, Key Preview, KeyDown, KeyPress
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now