複数行のテキスト文字列 (例: "Stuff\nMore Stuff\nYet More Stuff") があり、それをビットマップと共にツールチップにペイントしたいと考えています。ビットマップをペイントしているので、OwnerDraw を true に設定する必要があります。また、Popup イベントも処理しているので、ツールチップのサイズをテキストとビットマップを保持するのに十分な大きさにすることができます。
e.DrawBackground と e.DrawBorder() を呼び出してから、ツールチップ領域の左側にビットマップをペイントしています。
テキストを左揃えにするために e.DrawText() に渡すことができるフラグのセットはありますが、ビットマップ上に描画されないようにオフセットすることはできますか? または、すべてのテキストもカスタム描画する必要がありますか (おそらく改行などで文字列を分割する必要があります)?
更新: 最終的なコードは次のようになります。
private void _ItemTip_Draw(object sender, DrawToolTipEventArgs e)
{
e.DrawBackground();
e.DrawBorder();
// Reserve a square of size e.Bounds.Height x e.Bounds.Height
// for the image. Keep a margin around it so that it looks good.
int margin = 2;
Image i = _ItemTip.Tag as Image;
if (i != null)
{
int side = e.Bounds.Height - 2 * margin;
e.Graphics.DrawImage(i, new Rectangle(margin, margin, side, side));
}
// Construct bounding rectangle for text (don't want to paint it over the image).
int textOffset = e.Bounds.Height + 2 * margin;
RectangleF rText = e.Bounds;
rText.Offset(textOffset, 0);
rText.Width -= textOffset;
e.Graphics.DrawString(e.ToolTipText, e.Font, Brushes.Black, rText);
}