This article describes different ways a DicomLabel object can be aligned inside a DicomViewer control using its properties in .NET and COM version of DicomObjects.

DicomObjects.NET

In DicomObjects.NET version, 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 CSharp code shows how to put a DicomLabel on the Right Top corner of a DicomImage, and a Label in the center of the Image.

   
 DicomLabel rightTop, center;
 rightTop = new DicomLabel();
 rightTop.LabelType = LabelType.Text;
 rightTop.Area = new RectangleF(0, 0, Viewer.CurrentImage.Size.Width, Viewer.CurrentImage.Size.Height);
 rightTop.Text = "rightTop";
 rightTop.StringFormat.Alignment = StringAlignment.Far;
 rightTop.StringFormat.LineAlignment = StringAlignment.Near;
 rightTop.ScaleMode = ScaleMode.Image;
 Viewer.CurrentImage.Labels.Add(rightTop);

 center = new DicomLabel();
 center.LabelType = LabelType.Text;
 center.Area = new RectangleF(0, 0, Viewer.CurrentImage.Size.Width, Viewer.CurrentImage.Size.Height);
 center.Text = "center";
 center.StringFormat.Alignment = StringAlignment.Center;
 center.StringFormat.LineAlignment = StringAlignment.Center;
 center.ScaleMode = ScaleMode.Image;
 Viewer.CurrentImage.Labels.Add(center);

DicomObjects.COM

     
 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.ScaleMode = doLabelScaleCell1000
 tl.Alignment = doAlignLeft
 tl.AutoSizeMode = doSizeModeAuto
 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.ScaleMode = doLabelScaleCell1000
 tr.Alignment = doAlignRight
 tr.AutoSizeMode = doSizeModeAuto
 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.ScaleMode = doLabelScaleCell1000
 bl.ShowTextBox = True
 bl.AutoSizeMode = doSizeModeAuto
 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.AutoSizeMode = doSizeModeAuto
 br.ScaleMode = doLabelScaleCell1000
 br.Alignment = doAlignBottomRight
 Viewer.CurrentImage.Labels.Add br