請問一下如何在載入圖片的時候,同時改變Form1的寬度? |
答題得分者是:ys168
|
sunwingman
一般會員 發表:26 回覆:47 積分:14 註冊:2008-05-14 發送簡訊給我 |
|
ys168
初階會員 發表:3 回覆:24 積分:25 註冊:2005-10-14 發送簡訊給我 |
[code cpp] // 加個 ComboBox 物件 // 以下是 ComboBox 的 Text 看要將資料儲存成檔案 或手動加入ComboBox->Item 1600% 1200% 800% 600% 500% 400% 300% 200% 100% 75% 67% 50% 33% 20% 10% 5% 原圖大小 顯示全圖 //------------------------------------------------------------------ void __fastcall TForm1::ComboBox1Click(TObject *Sender) { String cbTxt=ComboBox1->Text; float nNum,dNum; int mw,mh,w,h; mw = Form2->imgWidth; mh = Form2->imgHeight; switch(ComboBox1->ItemIndex) { case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: //ShowMessage("0-8=>" IntToStr(ComboBox1->ItemIndex)); Form2->ClientWidth=Form2->imgWidth; Form2->ClientHeight=Form2->imgHeight; Form2->Image1->Width=Form2->imgWidth; Form2->Image1->Height=Form2->imgHeight; big=true; cbTxt=cbTxt.SubString(1,cbTxt.Pos("%")-1); nNum=cbTxt.ToDouble(); dNum=nNum/100; w=mw*dNum; h=mh*dNum; Form2->AutoSize=false; Form2->Image1->Stretch=true; if(h>600) { if(w>(Screen->Width-15)) Form2->ClientWidth=Screen->Width-15; else Form2->ClientWidth=(float)mw*dNum; Form2->ClientHeight=600; } else { Form2->ClientWidth=(float)mw*dNum; Form2->ClientHeight=(float)mh*dNum; } Form2->Image1->Width=(float)mw*dNum; Form2->Image1->Height=(float)mh*dNum; break; case 9: case 10: case 11: case 12: //ShowMessage("9-12=>" IntToStr(ComboBox1->ItemIndex)); cbTxt=cbTxt.SubString(1,cbTxt.Pos("%")-1); nNum=cbTxt.ToDouble(); dNum=nNum/100; Form2->Image1->Stretch=true; Form2->ClientWidth=(float)mw*dNum; Form2->ClientHeight=(float)mh*dNum; Form2->Image1->Width=(float)mw*dNum; Form2->Image1->Height=(float)mh*dNum; Form2->AutoSize=true; Form2->ClientWidth=Form2->Image1->Width; Form2->ClientHeight=Form2->Image1->Height; break; case 13: case 14: case 15: //ShowMessage("13-15=>" IntToStr(ComboBox1->ItemIndex)); if(big) { Form2->AutoSize=true; Form2->ClientWidth=Form2->imgWidth; Form2->ClientHeight=Form2->imgHeight; Form2->Image1->Width=Form2->imgWidth; Form2->Image1->Height=Form2->imgHeight; big=false; } cbTxt=cbTxt.SubString(1,cbTxt.Pos("%")-1); nNum=cbTxt.ToDouble(); dNum=nNum/100; Form2->Image1->Width=(float)mw*dNum; Form2->Image1->Height=(float)mh*dNum; Form2->Image1->Stretch=true; Form2->AutoSize=false; Form2->Image1->Left=(Form2->ClientWidth/2)-(Form2->Image1->Width/2); Form2->ClientHeight=Form2->Image1->Height; break; case 16: //ShowMessage("16=>" IntToStr(ComboBox1->ItemIndex)); Form2->Image1->Show(); Form2->AutoSize=true; Form2->ClientWidth=Form2->imgWidth; Form2->ClientHeight=Form2->imgHeight; Form2->Image1->Width=Form2->imgWidth; Form2->Image1->Height=Form2->imgHeight; break; case 17: Form2->AutoSize=true; Form2->Image1->Stretch=true; nNum=(float)Form2->Image1->Width/Form2->Image1->Height; Form2->Image1->Width=Form1->ClientWidth-12; if((float)(Form1->ClientWidth-14)/nNum < 620) Form2->Image1->Height=(float)(Form1->ClientWidth-12)/nNum; else { Form2->Image1->Width=600*nNum; Form2->Image1->Height=600; // Image1高 = Form1->ClientHeight)-(StatusBar1->Height Panel1->Height 標題列高) } StatusBar1->Panels->Items[1]->Text="變更後 寬: " IntToStr(Form2->Image1->Width) AnsiString(", 高") IntToStr(Form2->Image1->Height); break; } } //--------------------------------------------------------------------------- 開2個視窗 當您開啟圖檔後, 點選ComboBox的項目 [/code]
------
yangshuh |
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
試試直接繪製背景圖
[code cpp] //--------------------------------------------------------------------------- #ifndef fMainH #define fMainH //--------------------------------------------------------------------------- #include #include #include #include #include <Forms.hpp><br />//--------------------------------------------------------------------------- class TForm1 : public TForm { __published: void __fastcall FormPaint(TObject *Sender); void __fastcall FormResize(TObject *Sender); private: public: __fastcall TForm1(TComponent* Owner); void __fastcall DrawBackground(TCanvas *Canvas, TRect r, AnsiString FileName); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "fMain.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::DrawBackground(TCanvas *Canvas, TRect r, AnsiString FileName) { if(FileExists(FileName)){ Graphics::TBitmap *bmp = new Graphics::TBitmap(); try{ bmp->LoadFromFile(FileName); Canvas->Lock(); try{ Canvas->StretchDraw(r,bmp); } __finally{ Canvas->Unlock(); } } __finally{ delete bmp; } } } //--------------------------------------------------------------------------- void __fastcall TForm1::FormPaint(TObject *Sender) { DrawBackground(Canvas, ClientRect, "D:\\TEST.BMP"); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormResize(TObject *Sender) { Invalidate(); } //--------------------------------------------------------------------------- [/code] |
sunwingman
一般會員 發表:26 回覆:47 積分:14 註冊:2008-05-14 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |