WinForm ToolTip.SetToolTip is my application hang :(

I am trying to install ToolTip

on a control and my application is hanging.

I am programmatically adding a PictureBox to a FlowLayoutPanel. Works great. Then I choose one of the PictureBoxes to set the hint and .. the arrow! app hung: (

If I set the ToolTip the moment I first create each frame and add it to the flowlayout panel, it does not hang and is displayed / displayed correctly.

here's the code: -

// Toggle the button to green.
var pictureBoxs = flowLayoutPanel1.Controls.Find("Image_" + FileId, true);
if (pictureBoxs.Length > 0 &&
    pictureBoxs[0] is PictureBox)
{
    var pictureBox = pictureBoxs[0] as PictureBox;
    if (pictureBox != null)
    {
        pictureBox.Image = Resources.GreenButton;

        ToolTip toolTip = new ToolTip();

        // Hangs after this line
        toolTip.SetToolTip(pictureBox, "Started Parsing On: " + 
            DateTimeOffset.Now);

        int i=0; i++; // NEVER GETS CALLED.
    }
}

      

Any ideas? is this how I get a link to an existing PictureBox instance?

UPDATE:

This code has changed as requested.

public partial class Form1 : Form
{
    ... <snip>various private fields</snip>
    private ToolTip _toolTip; // Added this.

    ... 

    private void InitialiseStuff()
    {
         PictureBox pictureBox = new PictureBox
                                     {
                                         Image = Resources.RedButton,
                                         Name = "Image_" + someId,
                                         Width = 35
                                     };

         _toolTip = new ToolTip();
         _toolTip.SetToolTip(pictureBox, "Haven't yet parsed this file...");

         flowLayoutPanel1.Controls.Add(pictureBox);
    }


    private void foo_OnStartParsingData(object sender, DateTimeEventArgs e)
    {
       ... <snip>some boring code</snip>

       // Toggle the button to green.
        var pictureBoxes = flowLayoutPanel1.Controls.Find("Image_" + 
            someId, true);
        if (pictureBoxes.Length > 0)
        {
            var pictureBox = pictureBoxes[0] as PictureBox;
            if (pictureBox != null)
            {
                pictureBox.Image = Resources.GreenButton;

                // Hangs after it runs the line below.
                _toolTip.SetToolTip(pictureBox, 
                    "Started Parsing On: " + e.DateTimeOffset);
            }
         }
    }
}

      

+1


source to share


1 answer


You just need one Tooltip

as a class variable and your call:

toolTip.SetToolTip(pictureBox, 
    string.Format("Started Parsing On: {0}", e.DateTimeOffset));

      

must work. I have used this successfully so

So remove the line:

ToolTip toolTip = new ToolTip();

      



from your loop and place it in a constructor or other initialization code.

UPDATE

Looking at the new code, I don't see anything clearly wrong.

I can only assume that you have split the line structure for the tooltip customization. Possibly what e.DateTimeOffset

is causing the hang and this will confirm it.

0


source







All Articles