0

環境:VS 2008、.NET 2.0、WinForms

タイルモードのリストビューがあります。一部のアイテムには画像が関連付けられています。しない人もいます。

コンテンツ(リストビューアイテム)は、ユーザーがいくつかのコントロールをクリックすると更新されることがよくあります。これが発生すると、新しいアイテムのいずれにも画像がないように見えることがあります。その場合は、画像用に予約したアイテムの左側の空きスペースをなくしたいと思います。画像リストを一時的に削除するために、次の擬似コードを試しました

list.Items.Clear();
FillList();
list.LargeImageList= (none of the items has image) ? null : MyImageList;

しかし、それは機能しません。空きスペースはまだそこにあります。私はまた、無駄に、コントロールを塗り直そうとします。

代替テキストhttp://apptranslator.com/_so/so_list1.jpg 代替テキストhttp://apptranslator.com/_so/so_list2.jpg 代替テキストhttp://apptranslator.com/_so/so_list3.jpg

左:画像付きのリスト。

中央:画像なしのリスト。画像用のスペースが表示されます。

右:画像がないときの様子。

編集:私もこのテストを行いました:デザイナーで画像リストを割り当てないでください。最初のディスプレイに画像が含まれていない場合は、期待どおりの結果が得られます。次に、クリックして画像を表示します(画像を取得します)。もう一度クリックすると、画像なしの選択に戻ります。画像スペースは消えません。

また、ハス、いいえ、私は小さな画像や状態の画像を使用していません。大きな画像のみ。

私に何ができる?TIA。

4

3 に答える 3

1

本気ですか?このテストケースで動作しています:

using System;
using System.Windows.Forms;
public class MainForm : Form
{
    private System.ComponentModel.IContainer components = null;
    private System.Windows.Forms.ListView listView;
    private System.Windows.Forms.ImageList emptySmallImageList;
    private System.Windows.Forms.ImageList largeImageList;
    private System.Windows.Forms.Button imageListSmallButton;
    private System.Windows.Forms.Button imageListLargeButton;

    public MainForm()
    {
        InitializeComponent();
    }

    private void OnImageListSmallButtonClick(object sender, EventArgs e)
    {
        this.listView.LargeImageList = emptySmallImageList;       
    }

    private void OnImageListLargeButtonClick(object sender, EventArgs e)
    {
        this.listView.LargeImageList = largeImageList;
    }

    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        System.Windows.Forms.ListViewItem listViewItem5 = new System.Windows.Forms.ListViewItem("fgsdfg");
        System.Windows.Forms.ListViewItem listViewItem6 = new System.Windows.Forms.ListViewItem("sdfgsdfg");
        System.Windows.Forms.ListViewItem listViewItem7 = new System.Windows.Forms.ListViewItem("sdfgsdfgsdfg");
        System.Windows.Forms.ListViewItem listViewItem8 = new System.Windows.Forms.ListViewItem("sdfgsdfg");
        this.listView = new System.Windows.Forms.ListView();
        this.largeImageList = new System.Windows.Forms.ImageList(this.components);
        this.emptySmallImageList = new System.Windows.Forms.ImageList(this.components);
        this.imageListSmallButton = new System.Windows.Forms.Button();
        this.imageListLargeButton = new System.Windows.Forms.Button();
        this.SuspendLayout();
        // 
        // listView
        // 
        this.listView.Dock = System.Windows.Forms.DockStyle.Fill;
        this.listView.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
        listViewItem5,
        listViewItem6,
        listViewItem7,
        listViewItem8});
        this.listView.LargeImageList = this.largeImageList;
        this.listView.Location = new System.Drawing.Point(0, 0);
        this.listView.Name = "listView";
        this.listView.Size = new System.Drawing.Size(292, 266);
        this.listView.TabIndex = 0;
        this.listView.UseCompatibleStateImageBehavior = false;
        this.listView.View = System.Windows.Forms.View.Tile;
        // 
        // largeImageList
        // 
        this.largeImageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
        this.largeImageList.ImageSize = new System.Drawing.Size(32, 32);
        this.largeImageList.TransparentColor = System.Drawing.Color.Transparent;
        // 
        // emptySmallImageList
        // 
        this.emptySmallImageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
        this.emptySmallImageList.ImageSize = new System.Drawing.Size(1, 1);
        this.emptySmallImageList.TransparentColor = System.Drawing.Color.Transparent;
        // 
        // imageListSmallButton
        // 
        this.imageListSmallButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
        this.imageListSmallButton.Location = new System.Drawing.Point(175, 12);
        this.imageListSmallButton.Name = "imageListSmallButton";
        this.imageListSmallButton.Size = new System.Drawing.Size(95, 23);
        this.imageListSmallButton.TabIndex = 1;
        this.imageListSmallButton.Text = "ImageList 1x1";
        this.imageListSmallButton.UseVisualStyleBackColor = true;
        this.imageListSmallButton.Click += new System.EventHandler(this.OnImageListSmallButtonClick);
        // 
        // imageListLargeButton
        // 
        this.imageListLargeButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
        this.imageListLargeButton.Location = new System.Drawing.Point(175, 53);
        this.imageListLargeButton.Name = "imageListLargeButton";
        this.imageListLargeButton.Size = new System.Drawing.Size(95, 23);
        this.imageListLargeButton.TabIndex = 2;
        this.imageListLargeButton.Text = "ImageList 32x32";
        this.imageListLargeButton.UseVisualStyleBackColor = true;
        this.imageListLargeButton.Click += new System.EventHandler(this.OnImageListLargeButtonClick);
        // 
        // MainForm
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(292, 266);
        this.Controls.Add(this.imageListLargeButton);
        this.Controls.Add(this.imageListSmallButton);
        this.Controls.Add(this.listView);
        this.Name = "MainForm";
        this.Text = "Form1";
        this.ResumeLayout(false);

    }

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new MainForm());
    }
}

なぜサイズ変更を行わないのか理解できません... SendMessage を実行するとうまくいくのではないかと思いますが、どのようなメッセージになるかはわかりません。

あなたがこれを行うかどうか私が見ることができる最高の仕事:

imageList1.ImageSize = new Size(1,1);

テスト用のものを作成しましたが、設定しない限り動作するように見えましたStateImageList。もクリアStateImageListですか?

于 2008-11-25T12:59:20.743 に答える
0

完全に制御したい場合は、listview.drawitem イベントを使用します。

于 2009-09-29T01:55:51.890 に答える