• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

Tool tip on custom controls

Hi people

I have created a custom control and I'd like the tooltip attached to the control to propagate to the other parts of the control. Eg it seems the the tooltip is attaching it's self the the background. But it doesn't attach itself to the text box and the picture box that make up the custom control.

Thanks in advance. If you don't understand what I want just ask questions

Regards

Simion Tishler
0
simion_tishler
Asked:
simion_tishler
  • 11
  • 9
  • 4
2 Solutions
 
cyberdevil67Commented:
Hi simion_tishler,

 you can try this http://www.codeproject.com/cs/combobox/nishtooltiplistbox.asp

Cheers!
0
 
simion_tishlerAuthor Commented:
Thanks dude but not what I was thinking of. I'II show you the code I want that I use and then you might understand what I'm asking for.

PostPref1Tip.ShowAlways = true;
PostPref1Tip.InitialDelay = 0;
PostPref1Tip.Active = true;
PostPref1Tip.AutoPopDelay = 32000;
PostPref1Tip.SetToolTip(PostPref1Cbo,PGRow["course_name"].ToString().Trim());

The combobox PostPref1Cbo is my own creation. It's a self made combo box with extras. It's made with a textbox and a listview. When the combo box is passed to a tooltip I want all the items within the combo to be included in the tooltip. It's hard to explain but unless you have done a custom control it's hard to understand.

Thanks anyway I appreciate the effort but I had already looked at that code.

Regards

Simion
0
 
Fahad MukhtarDistinguished EngineerCommented:
as the PostPref1Cbo is the container control that may contain other controls. You have to set the same tooltip for the child controls as well:

PostPref1Tip.ShowAlways = true;
PostPref1Tip.InitialDelay = 0;
PostPref1Tip.Active = true;
PostPref1Tip.AutoPopDelay = 32000;
PostPref1Tip.SetToolTip(PostPref1Cbo,PGRow["course_name"].ToString().Trim());

foreach (Control c in PostPref1Cbo.Controls)
      {                        
      PostPref1Tip.SetToolTip(c,PGRow["course_name"].ToString().Trim());
      }
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
simion_tishlerAuthor Commented:
Well done dude, yeah it works but it wasn't exactly what I was looking for. I want something that I can put into the code of the custom control so I don't have to do stuff like that. It's not very nice code and defeats the purpose of having a custom control in the first place.

That reminds me of another problem I was having with the same custom control and it was a similar problem and some guy told me to do the same thing.

Anyway I'd like to leave this open for at least another couple of days to see if I can get the answer I really want. After that time I'II award the points to you because I'm going to use the code if I get no better answer.

Thanks and bare with me.

Simion
0
 
cyberdevil67Commented:
Hang ten here I pointed you in the right direction first.

And in answer to you last question you can do what you want, but you will need to create the code in the custom control and create a propery for it. This way you can change the tip at any time down the track.

So in the custom control you can move that code and when setting the property write code to populate everything else in the controls. So instead of referencing it on the outside like

foreach (Control c in PostPref1Cbo.Controls)
     {                    
     PostPref1Tip.SetToolTip(c,PGRow["course_name"].ToString().Trim());
     }

reference it in the control like

foreach (Control c in this.Controls)
     {                    
     this.SetToolTip(c,PGRow["course_name"].ToString().Trim());
     }
0
 
simion_tishlerAuthor Commented:
Hey dude

Okay I have to point out a few things you don't understand. The code you point out to me didn't help one bit because it only concerns putting a tooltip inside a control. The whole problem is that when you call the settooltip method you pass the custom control into the tooltip.

Therefore the custom control doesn't have a tooltip to set. When I pass in the reference of the custom control I also want to pass a refence to the textbox and picture control inside the custom control. Or something along those lines.

What I'm really looking for is some kind of event or something along those lines. It's a complicated bit of code which id why I gave it 500 points.

what I'm looking for is somelike what desp gave me but alot more advanced.

So if you can give me that I'II give you the points

Regards

Simion

0
 
Fahad MukhtarDistinguished EngineerCommented:
>> Hang ten here I pointed you in the right direction first.

RIGHT DIRECTION:
>>Hi simion_tishler,

>> you can try this http://www.codeproject.com/cs/combobox/nishtooltiplistbox.asp

>>Cheers!

cyberdevil67,
a URL is not always the solution of a 500 pts question..
0
 
cyberdevil67Commented:
No in your eyes it's not.

0
 
cyberdevil67Commented:
Like I said...

You can create your custom control with the code that you had on the outside, place it on the inside of the custom control. This way your not duplicating this code every time you want a custom control.

So then you can setup a property get/set to say this is the tooltip I would like to have displayed. The in you custom control, you can the populate the other controls in the custom control.

Something like this

public byte[] ToolTip
{
  get{ return m_ToolTip; }
  set
 {
   m_ToolTip= value;
   foreach (Control c in this.Controls)
   {                    
     this.SetToolTip(c,PGRow[value].ToString().Trim());
   }
  }
}

Now if you were to drag this custom control onto your form, you would notice in your properties the word Tooltip, so when you set this to something, the code above will make sure that all your controls are set to this tooltip.

Thats what I wrote, does the code help you more.

0
 
Fahad MukhtarDistinguished EngineerCommented:
you were referring to your first post... so was i... which includes nothing but a URL
0
 
simion_tishlerAuthor Commented:
okay cyberdevil I know what your saying here and it would work but it's not the best code I've ever seen. For 500 point you have to give me cream of the crop code. Your code would go something like this if we insserted the code you are proposing to use above into my custom control.

MethodA1Tip.SetToolTip(Pref1Cbo,PGRow["coursecode"].ToString();

Pref1Cbo.ToolTip(MethodA1Tip);

Now that is how it would work? If I understand your code. But what I really want is to only have to use the first line. Not the second.

And another thing is that the code you pointed out in the URL is nothing like what your proposing. The URL is proposing to creating a tooltip within the custom control which is all internal and has no connection with tooltips outside the control.

Anyway I think you guys know what I want. Can anyone help me. There must be someone who understands the solution.

Regards

Simion
0
 
cyberdevil67Commented:
I am not sure what your talking about..

my code does not have MethodA1Tip.SetToolTip

public string ToolTip
{
  get{ return m_ToolTip; }
  set
 {
   m_ToolTip= value;
   foreach (Control c in this.Controls)
   {                    
     this.SetToolTip(c,PGRow[value].ToString().Trim());
   }
  }
}

0
 
simion_tishlerAuthor Commented:
hmm well okay I'II look into it and see what I can do. I need to test to see if it works the way your suggesting.
0
 
cyberdevil67Commented:
Well the thing is if it works outside the Custom Control, then all you need to do is move it into the custom control and replace the namespace of the control with this, and it should go to populating the other controls.

See this is the same as PostPref1Tip, except that we are now inside the control.
0
 
cyberdevil67Commented:
If you would like to post you custom control with only the basics no other methods and just the controls I'll modify the code for you, to make it work.
0
 
simion_tishlerAuthor Commented:
umm it's okay I'II do it no problem but I'm concerned that you have taken desp's idea and used it to make a new solution. So not sure who to award the points to.  Also it still isn't what I wanted. It still just a workaround. So if I use you code then I might split the points evenly if no else comes up with anything better.
0
 
cyberdevil67Commented:
Well no because I did post a link to you that would show you how to apply the tips, it wasn't what you exactly wanted and desp got you going in that area, now I am helping you were I began.

So in this case why not just award us both, one accepted and one assisted. The idea is that we work together to help you with your problem.
0
 
Fahad MukhtarDistinguished EngineerCommented:
give them to cyberdevil, im not greedy for points... just here to help and im glad i could help
0
 
cyberdevil67Commented:
neither am I but we are both helping here desp, thats the main thing.
0
 
simion_tishlerAuthor Commented:
yeah I will split it but you know this is the second time I have posted this question and I never get the answer I'm looking for. Oh well. Obviously it's too advanced for this place.
0
 
cyberdevil67Commented:
Hang ten here a minute.

What question, how do you place code into a custom control/ user control to populate the tooltips to all controls. Desp answered that, although it was on the outside of the control, I have shown you how to do it on the inside of the control.

Maybe I should do this code instead.

            public string ToolTip
            {
                  get{ return m_ToolTip; }
                  set
                  {
                        m_ToolTip= value;
                        foreach (Control c in this.Controls)
                        {
                              toolTip1.SetToolTip(c,value);
                        }
                  }
            }

Now what this does is allows for you to have a property for your custome control, it then populates the string passed to the Custom Control and sets all the Controls that are attached to this User Control, which is what you wanted or have asked for.

0
 
simion_tishlerAuthor Commented:
Not quite dude. The controls that are at be attached to a tooltip are usually passed to the tooltip as a reference.

MethodA1Tip.SetToolTip(Pref1Cbo,PGRow["coursecode"].ToString());

Like the above.

Not the other way around which you are suggesting were you have a tooltip inside and pass in the string. So it not really the same.

Do you understand what I want now. I don't want some hack around. I want to be able to create a control that acts like any other windows control.

Regards

Simion
0
 
cyberdevil67Commented:
Yes I do understand....

Here is the code for the custom control that I wrote to test it for you.

Notice that when you drop this custom control on a form it now has the property ToolTip, you assign the tooltip and it populates all the controls in this custom control.

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace AccessDatabase
{
      /// <summary>
      /// Summary description for UserControl1.
      /// </summary>
      public class UserControl1 : System.Windows.Forms.UserControl
      {
            private System.Windows.Forms.TextBox textBox1;
            private System.Windows.Forms.ComboBox comboBox1;
            private System.Windows.Forms.ToolTip toolTip1;
            private System.ComponentModel.IContainer components;

            private string m_ToolTip = "";

            public UserControl1()
            {
                  // This call is required by the Windows.Forms Form Designer.
                  InitializeComponent();

                  // TODO: Add any initialization after the InitializeComponent call

                  toolTip1.ShowAlways = true;
                  toolTip1.InitialDelay = 0;
                  toolTip1.Active = true;
                  toolTip1.AutoPopDelay = 32000;
            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if(components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #region Component Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  this.components = new System.ComponentModel.Container();
                  this.textBox1 = new System.Windows.Forms.TextBox();
                  this.comboBox1 = new System.Windows.Forms.ComboBox();
                  this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
                  this.SuspendLayout();
                  //
                  // textBox1
                  //
                  this.textBox1.Location = new System.Drawing.Point(24, 120);
                  this.textBox1.Name = "textBox1";
                  this.textBox1.TabIndex = 0;
                  this.textBox1.Text = "textBox1";
                  //
                  // comboBox1
                  //
                  this.comboBox1.Location = new System.Drawing.Point(16, 24);
                  this.comboBox1.Name = "comboBox1";
                  this.comboBox1.Size = new System.Drawing.Size(121, 21);
                  this.comboBox1.TabIndex = 1;
                  this.comboBox1.Text = "comboBox1";
                  //
                  // UserControl1
                  //
                  this.Controls.Add(this.comboBox1);
                  this.Controls.Add(this.textBox1);
                  this.Name = "UserControl1";
                  this.Size = new System.Drawing.Size(304, 240);
                  this.ResumeLayout(false);

            }
            #endregion

            public string ToolTip
            {
                  get{ return m_ToolTip; }
                  set
                  {
                        m_ToolTip= value;
                        foreach (Control c in this.Controls)
                        {
                              toolTip1.SetToolTip(c,value);
                        }
                  }
            }
      }

}
0
 
simion_tishlerAuthor Commented:
cool dude. well I don't think anyone else is coming along to help me so I'II split the points down the middle.

Thanks for all your help guys.

Regards

Simion
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 11
  • 9
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now