LEADTOOLS Medical (Leadtools.MedicalViewer assembly)
LEAD Technologies, Inc

CustomPaint Event

Example 





Optional delegate method for additional processing.
Syntax
'Declaration
 
Public Event CustomPaint As EventHandler(Of MedicalViewerPaintEventArgs)
'Usage
 
Dim instance As MedicalViewerCell
Dim handler As EventHandler(Of MedicalViewerPaintEventArgs)
 
AddHandler instance.CustomPaint, handler
add_CustomPaint(function(sender, e))
remove_CustomPaint(function(sender, e))

Event Data

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

PropertyDescription
CellIndex Gets or sets the value that indicates the index of the cell that will be painted. This value is only valid if the cell is add to the MedicalViewer.
ClipRectangle (Inherited from System.Windows.Forms.PaintEventArgs)Gets the rectangle in which to paint.
Graphics (Inherited from System.Windows.Forms.PaintEventArgs)Gets the graphics used to paint.
SubCellIndex Gets or sets the value that indicates the index of the sub-cell that will be painted.
Example
 
Public Sub MedicalViewerEventsExample()
            Dim form As MainForm3 = New MainForm3()
            form.ShowDialog()
        End Sub
#End If
        ' MainForm1 will be the owner of the medical viewer control.
        Private Class MainForm3 : Inherits Form
            Private _medicalViewer As MedicalViewer
            Private _mouseDown As Boolean

            Private Sub _medicalViewer_UserActionMouseMove(ByVal sender As Object, ByVal e As MedicalViewerMouseEventArgs)
                ' Increase the gamma of the image as the user drags the mouse.
                If (e.ActionID = 101) AndAlso _mouseDown Then
                    CType(sender, MedicalViewerCell).Image.PaintGamma += 1
                    CType(sender, MedicalViewerCell).Invalidate()
                End If
            End Sub

            Private Sub _medicalViewer_UserActionMouseUp(ByVal sender As Object, ByVal e As MedicalViewerMouseEventArgs)
                _mouseDown = False
            End Sub

            Private Sub _medicalViewer_UserActionMouseDown(ByVal sender As Object, ByVal e As MedicalViewerMouseEventArgs)
                _mouseDown = True
            End Sub

            Private Sub _medicalViewer_UserActionKeyDown(ByVal sender As Object, ByVal e As MedicalViewerKeyEventArgs)
                If (CType(sender, MedicalViewerCell)).Image.PaintGamma > 1 Then
                    CType(sender, MedicalViewerCell).Image.PaintGamma -= 1
                End If
            End Sub

            Private Sub _medicalViewer_UserActionKeyUp(ByVal sender As Object, ByVal e As MedicalViewerKeyEventArgs)
                CType(sender, MedicalViewerCell).Invalidate()
            End Sub

            Private Sub _medicalViewer_CustomPaint(ByVal sender As Object, ByVal e As MedicalViewerPaintEventArgs)
                ' draw red ellipse around the first frame of the first cell.
                If (e.CellIndex = 0) AndAlso (e.SubCellIndex = 0) Then
                    e.Graphics.DrawEllipse(Pens.Red, e.ClipRectangle)
                End If
            End Sub

            Private Sub _medicalViewer_UserTag(ByVal sender As Object, ByVal e As MedicalViewerUserTagEventArgs)
                ' draw a red string at the bottom right edge of the first cell.
                If e.CellIndex = 0 Then
                    e.Graphics.DrawString("Owner Draw", New Font(FontFamily.GenericSerif, 15), Brushes.Red, New PointF(e.ClipRectangle.Left, e.ClipRectangle.Top))
                End If
            End Sub

            Public Sub New()
                Dim _codecs As RasterCodecs = New RasterCodecs()
                Dim _image As RasterImage

                ' Create the medical viewer and adjust some properties.
                _medicalViewer = New MedicalViewer()
                _medicalViewer.Rows = 1
                _medicalViewer.Columns = 2
                _medicalViewer.Location = New Point(0, 0)
                _medicalViewer.Size = New Size(Me.ClientRectangle.Right, Me.ClientRectangle.Bottom)

                ' Load an image and then add it to the control.
                _image = _codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "image3.dcm"))
                Dim cell As MedicalViewerCell = New MedicalViewerCell(_image, True)
                cell.AddAction(CType(101, MedicalViewerActionType))
                cell.SetAction(CType(101, MedicalViewerActionType), MedicalViewerMouseButtons.Left, MedicalViewerActionFlags.Active)

                cell.SetActionKeys(CType(101, MedicalViewerActionType), New MedicalViewerKeys(Keys.Up, Keys.Down, Keys.Left, Keys.Right, MedicalViewerModifiers.None))

                AddHandler cell.UserTag, AddressOf _medicalViewer_UserTag
                AddHandler cell.CustomPaint, AddressOf _medicalViewer_CustomPaint
                AddHandler cell.UserActionMouseDown, AddressOf _medicalViewer_UserActionMouseDown
                AddHandler cell.UserActionMouseUp, AddressOf _medicalViewer_UserActionMouseUp
                AddHandler cell.UserActionMouseMove, AddressOf _medicalViewer_UserActionMouseMove
                AddHandler cell.UserActionKeyUp, AddressOf _medicalViewer_UserActionKeyUp
                AddHandler cell.UserActionKeyDown, AddressOf _medicalViewer_UserActionKeyDown

                _medicalViewer.Cells.Add(cell)

                ' adjust some properties of the cell and add some tags.
                cell.SetTag(2, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.UserData, "EX. ID 230-36-5448")
                cell.SetTag(4, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.Frame)
                cell.SetTag(6, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.Scale)
                cell.SetTag(2, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.WindowLevelData)
                cell.SetTag(1, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.FieldOfView)
                cell.SetTag(1, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, "Good, Guy")
                cell.SetTag(2, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, "PID 125-98-445")
                cell.SetTag(3, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, "DOB 08/02/1929")
                cell.SetTag(5, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, "03/16/1999")
                cell.SetTag(0, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.RulerUnit)
                cell.SetTag(0, MedicalViewerTagAlignment.BottomRight, MedicalViewerTagType.OwnerDraw)

                Controls.Add(_medicalViewer)
                _medicalViewer.Dock = DockStyle.Fill
            End Sub
        End Class

   Public NotInheritable Class LEAD_VARS
      Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
   End Class
public void MedicalViewerEventsExample()
      {
         MainForm3 form = new MainForm3();
         form.ShowDialog();
      }
#endif
      // MainForm1 will be the owner of the medical viewer control.
      class MainForm3 : Form
      {
         private MedicalViewer _medicalViewer;
         private bool _mouseDown;

         void _medicalViewer_UserActionMouseMove(object sender, MedicalViewerMouseEventArgs e)
         {
            // Increase the gamma of the image as the user drags the mouse.
            if ((e.ActionID == 101) && _mouseDown)
            {
               ((MedicalViewerCell)sender).Image.PaintGamma += 1;
               ((MedicalViewerCell)sender).Invalidate();
            }
         }

         void _medicalViewer_UserActionMouseUp(object sender, MedicalViewerMouseEventArgs e)
         {
            _mouseDown = false;
         }

         void _medicalViewer_UserActionMouseDown(object sender, MedicalViewerMouseEventArgs e)
         {
            _mouseDown = true;
         }

         void _medicalViewer_UserActionKeyDown(object sender, MedicalViewerKeyEventArgs e)
         {
            if (((MedicalViewerCell)sender).Image.PaintGamma > 1)
               ((MedicalViewerCell)sender).Image.PaintGamma -= 1;
         }

         void _medicalViewer_UserActionKeyUp(object sender, MedicalViewerKeyEventArgs e)
         {
            ((MedicalViewerCell)sender).Invalidate();
         }

         void _medicalViewer_CustomPaint(object sender, MedicalViewerPaintEventArgs e)
         {
            // draw red ellipse around the first frame of the first cell.
            if ((e.CellIndex == 0) && (e.SubCellIndex == 0))
               e.Graphics.DrawEllipse(Pens.Red, e.ClipRectangle);
         }

         void _medicalViewer_UserTag(object sender, MedicalViewerUserTagEventArgs e)
         {
            // draw red string at the bottom right edge of the first cell.
            if (e.CellIndex == 0)
               e.Graphics.DrawString("Owner Draw", new Font(FontFamily.GenericSerif, 15), Brushes.Red, new PointF(e.ClipRectangle.Left, e.ClipRectangle.Top));
         }

         public MainForm3()
         {
            RasterCodecs _codecs = new RasterCodecs();
            RasterImage _image;

            // Create the medical viewer and adjust some properties.
            _medicalViewer = new MedicalViewer();
            _medicalViewer.Rows = 1;
            _medicalViewer.Columns = 2;
            _medicalViewer.Location = new Point(0, 0);
            _medicalViewer.Size = new Size(this.ClientRectangle.Right, this.ClientRectangle.Bottom);

            // Load an image and then add it to the control.
            _image = _codecs.Load(Path.Combine(LEAD_VARS.ImagesDir,"image3.dcm"));
            MedicalViewerCell cell = new MedicalViewerCell(_image, true);
            cell.AddAction((MedicalViewerActionType)101);
            cell.SetAction((MedicalViewerActionType)101, MedicalViewerMouseButtons.Left, MedicalViewerActionFlags.Active);

            cell.SetActionKeys((MedicalViewerActionType)101, new MedicalViewerKeys(Keys.Up, Keys.Down, Keys.Left, Keys.Right, MedicalViewerModifiers.None));

            cell.UserTag += new EventHandler<MedicalViewerUserTagEventArgs>(_medicalViewer_UserTag);
            cell.CustomPaint += new EventHandler<MedicalViewerPaintEventArgs>(_medicalViewer_CustomPaint);
            cell.UserActionMouseDown += new EventHandler<MedicalViewerMouseEventArgs>(_medicalViewer_UserActionMouseDown);
            cell.UserActionMouseUp += new EventHandler<MedicalViewerMouseEventArgs>(_medicalViewer_UserActionMouseUp);
            cell.UserActionMouseMove += new EventHandler<MedicalViewerMouseEventArgs>(_medicalViewer_UserActionMouseMove);
            cell.UserActionKeyUp += new EventHandler<MedicalViewerKeyEventArgs>(_medicalViewer_UserActionKeyUp);
            cell.UserActionKeyDown += new EventHandler<MedicalViewerKeyEventArgs>(_medicalViewer_UserActionKeyDown);

            _medicalViewer.Cells.Add(cell);

            // adjust some properties of the cell and add some tags.
            cell.SetTag(2, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.UserData, "EX. ID 230-36-5448");
            cell.SetTag(4, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.Frame);
            cell.SetTag(6, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.Scale);
            cell.SetTag(2, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.WindowLevelData);
            cell.SetTag(1, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.FieldOfView);
            cell.SetTag(1, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, "Good, Guy");
            cell.SetTag(2, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, "PID 125-98-445");
            cell.SetTag(3, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, "DOB 08/02/1929");
            cell.SetTag(5, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, "03/16/1999");
            cell.SetTag(0, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.RulerUnit);
            cell.SetTag(0, MedicalViewerTagAlignment.BottomRight, MedicalViewerTagType.OwnerDraw);

            Controls.Add(_medicalViewer);
            _medicalViewer.Dock = DockStyle.Fill;
         }
      }

   static class LEAD_VARS
   {
      public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
   }
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

MedicalViewerCell Class
MedicalViewerCell Members

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.MedicalViewer requires a Medical Imaging license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features