23

我在我的表单中使用 TListView(它继承自 TCustomListView),当我将 ListView 样式更改为“vsSmallIcon”时,图标排列不当。自从我们将代码从 Borland 2006 移植到 XE4 后,我们就发现了这个问题。其余所有“ViewStyle”,如 vsIcon、vsList 和 vsReport 工作正常。有没有人在 VCL 的 TlistView 组件中遇到过类似的问题?我已经尝试过 ListView1->Arrange(arDefault) 和 'AutoArrange' 图标选项,但对于 'vsSmallIcon' TViewStyle 似乎没有任何效果。

我在 Windows 7 上并使用带有 Update1 的 RAD Studio XE4。

谢谢,
SantoshThankachan
PS:添加了一张图片来显示 vsSmallIcon TViewStyle 的这个问题。

TCustomListView TViewStyle vsSmallIcon 排列不当的图标 Borland 2005 TListView 'vsSmallIcon' 排列整齐

代码如下:

//SmallIconIssue.h
#ifndef SmallIconsIssueH
#define SmallIconsIssueH
#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.Forms.hpp>
#include <Vcl.ImgList.hpp>
#include <Vcl.ComCtrls.hpp>
class TSmallIconTest : public TForm
{
__published:    // IDE-managed Components
  TImageList *ImageList1;
  TComboBox *ComboBox1;
  TListView *ListView1;
  TLabel *Label1;
  void __fastcall FormCreate(TObject *Sender);
  void __fastcall ComboBox1Click(TObject *Sender);
private:    // User declarations
public:     // User declarations
  __fastcall TSmallIconTest(TComponent* Owner);
};
extern PACKAGE TSmallIconTest *SmallIconTest;
#endif

//SmallIconIssue.cpp
#pragma package(smart_init)
#pragma resource "*.dfm"
TSmallIconTest *SmallIconTest;
__fastcall TSmallIconTest::TSmallIconTest(TComponent* Owner) : TForm(Owner) {}

void __fastcall TSmallIconTest::FormCreate(TObject *Sender) {
  const char Names[42][2][10] =
   {{"Rubble","Barny"},
    {"Michael", "Johnson"},
    {"Bunny", "Bugs"},
    {"Silver", "HiHo"},
    {"Silver1", "HiHo1"},
    {"Silver2", "HiHo2"},
    {"Silver3", "HiHo3"},
    {"Silver4", "HiHo4"},
    {"Silver5", "HiHo5"},
    {"Silver6", "HiHo6"},
    {"Silver7", "HiHo7"},
    {"Silver8", "HiHo8"},
    {"Silver9", "HiHo9"},
    {"Silver11", "HiHo11"},
    {"Silver22", "HiHo22"},
    {"Silver33", "HiHo33"},
    {"Silver44", "HiHo44"},
    {"Silver55", "HiHo55"},
    {"Silver66", "HiHo66"},
    {"Silver77", "HiHo77"},
    {"Simpson1", "Bart1"},
    {"Simpson2", "Bart2"},
    {"Simpson3", "Bart3"},
    {"Simpson4", "Bart4"},
    {"Simpson5", "Bart5"},
    {"Simpson6", "Bart6"},
    {"Simpson7", "Bart7"},
    {"Simpson8", "Bart8"},
    {"Simpson9", "Bart9"},
    {"Simpson11", "Bart11"},
    {"Simpson22", "Bart22"},
    {"Simpson33", "Bart33"},
    {"Simpson44", "Bart44"},
    {"Simpson55", "Bart55"},
    {"Simpson66", "Bart66"},
    {"Simpson77", "Bart77"},
    {"Simpson88", "Bart88"},
    {"Simpson99", "Bart99"},
    {"Simpson00", "Bart00"},
    {"Simpson12", "Bart12"},
    {"Simpson13", "Bart13"},
    {"Squirrel", "Rocky"}};

  TListItem *Item;
  TListColumn *Column;
  const char imagenames[30][30] = {
    "Borland2 Image akjlhfkja",
    "Borland3 Imagewerq r",
    "Borland4 Rest qew reqwr",
    "Borland5 Imagedf fa",
    "Borland6 Free df ",
    "Borland7 Image af ",
    "Borland8 Clear ad3e",
    "Borland9 Image123 ",
    "Borland11 df d",
    "Borland22 Imagea fa f",
    "Borland33 hmmm f sdf f",
    "C++ Image",
    "Borland1 Test",
    "Borland44 Imageq3r r",
    "Borland55 abcdefg rest",
    "Borland66 Imageq tr trt",
    "Borland77 no rest atall dg",
    "Borland88 Imageqtree",
    "Borland99 Free VCL tree",
    "Borland12 Imagedf fa",
    "Borland23 Blurr df d",
    "Borland34 r",
    "Borland45 Rest qew reqwr",
    "Borland56 Free df ",
    "Borland67 Image123 ",
    "Borland78 Imagea fa f",
    "Borland89 Being",
    "Borland90 AdFree",
    "Borland13 Image akjlhfkja",
    "Delphi23 Image color"
  };
  const char Col2Array[30][60] =
  {
    "Documentation for the C++ icon.",
    "Borland1 icon test.",
    "Borland2 icon. Rest sar",
    "Borland3 icon Free .",
    "Borland4 icon Tree. af",
    "Borland6 icon Kree kjadsf k.",
    "Borland7 icon lest hghghg.",
    "Borland8 icon mnmnm.",
    "Borland9 icon jiop werq .",
    "Borland0 icon terere df af .",
    "Borland5 icon nmijh fdferfr .",
    "Borland11 icon Clear vc.",
    "Borland22 icon Image sdgfsdg.",
    "Borland33 icon Picture t4.",
    "Borland44 iconv Congress25245.",
    "Borland55 icon Labor 25v545.",
    "Borland66 icon tony b3764656.",
    "Borland77 icon 5 Abott reg354.",
    "Borland88 icon. Rest sar",
    "Borland99 icon Kevin 342455vreg354.",
    "Borland00 icon test.",
    "Borland12 icon Free .",
    "Borland23 icon Kree kjadsf k.",
    "Borland34 con Tree. af",
    "Borland56 icon nmijh fdferfr .",
    "Borland45 icon mnmnm.",
    "Borland56 icon jiop werq .",
    "Borland78 icon terere df af .",
    "Borland89 icon lest hghghg.",
    "Delphi90 icon Rudd 45c rewffretew."
  };

  ListView1->SmallImages = ImageList1;
  ListView1->LargeImages = ImageList1;

  for (int i = 0; i < ImageList1->Count; i++)
  {
    Item = ListView1->Items->Add();
    Item->Caption = imagenames[i];
    Item->ImageIndex = i;
    Item->SubItems->Add(Col2Array[i]);
  }
  // Create two columns to show during viewing as vsReport
  Column = ListView1->Columns->Add();
  Column->Caption = "Image Name";
  Column->Width = 200;
  Column = ListView1->Columns->Add();
  Column->Caption = "Image Description";
  Column->Width = 200;

  // Add View styles and constants to the Combo Box
  ComboBox1->Items->AddObject("vsIcon", reinterpret_cast<TObject *>(vsIcon));
  ComboBox1->Items->AddObject("vsList", reinterpret_cast<TObject *>(vsList));
  ComboBox1->Items->AddObject("vsReport", reinterpret_cast<TObject *>(vsReport));
  ComboBox1->Items->AddObject("vsSmallIcon", reinterpret_cast<TObject *>(vsSmallIcon));

  // Display First item in the Combo Box and arrange ListView accordingly...
  ComboBox1->ItemIndex = 0;
  ListView1->ViewStyle = (TViewStyle) ComboBox1->Items->Objects[ComboBox1->ItemIndex];
  ListView1->Arrange(arDefault);
}

void __fastcall TSmallIconTest::ComboBox1Click(TObject *Sender)
{
  ListView1->ViewStyle = (TViewStyle) ComboBox1->Items->Objects[ComboBox1->ItemIndex];
  ListView1->Arrange(arDefault);
}
4

0 回答 0