PostImagePaint Event

Summary

Occurs after painting the Image and the FloaterImage. Any additional painting should be done in this event.

Syntax

C#
C++/CLI
C++
public event PaintEventHandler PostImagePaint 
public: 
event PaintEventHandler^ PostImagePaint 
public:  
   event PaintEventHandler^ PostImagePaint 

Event Data

The event handler receives an argument of type PaintEventArgs containing data related to this event. The following PaintEventArgs properties provide information specific to this event.

PropertyDescription
ClipRectangle Gets the rectangle in which to paint.
Graphics Gets the graphics used to paint.

Example

C#
using Leadtools.WinForms; 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Drawing; 
 
class MyForm2 : Form 
{ 
 
   class MyPanel : Panel 
   { 
      protected override void OnPaintBackground(PaintEventArgs pe) 
      { 
         // do nothing 
      } 
   } 
 
   RasterImageViewer viewer; 
   MyPanel panel; 
 
   public MyForm2(string title) 
   { 
      Text = title; 
      Size = new Size(750, 450); 
 
      // Create the raster viewer 
      viewer = new RasterImageViewer(); 
      viewer.DoubleBuffer = true; 
      viewer.Dock = DockStyle.Fill; 
 
      // Load an image into the viewer 
      RasterCodecs codecs = new RasterCodecs(); 
      viewer.Image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Sample1.cmp")); 
      codecs.Dispose(); 
 
      // Create the panel 
      panel = new MyPanel(); 
      panel.Parent = this; 
      panel.Width = 400; 
      panel.Height = 400; 
      panel.Dock = DockStyle.Right; 
      panel.BackColor = Color.Beige; 
      panel.BorderStyle = BorderStyle.Fixed3D; 
 
      Controls.Add(panel); 
      panel.BringToFront(); 
 
      Controls.Add(viewer); 
      viewer.BringToFront(); 
 
      panel.Paint += new PaintEventHandler(panel_Paint); 
      viewer.PostImagePaint += new PaintEventHandler(viewer_PostImagePaint); 
      viewer.RedirectImagePaint += new EventHandler(viewer_RedirectImagePaint); 
   } 
 
   void viewer_RedirectImagePaint(object sender, EventArgs e) 
   { 
      panel.Invalidate(); 
   } 
 
   void panel_Paint(object sender, PaintEventArgs e) 
   { 
      if (viewer.Image != null) 
      { 
         int dx = viewer.Image.Width / 2; 
         int dy = viewer.Image.Height / 2; 
         Rectangle dest = viewer.SourceRectangle; 
 
         // move center of image to origin 
         Matrix m1 = new Matrix(1, 0, 0, 1, -dx, -dy); 
 
         // mirror the image 
         Matrix m2 = new Matrix(-1, 0, 0, 1, 0, 0); 
         m1.Multiply(m2, MatrixOrder.Append); 
 
         // move back to original location 
         Matrix m3 = new Matrix(1, 0, 0, 1, dx, dy); 
         m1.Multiply(m3, MatrixOrder.Append); 
 
         // scale image to fit on panel 
         float scaleX = (float)panel.Width / (float)viewer.Image.Width; 
         float scaleY = (float)panel.Height / (float)viewer.Image.Height; 
         Matrix m4 = new Matrix(scaleX, 0, 0, scaleY, 0, 0); 
         m1.Multiply(m4, MatrixOrder.Append); 
 
         // display contents of RaserImageViewer on panel 
         viewer.RedirectPaint( 
            e.Graphics, 
            Rectangle.Empty, //_viewer.SourceRectangle, 
            Rectangle.Empty, 
            Rectangle.Empty, //e.ClipRectangle,  
            m1); 
      } 
   } 
 
   private void viewer_PostImagePaint(object sender, PaintEventArgs e) 
   { 
      Graphics graphics = e.Graphics; 
      GraphicsState graphicsState = graphics.Save(); 
 
      Font font = new Font("Arial", 16); 
      e.Graphics.DrawString("This text stays with the window", font, Brushes.Yellow, new PointF(100, 100)); 
 
      graphics.MultiplyTransform(viewer.Transform); 
      e.Graphics.DrawString("This text stays with the image.", font, Brushes.White, new PointF(100, 200)); 
 
      graphics.Restore(graphicsState); 
      graphics.Flush(); 
   } 
} 
 
public void RasterImageViewer_RedirectPaint(string title) 
{ 
   MyForm2 form = new MyForm2(title); 
   form.ShowDialog(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 

Requirements

Target Platforms

See Also

Reference

RasterImageViewer Class

RasterImageViewer Members

Help Version 22.0.2023.1.24
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.WinForms Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.