m8815010
版主
發表:99 回覆:372 積分:289 註冊:2003-11-13
發送簡訊給我
|
引言:
請教各位要如何把目錄內的圖(jpg,bmp)秀出像底圖的陣列方式(有Scroll bar來挑圖)?
在陣列圖上按一滑鼠左鍵就會在左下圖的地方呈現出大點的圖?
有試了在ScrollBox上放Image,但應有好一點的方法或資料可參考?
感謝..
發表人 - samdb 於 2004/10/28 23:44:42
samdb你好: 你想要做的效果不是就是一般 class="code">
Unit1.h
~~
#include //<---額外宣告 //---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TListView *ListView1; //add this object
TImageList *ImageList1; //add this object
TOpenDialog *OpenDialog1; //add this object
TImage *Image1; //add this object
void __fastcall FormCreate(TObject *Sender);
void __fastcall ListView1DblClick(TObject *Sender);
void __fastcall ListView1SelectItem(TObject *Sender,
TListItem *Item, bool Selected);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
}; ~~ Unit1.cpp
~~
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
ListView1->ViewStyle=vsIcon; //設定為大圖示模式
ListView1->LargeImages=ImageList1; //大圖示來源元件
//ImageList1->Masked=false;
ImageList1->Height=100; //default 大圖示 height
ImageList1->Width=100; //default 大圖示 width Image1->Height=240; //default 放大圖的heigth
Image1->Width=320; //default 放大圖的width
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListView1DblClick(TObject *Sender)
{
if (OpenDialog1->Execute()) {
TListItem* Itm;
Graphics::TBitmap *bmp=new Graphics::TBitmap(); Itm=ListView1->Items->Add();
Itm->Caption=OpenDialog1->FileName; //TJPEGImage *jp=new TJPEGImage(); //如果檔案是.jpg的話
//jp->LoadFromFile(OpenDialog1->FileName);
//bmp->Assign(jp); bmp->LoadFromFile(OpenDialog1->FileName); //如果檔案是.bmp的話 TRect SrcRect=Rect(0,0,bmp->Width,bmp->Height);
TRect DesRect=Rect(0,0,100,100);
bmp->Canvas->CopyRect(DesRect,bmp->Canvas,SrcRect); //縮圖 Itm->ImageIndex=ImageList1->Add(bmp,NULL); delete bmp;
//delete jp; //如果檔案是.jpg的話
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListView1SelectItem(TObject *Sender,
TListItem *Item, bool Selected)
{
Graphics::TBitmap* bmp=new Graphics::TBitmap;
bmp->LoadFromFile(Item->Caption); Image1->Picture->Bitmap=bmp;
delete bmp;
}
//--------------------------------------------------------------------------- 參著參著!
|