Label Alignment

Contents

Label Alignment in DO.NET

In DicomObjects.NET RC1 and all later versions, Label alignment can be done using StringFormat property of the DicomLabel:

  • DicomLabel.StringFormat.Alignment.(near, center, far) ==> Horizontal Alignment
  • DicomLabel.StringFormat.LineAlignment.(near, center, far) ==> Vertical Alignment

Please NOTE Label Alignment is relative to the area available for the text.

The following VB.NET code shows how to put a DicomLabel on the Right Top corner of a DicomImage, and a Label in the center of the Image.

Dim rightTop, center As DicomObjects.DicomLabel

rightTop= New DicomObjects.DicomLabel
rightTop.LabelType = DicomObjects.Enums.LabelType.Text
rightTop.Area = New RectangleF(0, 0, DicomViewer1.CurrentImage.Size.Width, DicomViewer1.CurrentImage.Size.Height)
rightTop.Text = "rightTop"
rightTop.StringFormat.Alignment = StringAlignment.Far
rightTop.StringFormat.LineAlignment = StringAlignment.Near
rightTop.ScaleMode = DicomObjects.Enums.ScaleMode.Image
DicomViewer1.CurrentImage.Labels.Add(rightTop)

center = New DicomObjects.DicomLabel
center.LabelType = DicomObjects.Enums.LabelType.Text
center.Area = New RectangleF(0, 0, DicomViewer1.CurrentImage.Size.Width, DicomViewer1.CurrentImage.Size.Height)
center.Text = "center"
center.StringFormat.Alignment = StringAlignment.Center
center.StringFormat.LineAlignment = StringAlignment.Center
center.ScaleMode = DicomObjects.Enums.ScaleMode.Image
DicomViewer1.CurrentImage.Labels.Add(center)

For more information about differences between COM version and .NET version, check the _Conversion_Page

Label Alignment in DO.COM

Align with Cell

Sample VB6 code:

 Dim tl As New DicomLabel
 Dim tr As New DicomLabel
 Dim bl As New DicomLabel
 Dim br As New DicomLabel

 'TOP LEFT
 tl.LabelType = doLabelText
 tl.Text = "TOP" & vbCrLf & "LEFT"
 tl.FontSize = 16
 tl.ForeColour = vbRed
 tl.Left = 0
 tl.Top = 0
 tl.Width = 100
 tl.Height = 50
 tl.ScaleWithCell = True
 tl.Alignment = doAlignLeft
 tl.AutoSize = True
 tl.ShowTextBox = True
 Viewer.CurrentImage.Labels.Add tl

 'TOP RIGHT
 tr.LabelType = doLabelText
 tr.Text = "TOP" & vbCrLf & "RIGHT"
 tr.FontSize = 16
 tr.ForeColour = vbRed
 tr.Width = 100
 tr.Height = 50
 tr.Left = 1000 - tr.Width
 tr.Top = 0
 tr.ScaleWithCell = True
 tr.Alignment = doAlignRight
 tr.AutoSize = True
 tr.ShowTextBox = True
 Viewer.CurrentImage.Labels.Add tr

 'BOTTOM LEFT
 bl.LabelType = doLabelText
 bl.Text = "BOTTOM" & vbCrLf & "LEFT"
 bl.FontSize = 16
 bl.ForeColour = vbRed
 bl.Width = 100
 bl.Height = 50
 bl.Left = 0
 bl.Top = 1000 - bl.Height
 bl.ScaleWithCell = True
 bl.ShowTextBox = True
 bl.AutoSize = True
 bl.Alignment = doAlignBottomLeft
 Viewer.CurrentImage.Labels.Add bl

 'BOTTOM RIGHT
 br.LabelType = doLabelText
 br.Text = "BOTTOM" & vbCrLf & "RIGHT"
 br.FontSize = 16
 br.ForeColour = vbRed
 br.Width = 100
 br.Height = 50
 br.Left = 1000 - bl.Width
 br.Top = 1000 - bl.Height
 br.ShowTextBox = True
 br.AutoSize = True
 br.ScaleWithCell = True
 br.Alignment = doAlignBottomRight
 Viewer.CurrentImage.Labels.Add br

Labels will be aligned to the four corners of the Image cell, like this:

Align with Image

Sample VB6 code:

 Dim tl As New DicomLabel
 Dim tr As New DicomLabel
 Dim bl As New DicomLabel
 Dim br As New DicomLabel

 'TOP LEFT
 tl.LabelType = doLabelText
 tl.Text = "TOP" & vbCrLf & "LEFT"
 tl.FontSize = 12
 tl.ForeColour = vbRed
 tl.Left = 0
 tl.Top = 0
 tl.Width = 100
 tl.Height = 50
 tl.ScaleWithCell = False
 tl.ImageTied = True
 tl.Alignment = doAlignLeft
 tl.AutoSize = True
 tl.ShowTextBox = True
 Viewer.CurrentImage.Labels.Add tl

 'TOP RIGHT
 tr.LabelType = doLabelText
 tr.Text = "TOP" & vbCrLf & "RIGHT"
 tr.FontSize = 12
 tr.ForeColour = vbRed
 tr.Width = 100
 tr.Height = 50
 tr.Left = Viewer.CurrentImage.SizeX - tr.Width
 tr.Top = 0
 tr.ScaleWithCell = False
 tr.ImageTied = True
 tr.Alignment = doAlignRight
 tr.AutoSize = True
 tr.ShowTextBox = True
 Viewer.CurrentImage.Labels.Add tr

 'BOTTOM LEFT
 bl.LabelType = doLabelText
 bl.Text = "BOTTOM" & vbCrLf & "LEFT"
 bl.FontSize = 12
 bl.ForeColour = vbRed
 bl.Width = 100
 bl.Height = 50
 bl.Left = 0
 bl.Top = Viewer.CurrentImage.SizeY - bl.Height
 bl.ScaleWithCell = False
 bl..ImageTied = True
 bl.ShowTextBox = True
 bl.AutoSize = True
 bl.Alignment = doAlignBottomLeft
 Viewer.CurrentImage.Labels.Add bl

 'BOTTOM RIGHT
 br.LabelType = doLabelText
 br.Text = "BOTTOM" & vbCrLf & "RIGHT"
 br.FontSize = 12
 br.ForeColour = vbRed
 br.Width = 100
 br.Height = 50
 br.Left = Viewer.CurrentImage.SizeX - bl.Width
 br.Top = Viewer.CurrentImage.SizeY - bl.Height
 br.ShowTextBox = True
 br.AutoSize = True
 br.ScaleWithCell = False
 br.ImageTied = True
 br.Alignment = doAlignBottomRight
 Viewer.CurrentImage.Labels.Add br

Labels will be aligned to the four corners of the Image, like this:

Relevance: