私のニーズに合わせてカスタムのリストビューコントロールを作成しましたが、フォームが表示されてもリストビューにコンテンツが表示されない最初の負荷。カスタムリストビューコントロールが最初に表示されたときにペイントされません
フォームのサイズを変更したり、コントロール(ListViewで再描画を強制するもの)をクリックした場合、予期したとおりに表示されます。
今日の小さな変更を加えてコントロールを再構築するまで、それはうまく動作していました。私が行ったすべての変更を取り除いて再構築しましたが、問題はまだ発生します。フォームが最初に読み込まれたときになぜ表示されないのか(塗料)これは私が私のカスタムListViewコントロールでカスタム描画を行うために使用するものである
...私はまた私のカスタムコントロールのコンストラクタで、次のものを設定し
protected override void OnDrawItem(DrawListViewItemEventArgs e)
{
Image image = e.Item.ImageList.Images[e.Item.ImageIndex];
Size textSize = new Size((int)e.Graphics.MeasureString(e.Item.Text, e.Item.Font).Width, (int)e.Graphics.MeasureString(e.Item.Text, e.Item.Font).Height);
//Get the area of the item to be painted
Rectangle bounds = e.Bounds;
bounds.X = 0;
bounds.Width = this.Width;
//Set the spacing on the list view items
int hPadding = 0;
int vPadding = 0;
IntPtr padding = (IntPtr)(int)(((ushort)(hPadding + bounds.Width)) | (uint)((vPadding + bounds.Height) << 16));
SendMessage(this.Handle, (uint)ListViewMessage.LVM_SETICONSPACING, IntPtr.Zero, padding);
//Set the positions of the image and text
int imageLeft = (bounds.Width/2) - (image.Width/2);
int imageTop = bounds.Top + 3;
int textLeft = (bounds.Width/2) - (textSize.Width/2);
int textTop = imageTop + image.Height;
Point imagePosition = new Point(imageLeft, imageTop);
Point textPosition = new Point(textLeft, textTop);
//Draw background
using (Brush brush = new SolidBrush(e.Item.BackColor))
e.Graphics.FillRectangle(brush, bounds);
//Draw selected
if (e.Item.Selected)
{
using (Brush brush = new SolidBrush(m_SelectedColor))
e.Graphics.FillRectangle(brush, bounds);
}
//Draw image
e.Graphics.DrawImage(image, imagePosition);
//Draw text
e.Graphics.DrawString(e.Item.Text, e.Item.Font, new SolidBrush(e.Item.ForeColor), textPosition);
}
...
public MyListView()
{
this.DoubleBuffered = true;
this.OwnerDraw = true;
this.View = View.LargeIcon;
this.Cursor = Cursors.Hand;
this.Scrollable = false;
}
私はまた、あなたがitselを再描画するためにセットにコントロールを設定する必要が
public class MyListView : ListView
{
//All my source
}
hapenしていますか?また、OnDrawItemが呼び出されていないか、最初は期待どおりに機能しないのでしょうか? (ブレークポイントを設定!) – TaW
私はフォーム上に直接持っています。私はタブコントロールを使用していましたが、それに問題があったので、その方向から逃げました。 OnDrawItemが「呼び出された」かどうかを確認するにはどうすればよいですか?私はそれが最初のドローで期待どおりに働くだけではないかもしれないと思っています...私は理由を理解できません。コントロールが表示された後にSAMEコードが完璧に機能する場合、最初の描画はなぜですか? –
実際には、私は、サイズ変更などを強制するようなことをするまでは、何らかの理由でOnDrawItemが起動しないと思います。 –