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
621 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 30

Expert Comment

by:Alexandre Simões
Comment Utility
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
Comment Utility
Just to add... call that method after the fPOSNumberPad.Show();
0
 

Author Comment

by:wenyonk
Comment Utility
Please see my new question if you are interested?

C#, Key Preview, KeyDown, KeyPress
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now