1

コントロールに を設定しようとしToolTipていますが、アプリケーションがハングしています。

プログラムで PictureBox を FlowLayoutPanel に追加します。よく働く。次に、PictureBox の 1 つを選択してツールヒントを設定すると、.. ブーム! アプリがハングしました:(

各ピクチャボックスを最初に作成してフローレイアウトパネルに追加する時点でツールチップを設定すると、ハングせず、正しく表示/レンダリングされます。

ここにコードがあります:-

// 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 インスタンスへの参照を取得する方法はありますか?

アップデート:

要求に応じて、これは次のコードを変更しました..

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);
            }
         }
    }
}
4

1 に答える 1

0

Tooltipクラス変数とあなたの呼び出しとして1つだけ必要です:

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

動作するはずです。私はこれをうまく使ったので

したがって、次の行を削除します。

ToolTip toolTip = new ToolTip();

ループから、コンストラクターまたはその他の初期化コードに入れます。

アップデート

新しいコードを見ると、明らかに間違っていることはわかりません。

ツールチップの設定から文字列の構築を分割することをお勧めします。e.DateTimeOffsetそれがハングの原因である可能性があり、これによりそれが確認されます。

于 2009-07-14T09:13:56.400 に答える