Windowsフォーム(C#)にはツールヒントの高さと幅を動的に設定する方法があります。私はDataViewGridコントロールで作業しているので、Showメソッドを使用する必要があります。 (それ自身のデバイスに去ったとき)しかし、私は、ツールヒントコントロールは、常に提供するコンテンツに合わせて調整しないことに気づいた....Windowsフォーム(C#)には、ツールヒントの高さと幅を動的に設定する方法があります。
例を:ToolTipコントロールを持つ
は(と呼ばれるフォームに追加しましたこの上
ttText.Show("Well, too bad -- so much for your stamina, you should not be here!\nSo the little bear responds!");
任意の考え:
ttText.Show("I'm hungry\nand waiting!");
は、次の呼び出しを切り捨てます:ttText)とは、それが最初のテキストを表示しましたか?
ここ
はコードの例です... DataGridViewのは、それゆえ表示方法の使用をツールチップヘルプを表示する機構を必要とし、私は非DataViewGridsの別の場所で、この動作を見てきたことに留意してください: using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Windows.Forms;
namespace TestForm
{
class Form1 : Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.ttText = new System.Windows.Forms.ToolTip(this.components);
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// dataGridView1
//
this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(13, 19);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(453, 321);
this.dataGridView1.TabIndex = 0;
this.dataGridView1.CellMouseEnter += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_MouseCellEnter);
//
// ttText
//
this.ttText.AutomaticDelay = 60;
this.ttText.AutoPopDelay = 600000;
this.ttText.InitialDelay = 60;
this.ttText.IsBalloon = true;
this.ttText.ReshowDelay = 60;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(478, 352);
this.Controls.Add(this.dataGridView1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
}
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.ToolTip ttText;
public Form1()
{
InitializeComponent();
var ds = Sayings().ToList();
dataGridView1.DataSource = ds;
}
public List<dynamic> Sayings()
{
return new List<dynamic>
{
new
{
Human = "I'm hungry\nand waiting!",
BabyBear = "Well, too bad -- so much for your stamina, you should not be here!\nSo the little bear responds!"
}
};
}
private void dataGridView1_MouseCellEnter(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex != -1 && e.RowIndex != -1)
{
var rect = dataGridView1.GetColumnDisplayRectangle(e.ColumnIndex, true);
var left = rect.Left + (int)(rect.Width * .5f);
var top = rect.Top;
Point displayPoint = new Point(left + this.ClientRectangle.Left, top + this.ClientRectangle.Top + 40);
ttText.Show(dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString(), this, displayPoint);
}
}
}
}
あなたは1列目の上に置くと、2番目は、ツールチップのテキストが切り捨てられます。
文字列パラメータだけをとる 'Show()'メソッドはどこにありますか? MSDNのそのメソッドにリンクできますか? –
http://msdn.microsoft.com/en-us/library/ms752368.aspx、これは役立つかもしれませんか? –
そして、コード例を追加しないと誰かが嫌がる前に、ここに行く: – Silverten