6

マーキーとしてSystem.Windows.Forms.Label内部を使用するかなり大きな(幅に関して)C#WinFormsアプリケーションがあります。System.Windows.Forms.Panel

Aは、ティックイベントの後に位置をSystem.Timers.Timer更新します。Label

int new_X_location = (label.Location.X + distance_invariant) % modulo;
label.Location = new Point(new_X_location, label.Location.Y);

マーキーの機能は問題ではありません。Label.Textフィールドを変更すると、ラベルが消えます。

string some_string = working_function_that_returns_string();
label.Text = some_string; //disappears!

ここに画像の説明を入力してください

フォントサイズが大きい場合は、2100文字程度の長さに制限されるようです(24pt)。小さい場合(10pt)、文字列ははるかに長くなる可能性があります(label.Text.Length >= 4200)。

string some_string = working_function_that_returns_string();
label.Text = some_string.SubString(0,2000); //it's still visibile here.
...
label.Text = some_string.SubString(0,2200) //it's not visible!

幅の制限、フォントサイズの制限、またはフォームの幅の配置に関係があるかどうかはわかりません。。フォントサイズが小さく、文字列が短い場合、位置は正しくなります。したがって、ポジショニングエラーではありません。

4

5 に答える 5

0

AutoEllipsisプロパティが trueの固定サイズのラベル ( AutoSizefalse) を試しましたか? 幅の制限や折り返しの問題が原因である場合は、なくなるはずです。

それでも問題が解決しない場合は、ポジショニング コードを確認してください。位置計算でラベル幅を使用している場合、テキストの変更による幅の変更は、いくつかのまれなケースで驚きをもたらす可能性があります。繰り返しますが、固定サイズのラベル (または最大サイズ) を使用すると役立つ場合があります。

于 2013-01-03T11:32:31.603 に答える
0

エラーを解決するための私の試み:

// Try disabling the "AutoSize"-property, and use the panels' sizes
label.AutoSize = false;
label.Width = yourRedPanel.Width;
label.Height = yourRedPanel.Height;
label.TextAlign = ContentAlignment.MiddleLeft;
label.AutoEllipsis = true;

// Check that "new_X_location"-variable is not negative or 
// too big to move the label out of the viewable area
label.Location = new System.Drawing.Point(new_X_location, label.Location.Y);

// Check that some_string.Length is as great or greater than given Substring length argument
label.Text = some_string.Substring(0, 2200);

// The max font size is the biggest possible value of float
Font testFont = new Font("Arial", float.MaxValue);

// If this doesn't help, wrap your code to try-catch block
// Run the code line by line (F10), and see where it jumps to "catch",
// if there occurs errors
try
{
   // Code here
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
于 2014-05-28T11:38:46.257 に答える
0

その関数にブレークポイントを使用できます。

(brkpnt)|    string some_string = working_function_that_returns_string();  

次に、その関数の「ステップイン」をデバッグします。段階的にデバッグします。autos ウィンドウから変数を確認します。"" 空の文字列を返す LOGICAL MISTAKE がある可能性があります。

その working_function_that_returns_string(); を投稿する必要があります。

その他のアイデア。textbox.bacgorundcolor を none に変更して、ラベルのように見せることができます

于 2014-05-26T21:16:33.563 に答える
0

こんなものも使っています!これを試して:

label1.Size = CreateGraphics().MeasureString(label_txt, label1.Font).ToSize();
于 2013-03-05T13:50:33.397 に答える