pitek3010 napisał(a):Witam mam pytanie jak nmieścić komponent Label na ProgressBar ?
TWndMethod FProgressBarWndProc;
//...
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
FProgressBarWndProc = ProgressBar1->WindowProc;
ProgressBar1->WindowProc = ProgressBar1WndProc;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ProgressBar1WndProc(TMessage& Message)
{
if (Message.Msg == WM_PAINT)
{
TCanvas * Canvas = new TCanvas;
try
{
Canvas->Handle = GetDC(ProgressBar1->Handle);
try
{
// erase background
TRect R = ProgressBar1->ClientRect;
Canvas->Brush->Color = Color;
Canvas->FillRect(R);
// let the progressbar paint itself
FProgressBarWndProc(Message);
// draw text
Graphics::TBitmap * B = new Graphics::TBitmap;
try
{
B->Width = R.Right - R.Left;
B->Height = R.Bottom - R.Top;
B->Canvas->Brush->Color = clBlack;
B->Canvas->FillRect(R);
B->Canvas->Font = this->Font;
B->Canvas->Font->Style = B->Canvas->Font->Style << fsBold; //+
B->Canvas->Font->Color = clWhite;
const double ipr = 100.0 * ProgressBar1->Position / ProgressBar1->Max;
const AnsiString pr = AnsiString().sprintf("%.0f%%", ipr);
R.top += 2; //+
DrawText(B->Canvas->Handle, pr.c_str(), -1, &R, DT_NOCLIP | DT_CENTER);
BitBlt(Canvas->Handle, 0, 0, B->Width, B->Height, B->Canvas->Handle, 0, 0, SRCINVERT);
}
__finally
{
delete B;
}
}
__finally
{
ReleaseDC(ProgressBar1->Handle, Canvas->Handle);
}
}
__finally
{
delete Canvas;
}
}
else FProgressBarWndProc(Message);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
ProgressBar1->WindowProc = FProgressBarWndProc;
FProgressBarWndProc = 0;
}
//---------------------------------------------------------------------------
// ...
Canvas->Brush->Style = bsClear;
DrawText(Canvas->Handle, pr.c_str(), -1, &R, DT_NOCLIP | DT_CENTER);
//...
Powrót do Ogólne problemy z programowaniem
Użytkownicy przeglądający ten dział: Brak zalogowanych użytkowników i 16 gości