Page 1 of 1
controls position
Posted: Sat Jun 24, 2006 4:45 pm
by hdassler
hi everybody,
short question:
how can I get the absolute position for a control in a document?
thx
( always tables, I'll never understand it! ;o))) )
Posted: Mon Jun 26, 2006 1:22 pm
by hdassler
oh, no anwsers.
maybe I have to concretize it.
Wanna use RV as an report designer.
The problem is while printing controls (tmemo).
Preview looks fine, but not print out.
So I wanna replace the image and draw text
directly to printer canvas.
So I need exactly the position of this control.
maybe know anyone knows, how to realize.
henri
Posted: Mon Jun 26, 2006 1:45 pm
by Jacek Puczynski
Hi.
I think you could use function GetItemCoords in order to establish memo position relative to Canvas.
Greetings, Jacek.
Posted: Mon Jun 26, 2006 2:17 pm
by hdassler
hi jacek,
well, your're right. GetItemCoords works.
But not in table.
the way I tried:
Code: Select all
if(Sender->rv->RVData->GetItemStyle(ItemNo) == rvsTable) {
TRVTableItemInfo *table = (TRVTableItemInfo *) ((TRichViewEdit*) (TRVReportHelper * ) Sender)->RichView)->GetItem(ItemNo);
TRVTableItemInfo *table = (TRVTableItemInfo *) ((TRichViewEdit *) ((TRVReportHelper * ) Sender)->RichView)->GetItem(ItemNo);
table->GetCellWhichOwnsControl(PrintMe, row, col, x);
Cell1 = table->Cells[row][col];
Cell1->GetItemCoords(Cell1->FindControlItemNo(PrintMe), l,t);
}
else {
Sender->rv->RVData->GetItemCoords(ItemNo,l,t);
}
When I use getItemCoords in tables I get coords of table.
but how to get position in table? The code above don't work.
But I always have problems with tables. Maybe I not understood
the system with tables ;o))
henri
Posted: Mon Jun 26, 2006 3:23 pm
by Jacek Puczynski
Hmm. Why don't you simply print TMemo Canvas?
Code: Select all
TCanvas *C = new TCanvas;
C->Handle=GetDC(Memo1->Handle);
//example: show memo in TImage
Image1->Canvas->Handle=C->Handle;
//printing C
ReleaseDC(Memo1->Handle,C->Handle);
C->Free();
Posted: Mon Jun 26, 2006 4:59 pm
by hdassler
the problem is, I'm not really a c++ developer but have to solve this
problem.
this image shows, what happen without replacing memo.
So I tested your code. but no image returns
Code: Select all
void __fastcall TFormDruck::rvhHeaderPrintComponent1(TCustomRVPrint *Sender,
TControl *PrintMe, Graphics::TBitmap *&ComponentImage)
{
TMemo *Memo = (TMemo *) PrintMe;
TCanvas *C = new TCanvas;
C->Handle=GetDC(Memo->Handle);
Graphics::TBitmap *Img = new Graphics::TBitmap;
Img->Canvas->Handle = C->Handle;
//ReleaseDC(Memo->Handle,C->Handle);
//C->Free();
ComponentImage = Img;
}
I also thought about, using other controls as a memo. but no idea.
Posted: Mon Jun 26, 2006 7:23 pm
by Jacek Puczynski
Try it.
Code: Select all
TCanvas *C = new TCanvas;
C->Handle=GetDC(Memo->Handle);
Graphics::TBitmap *Img = new Graphics::TBitmap;
Img->Handle=CreateCompatibleBitmap(C->Handle, Memo->Width, Memo->Height);
TRect rect = TRect(0,0,Memo->Width,Memo->Height);
Img->Canvas->CopyRect(rect,C,rect);
ReleaseDC(Memo->Handle,C->Handle);
C->Free();
ComponentImage = Img;
Greetings, Jacek.
Posted: Tue Jun 27, 2006 6:54 pm
by Sergey Tkachenko
TPoint ClientCoords = ctrl->ClientToParent(Point(0,0), RichViewEdit1);
TPoint DocCoords = RichViewEdit1->ClientToDocument(ClientCoords);
But it will not help you with printing, because a position on page is not a position on screen.
If you want to customize printing, process RVPrint->OnPrintComponent event. In this event, you create a bitmap with the control image, and RVPrint will print the bitmap at the proper position.
If you want a high quality printing, you can:
- create a lager bitmap in this event, it was scaled down to the proper size on printing, providing higher quality printing output;
or
- create your own TRichView item type for your controls, see Demos\Addins\ChartItem\ for an example.