Click here to Skip to main content
16,021,417 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a Main form(form1) that has a panel(panel1) that show other smaller form (form2); when I define a tooltip for any control in the form2 and then want show Form1 that has subform2; the tooltip don't show;

describe it shortly as below:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace TansaBanoo
{
    public partial class Nutrition : Form
    {
public Form2 form2;
        [DllImport("user32.dll")]
        static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
        [DllImport("user32.dll")]
        static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
        public Nutrition()
        {
            InitializeComponent();
            marqueeProgressBarControl1.Hide();
        }


        private void button1_Click(object sender, EventArgs e)
        {
                form2 = new Formf();
                form2.Show();
                SetParent(form2.Handle, panel1.Handle);
                MoveWindow(form2.Handle, 0, 0, panel1.Width, panel1.Height, false);


        }
    }
}


the control'stooltip of form2 not show in form1(main form)

please help me and suggest the best way to show a form into another that tooltips work
Posted

... begin content added January 10 #1

First, I am unable to replicate the problem you describe in VS 2013, compiling against FrameWork .NET 4.5, and 3.0. Here's what I did to re-create (what I imagine is) your current UI:

0. on the main form:

a. put a TableLayoutPanel with 4 rows, and five columns, docked Left. Set its 'AutoSize property to 'true, and its 'AutoSizeMode to 'GrowAndShrink

a.1. put a Button in each cell of the TableLayoutPanel

b. added a Panel to the main form, docked Right. AutoSize = 'false. Send it to the back in the z-order.

1. added a second form, 'Form2 to the Project

a. added some standard Controls to Form2, added a ToolTip to Form2

b. set some of the Controls on Form2's ToolTip Text

2. in the main Form, declared an instance of Form2, and created it in the Form Load Event:
C#
private Form2 f2;

private void Form1_Load(object sender, EventArgs e)
{
    f2 = new Form2();
    f2.TopLevel = false;
     
    // for testing
    panel1.Controls.Add(f2);
    
    // this will hide the Panel
    tableLayoutPanel1.Dock = DockStyle.Fill;
}


3. The important part is, of course, how you show the secondary Form inside the Panel: for testing purposes I assigned the same Click EventHandler to all the Buttons inside the TableLayoutPanel:
C#
private void button1_Click(object sender, EventArgs e)
{
    this.SuspendLayout();

        tableLayoutPanel1.Dock = DockStyle.Left;

        // in your code that selects from multiple possible
        // Forms or whatever to be shown in the Panel, this
        // is where you'd have the code to select your choice
        // panel1.Controls.Add(????);
        
        panel1.Visible = true;

        f2.Visible = true;

    this.ResumeLayout();
}
Discussion:

1. running the test, I found that the ToolTip comments assigned to the Controls on Form2 did appear at run-time when the Form was viewed inside the Panel.

2. if you wanted to switch the interface back to show the TableLayoutPanel occuping the full screen real-estate, with the Panel hidden:

C#
this.SuspendLayout();

    // possibly remove the current whatever shown in the Panel here
    // panel1.Controls.Remove(????);

    tableLayoutPanel1.Dock = DockStyle.Fill;

this.ResumeLayout();
I would encourage you, if at all possible, to re-create what are now your separate Forms as UserControls, and display those inside the Panel.

But, I'm not clear if, in your design, the selector Buttons are always visible or not.

... end content added January 10 edit #1

It is a very bad idea to put a Form inside another Form in programming in Windows Forms, or put a Form inside any other Container Control, like a Panel, in a Form.

It doesn't surprise me that Form2's ToolTip disappears ... you are doing some strange stuff with the API calls.

There are many alternatives to your current design choice; alternatives like: using a UserControl instead of a Form ... possibly using a TabControl to create a tabbed-ui.

If you care to describe what the goal of your application and its user interface is, I, and I am sure other people here, will be glad to make suggestions based on years of experience.

I am curious to know why you think you need to use another Form inside (what I assume is) your Main Form.

If you think this feedback/advice is not helpful, let me know, and I'll remove this post.
 
Share this answer
 
v2
Comments
Hadi IR 9-Jan-14 17:52pm    
thank you very much for reply; I have a main form that has about 20 button (use tile button) and each button fire show different form; and I want show in the main form; what's your suggestion?
BillWoodruff 9-Jan-14 23:52pm    
I will reply in detail later today (GMT +0700)
Hadi IR 10-Jan-14 6:16am    
thank you very much for your time and your help; I am so happy to contact with you;
Please take me some time to check your suggestion; I think it is possible to take a lot of memory by visible and invisible the forms; what's your idea about it; because in the past state; I close the opened form and open the new form when click an other button because of EVERY form has about memory consumer
Hadi IR 10-Jan-14 7:03am    
thank you my friend; tooltip works well; I have an other question; you think if on load event add create instance from every of forms related to buttons; will not be there problem about memory;
if not, add a form and remove last opened form from controls of panel; what is your idea?
BillWoodruff 10-Jan-14 10:57am    
I'd suggest you try creating an instance of every Form you will use, hide the ones you want hidden, show the one you want visible, and see how your application responds on the type of computers (cpu, memory, OS) you anticipate using the application on.

Remember that when you close, and then re-open a Form, all the settings of the current Controls on the Form are reset to their default values (or, values you have set at design-time, or in Events like the Form Load Event). If maintaining the current state of each Form is important to you, then just hiding and showing them should be a win.

Again, I'd recommend you use UserControls, rather Forms. Using a Form does "cost" more.

Another interface you might consider is to have a menu on the main Form where one Menu Item contains a list of all the available Forms ... but, if Buttons do it for you ... that's fine.
I want have a main form that has tile button group like windows 8; and click event of every button; show related form in the side of main form;
I like avoid open and close form and in this way by hiding form border; just the contents of main form will change after that button cliked
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900