Forms in a panel control?
-
I have a main form that has a panel control and the user can select which of the two "child" forms to display in that panel control from a menu selection. Depending on which form is displayed in the panel, the app will display data from a Tektronix TDS-2024B scope or other data from an external DAQ (Data Acquisition module). The current code shows the forms without a problem. But if I switch between the two forms; data is no longer updated in the textboxes when I run a data capture routine for one form or the other. However, if I do not switch from one form display to the other after firing up the app, data is updated correctly. Example code for one of the form displays in the panel is: private void ScopeCapture_Click(object sender, EventArgs e) { frmTDS2024BScopeCapture TDS = new frmTDS2024BScopeCapture(); TDS.MdiParent = this; TDS.TopLevel = false; TDS.Dock = DockStyle.Fill; //Container this.panel1.Controls.Clear(); this.panel1.Controls.Add(TDS); TDS.Show(); currentTest = "TDS"; ////TDS.tbFreq.Text = "4578223"; //test only } The code for the second form is identical, except for the form reference. Could I be having a problem with the Z-order of the panel when switching from one form to the other? Hope someone has run into this before and can shed some light on the issue. I tried not to clutter this post with too many details. If further code is required, please advise. Thanks in advance, Steve. P.S. I have Googled, searched forums, etc till I'm blue in this face with this one.
-
I have a main form that has a panel control and the user can select which of the two "child" forms to display in that panel control from a menu selection. Depending on which form is displayed in the panel, the app will display data from a Tektronix TDS-2024B scope or other data from an external DAQ (Data Acquisition module). The current code shows the forms without a problem. But if I switch between the two forms; data is no longer updated in the textboxes when I run a data capture routine for one form or the other. However, if I do not switch from one form display to the other after firing up the app, data is updated correctly. Example code for one of the form displays in the panel is: private void ScopeCapture_Click(object sender, EventArgs e) { frmTDS2024BScopeCapture TDS = new frmTDS2024BScopeCapture(); TDS.MdiParent = this; TDS.TopLevel = false; TDS.Dock = DockStyle.Fill; //Container this.panel1.Controls.Clear(); this.panel1.Controls.Add(TDS); TDS.Show(); currentTest = "TDS"; ////TDS.tbFreq.Text = "4578223"; //test only } The code for the second form is identical, except for the form reference. Could I be having a problem with the Z-order of the panel when switching from one form to the other? Hope someone has run into this before and can shed some light on the issue. I tried not to clutter this post with too many details. If further code is required, please advise. Thanks in advance, Steve. P.S. I have Googled, searched forums, etc till I'm blue in this face with this one.
The only thing that seems 'odd' to me at first glance is the line
TDS.MdiParent = this;
. From the code you have posted I can see no need for this. By adding TDS to the panel, you are not allowing the Main Form to operate properly as an MDI Parent, and I would suggest that you at least try running your Application with the line commented out and see if it runs OK. I do not know if this will solve the problem entirely, but that line is certainly not helping.Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
The only thing that seems 'odd' to me at first glance is the line
TDS.MdiParent = this;
. From the code you have posted I can see no need for this. By adding TDS to the panel, you are not allowing the Main Form to operate properly as an MDI Parent, and I would suggest that you at least try running your Application with the line commented out and see if it runs OK. I do not know if this will solve the problem entirely, but that line is certainly not helping.Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
Thank you Henry for the reply. I will try what you recommend. I don't see many comments on the Web or MicroSoft on how to show forms in a panel control. Could be, I'm trying something that has potential problems that are not documented anywhere. As I mentioned, the forms show up in the panel control just fine. After switching between one and the other, the textboxes in those forms are no longer updated when expected. I'm using a PXI chassis from National Instruments to capture data from several voltage/current sources and as well as getting scope captures via a USB port from a Tektronix scope. Best Regards, Steve. BTW, I don't read medical books. Former medical student here... Then I got hooked on Math and programming and now this problem!
-
Thank you Henry for the reply. I will try what you recommend. I don't see many comments on the Web or MicroSoft on how to show forms in a panel control. Could be, I'm trying something that has potential problems that are not documented anywhere. As I mentioned, the forms show up in the panel control just fine. After switching between one and the other, the textboxes in those forms are no longer updated when expected. I'm using a PXI chassis from National Instruments to capture data from several voltage/current sources and as well as getting scope captures via a USB port from a Tektronix scope. Best Regards, Steve. BTW, I don't read medical books. Former medical student here... Then I got hooked on Math and programming and now this problem!
Good luck!
thompsons wrote:
I'm using a PXI chassis from National Instruments to capture data from several voltage/current sources and as well as getting scope captures via a USB port from a Tektronix scope.
Please don't ask me anything about that part, way out of my depth!
thompsons wrote:
I don't see many comments on the Web or MicroSoft on how to show forms in a panel control. Could be, I'm trying something that has potential problems that are not documented anywhere
There are several examples of this here on CP, if you search the articles/messages. The only thing that strikes me about it is a matter of personal preference. I would set the
FormBorderStyle
property toNone
, but that's just my preference and has nothing to do with your problem. At the end of the dayForm
is a descendant ofControl
and therefore should act like any other control. Here is a snippet from one of my apps:private void btnForm\_Click(object sender, EventArgs e) { Form newForm = new Form(); newForm.TopLevel = false; newForm.Parent = this; newForm.Visible = true; newForm.Location = new Point(10, 10); newForm.Size = new Size(this.ClientSize.Width - 20, this.ClientSize.Height - this.panel1.Height - 20); newForm.BackColor = Color.Bisque; newForm.FormBorderStyle = FormBorderStyle.None; newForm.Dock = DockStyle.Left; this.Controls.Add(newForm); }
The only difference between yours and mine is that I add it directly to the parent form, you add it to a panel.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”