[問題] BCB程式問題
小弟程式薄弱請大家見諒
我程式使用到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
06/13 09:59, 1F
→
06/13 09:59, , 2F
06/13 09:59, 2F
→
06/13 10:00, , 3F
06/13 10:00, 3F
→
06/13 10:01, , 4F
06/13 10:01, 4F
推
06/13 10:05, , 5F
06/13 10:05, 5F
→
06/15 13:47, , 6F
06/15 13:47, 6F
→
06/15 13:47, , 7F
06/15 13:47, 7F
→
06/15 13:48, , 8F
06/15 13:48, 8F
→
06/15 13:48, , 9F
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
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
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章