Я пытаюсь установить ToolTip
на элемент управления, и оно вешает мое приложение.
Я программно добавляю PictureBox в FlowLayoutPanel. Работает отлично. Затем я выбираю один из PictureBox, чтобы установить всплывающую подсказку и .. бум! Приложение зависло: (
Если я установлю всплывающую подсказку в том месте, где я сначала создаю каждый графический блок, и добавляю его в панель потока, она не зависает и отображается / отображается правильно.
вот код: -
// 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.
}
}
Есть идеи? это как получить ссылку на существующий экземпляр PictureBox?
UPDATE:
В соответствии с просьбой, это следующий код, который я изменил ..
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);
}
}
}
}