Mega Code Archive

 
Categories / Delphi / VCL
 

Implementing the vb twipsperpixel in delphi

Question: I need the equivalent of the VB TwipsPerPixel functions. How can implement the same functionality in Delphi? Answer: The following example demonstrates two functions (TwipsPerPixelX, and TwipsPerPixelY) that implement the same functionality in Delphi. Example: function TwipsPerPixelX(Canvas : TCanvas) : Extended; begin result := 1440 / GetDeviceCaps(Canvas.Handle, LOGPIXELSX); end; function TwipsPerPixelY(Canvas : TCanvas) : Extended; begin result := 1440 / GetDeviceCaps(Canvas.Handle, LOGPIXELSY); end; procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(FloatToStr(TwipsPerPixelX(Form1.Canvas))); ShowMessage(FloatToStr(TwipsPerPixelY(Form1.Canvas))); end;