?
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
Medium Priority
?
631 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

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