StringGrid和ComboBox放大縮小問題 |
缺席
|
qoror
一般會員 發表:2 回覆:0 積分:0 註冊:2014-06-09 發送簡訊給我 |
小弟程式薄弱請大家見諒
我程式使用到StringGrid和ComboBox物件,在StringGrid裡面的表格點進去使用到 ComboBox可以選擇選項,如選擇Teen ,表格會出現黃色框框和黑色的Teen文字,但 我現在想要有放大縮小功能,單純把StringGrid長寬放大縮小,有放大縮小的感覺 但是裡面的文字不會隨著放大縮小,並且本來變成黃色的會不見,請教大大怎麼修改 給點提示,謝謝 下面是我的程式碼 ------------------------------------ //--------------------------------------------------------------------------- #include #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 (State.Contains(gdFixed)) return; if(ComboBox1->Items->Strings[ComboBox1->ItemIndex]=="Teen") { //Label2->Caption = "123"; if(StringGrid1->Canvas->Brush->Color==clYellow) { //Label3->Caption = "123"; ComboBox1->Visible=true; StringGrid1->Canvas->Brush->Color=clYellow; // ««ª½ cell I´ºÅܦâ // if(ComboBox1->Items->Strings[ComboBox1->ItemIndex]=="Teen") StringGrid1->Canvas->TextRect (Rect, Rect.Left, Rect.Top,StringGrid1->Cells[ACol][ARow]); } else if(StringGrid1->Canvas->Brush->Color!=clYellow) { // Label4->Caption = "123"; ComboBox1->Visible=false ; StringGrid1->Canvas->Brush->Color=clYellow; // ««ª½ cell I´ºÅܦâ // if(ComboBox1->Items->Strings[ComboBox1->ItemIndex]=="Teen") 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 { for(int i=0;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; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button6Click(TObject *Sender) { TStringList *sl=new TStringList; AnsiString str; //ofstream outfile("C:\\rowcol.txt"); for (int col=1;col<=101;col ) { str=""; for (int row=1;row<=100;row ) { if (StringGrid1->Cells[row][col]!="") str=str StringGrid1->Cells[row][col] " "; else str=str; Application->ProcessMessages(); } sl->Add(str); //outfile << str.c_str() << endl; } //outfile.close(); sl->SaveToFile("test.txt"); delete sl; } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |