controls position

General TRichView support forum. Please post your questions here
Post Reply
hdassler
Posts: 15
Joined: Fri Jun 09, 2006 8:16 am

controls position

Post 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))) )
hdassler
Posts: 15
Joined: Fri Jun 09, 2006 8:16 am

Post 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
Jacek Puczynski
Posts: 27
Joined: Tue Jun 20, 2006 7:34 pm
Location: Europe

Post by Jacek Puczynski »

Hi.
I think you could use function GetItemCoords in order to establish memo position relative to Canvas.

Greetings, Jacek.
hdassler
Posts: 15
Joined: Fri Jun 09, 2006 8:16 am

Post 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
Jacek Puczynski
Posts: 27
Joined: Tue Jun 20, 2006 7:34 pm
Location: Europe

Post 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();
hdassler
Posts: 15
Joined: Fri Jun 09, 2006 8:16 am

Post by hdassler »

the problem is, I'm not really a c++ developer but have to solve this
problem.
Image

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.
Jacek Puczynski
Posts: 27
Joined: Tue Jun 20, 2006 7:34 pm
Location: Europe

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17604
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Post Reply