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
629 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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

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!

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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