[問題] BCB程式問題

看板C_and_CPP (C/C++)作者 (自由)時間11年前 (2014/06/08 16:32), 編輯推噓3(3011)
留言14則, 2人參與, 最新討論串1/1
小弟程式薄弱請大家見諒 我程式使用到StringGrid和ComboBox物件,在StringGrid裡面的表格點進去使用到 ComboBox可以選擇選項,如選擇Teen ,表格會出現黃色框框和黑色的Teen文字,但 我現在想要有放大縮小功能,單純把StringGrid長寬放大縮小,有放大縮小的感覺 但是裡面的文字不會隨著放大縮小,並且本來變成黃色的會不見,請教大大怎麼修改 給點提示,謝謝 下面是我的程式碼 //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; int x, y; int a,b; int t=0; float ScaleFactor1=2; float ScaleFactor2=0.5; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::StringGrid1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { int x, y; StringGrid1->MouseToCell(X, Y, x, y); a=x; b=y; Label1->Caption = "Col: " + AnsiString(x) + " Row: " + AnsiString(y); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { StringGrid1->DefaultRowHeight=ComboBox1->Height; StringGrid1->RowHeights[0]=18; StringGrid1->ColWidths[2]=80; StringGrid1->Cells[0][0]="FirstName"; StringGrid1->Cells[1][0]="LastName"; StringGrid1->Cells[2][0]="SBVLEdit LV1"; StringGrid1->Cells[3][0]="Action"; ComboBox1->Text=""; ComboBox1->Items->Add("Teen"); ComboBox1->Items->Add("Adult"); ComboBox1->Items->Add("Senior"); ComboBox1->Items->Add(""); ComboBox1->Visible=False; } //--------------------------------------------------------------------------- void __fastcall TForm1::ComboBox1Change(TObject *Sender) { StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row]=ComboBox1->Items->Strings[ComboBox1->ItemIndex]; } //--------------------------------------------------------------------------- void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State) { if(ComboBox1->Items->Strings[ComboBox1->ItemIndex]=="Teen") { if(StringGrid1->Canvas->Brush->Color==clYellow) { ComboBox1->Visible=true; StringGrid1->Canvas->Brush->Color=clYellow; StringGrid1->Canvas->TextRect (Rect, Rect.Left, Rect.Top,StringGrid1->Cells[ACol][ARow]); } else if(StringGrid1->Canvas->Brush->Color!=clYellow) { ComboBox1->Visible=false ; StringGrid1->Canvas->Brush->Color=clYellow; StringGrid1->Canvas->TextRect (Rect, Rect.Left, Rect.Top,StringGrid1->Cells[ACol][ARow]); } } } //--------------------------------------------------------------------------- void __fastcall TForm1::StringGrid1Click(TObject *Sender) { TRect r; if(StringGrid1->Col>0) { int ACol=StringGrid1->Col; int ARow=StringGrid1->Row; r=StringGrid1->CellRect(ACol,ARow); ComboBox1->Top=StringGrid1->Top + r.Top + StringGrid1->GridLineWidth+1; ComboBox1->Left=StringGrid1->Left + r.Left + StringGrid1->GridLineWidth+1; ComboBox1->Width=r .Right-r.Left; ComboBox1->ItemIndex=ComboBox1->Items->IndexOf(StringGrid1->Cells[ACol][ARow]); ComboBox1->Visible=true ; } else ComboBox1->Visible=false ; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { if(SaveDialog1->Execute()) { TStringList *sl=new TStringList; for(int j=0;j<StringGrid1->RowCount;j++) { for(int i=0;i<StringGrid1->ColCount;i++) sl->Add(t); } sl->SaveToFile(SaveDialog1->FileName); } } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void __fastcall TForm1::Button4Click(TObject *Sender) { StringGrid1->DefaultColWidth=StringGrid1->DefaultColWidth/ScaleFactor1; StringGrid1->DefaultRowHeight=StringGrid1->DefaultRowHeight/ScaleFactor1; StringGrid1->Width=StringGrid1->Width/ScaleFactor1; StringGrid1->Height=StringGrid1->Height/ScaleFactor1; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button5Click(TObject *Sender) { StringGrid1->DefaultColWidth=StringGrid1->DefaultColWidth/ScaleFactor2; StringGrid1->DefaultRowHeight=StringGrid1->DefaultRowHeight/ScaleFactor2; StringGrid1->Width=StringGrid1->Width/ScaleFactor2; StringGrid1->Height=StringGrid1->Height/ScaleFactor2; } //--------------------------------------------------------------------------- -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.134.32.119 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1402216333.A.3CA.html

06/13 09:59, , 1F
手邊沒有可以測 我猜是 DefaultColWidth (int)
06/13 09:59, 1F

06/13 09:59, , 2F
DefaultRowHeight (int)
06/13 09:59, 2F

06/13 10:00, , 3F
Width (int) Height(int) 四個int值 做除法以後
06/13 10:00, 3F

06/13 10:01, , 4F
因為四捨五入 後搭配出來的值有衝突
06/13 10:01, 4F

06/13 10:05, , 5F
噗 抱歉我看錯題目我以為按了會出錯 SORRY
06/13 10:05, 5F

06/15 13:47, , 6F
簡單來說我設計StringGrid裡的表格按按鈕會放大和縮小
06/15 13:47, 6F

06/15 13:47, , 7F
但ComboBox有如何也會跟著放大縮小?
06/15 13:47, 7F

06/15 13:48, , 8F
因為我設計的StringGrid裡的表格可以先選擇選項利用Comb
06/15 13:48, 8F

06/15 13:48, , 9F
ComboBox,但是選完後我在放大縮小後
06/15 13:48, 9F

06/15 13:49, , 10F
原本在表格內選好的文字就會跑掉,想問一下
06/15 13:49, 10F

06/15 13:49, , 11F
我哪裡有問題可以給點提示嗎?
06/15 13:49, 11F

06/16 11:29, , 12F
我不知道你後續要做啥 不知道用EXCEL是否比較簡單
06/16 11:29, 12F

06/16 11:29, , 13F
06/16 11:29, 13F

06/16 11:29, , 14F
06/16 11:29, 14F
文章代碼(AID): #1Jb1-DFA (C_and_CPP)
文章代碼(AID): #1Jb1-DFA (C_and_CPP)