question

heyangben-3420 avatar image
0 Votes"
heyangben-3420 asked heyangben-3420 commented

How do I get the ToolTip control and Call it RemoveAll

In WinForm, the ToolTip control in the control. Without knowing what type of control it is How do I get the ToolTip control from in the control and call its RemoveAll function.
I want to call "ToolTip.RemoveAll()" in every control,but without changing every control
I had thought of using the FieldInfo retrieved by reflection to get tootip, but FieldInfo couldn't call RemoveAll

windows-forms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JackJJun-MSFT avatar image
0 Votes"
JackJJun-MSFT answered heyangben-3420 commented

@heyangben-3420 , Welcome to Microsoft Q&A, we could get component list of the form, then we could convert the component to the Tooltip type to call the RemoveAll method.

Here is a code example you could refer to.

   private void button1_Click(object sender, EventArgs e)
         {
             var result = EnumerateComponents();
             foreach (var item in result)
             {
                 if(item is ToolTip)
                 {
                     ToolTip tip = (ToolTip)item;
                     tip.RemoveAll();
                 }
             }
    
         }
    
         private void Form1_Load(object sender, EventArgs e)
         {
             toolTip1.SetToolTip(button1, "Save changes");
             toolTip1.SetToolTip(checkBox1, "Please choose");
    
         }
    
         private IEnumerable<Component> EnumerateComponents()
         {
             return from field in GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                    where typeof(Component).IsAssignableFrom(field.FieldType)
                    let component = (Component)field.GetValue(this)
                    where component != null
                    select component;
         }


Result:

199110-3.gif


Best Regards,
Jack



If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



3.gif (49.5 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

thank you very much,You've been very helpful

0 Votes 0 ·