C
JürgenP schrieb:
Könntest du bitte vielleicht mal den kompletten Beispiel Quelltext posten. Ich bin wie gesagt nicht sehr fit in Sachen C++. Wäre echt nett, danke
?!?
Kenn ich Dein Programm?
Wenn Du noch nicht mal Schleifen oder Bedingungen kannst, wäre ein Grundlagenbuch wohl Mittel der Wahl.
Aber bitte. Hier meine Anfängerarbeit zu Thema Canvas:
void __fastcall TMainMLVisard::DBGridDrawColumnCell(TObject *Sender,
const TRect &Rect, int DataCol, TColumn *Column,
TGridDrawState State)
{
if (ADOQuery->Active) {
if (ADOQuery->RecordCount > 0) {
if (ADOQuery->FieldValues["MELOFLAG"] == 0 ) {
DBGrid->Canvas->Brush->Color = clMoneyGreen;
DBGrid->Canvas->Font->Color = clWindowText;
if (Column->FieldName=="STUNDENML" || Column->FieldName=="BEMERKUNG") {
DBGrid>Canvas->FillRect(Rect);
if (Column->FieldName=="STUNDENML")
// Text rechtsbündig ausgeben:
DrawCellText(DBGrid->Canvas,ADOQuery->FieldValues["STUNDENML"],Rect,taRightJustify);
}
}
}
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Zeichnen der Texte in die Tabellenzelle gem. der Ausrichtungsvorgabe:
//---------------------------------------------------------------------------
// Funktion benötigt folgende Parameter:
// 1. Zeiger auf Canvas des TStringGrid -> Graphics::TCanvas* pCanvas
// 2. Der Ausgabetext -> AnsiString slStr
// 3. Rechteck mit der Zellenposition -> TRect &Rect
// 4. Textausrichtung in der Zelle -> TAlignment eAlignment
// (taLeftJustify, taRightJustify oder taCenter)
//---------------------------------------------------------------------------
void __fastcall TMainMLVisard::DrawCellText(Graphics::TCanvas* pCanvas,
AnsiString slStr, TRect &Rect,
TAlignment eAlignment)
{
if(eAlignment == taLeftJustify)
{
pCanvas->TextRect(Rect, Rect.Left + 3,
(Rect.Top+Rect.Bottom-pCanvas->TextHeight(slStr))/2, slStr);
}
else if(eAlignment == taRightJustify)
{
pCanvas->TextRect(Rect, Rect.Right - pCanvas->TextWidth(slStr) - 3,
(Rect.Top+Rect.Bottom-pCanvas->TextHeight(slStr))/2, slStr);
}
else
{
pCanvas->TextRect(Rect, Rect.Left + (Rect.Right - Rect.Left)/2 -
pCanvas->TextWidth(slStr)/2, (Rect.Top+Rect.Bottom-
pCanvas->TextHeight(slStr))/2, slStr);
}
}