如何使用align vb.net打印文本框 [英] how to print textboxs with align vb.net

查看:157
本文介绍了如何使用align vb.net打印文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我,我正在使用此代码在表单中打印文本框,它可以正常工作,但是对齐问题,因为每个文本框都有不同的对齐方式,所以我想在文本框对齐时打印文本对齐方式,例如如果textboxt.textalign = right,则文本的打印也正确;或者,如果textboxalign.textalign = left,则文本的打印为左

代码是

Please i need your help , I am using this code to print textboxs in the form and it works fine but the problem with alignment because every textbox have different align so i want to print the text align as the textboxs align , such as if the textboxt.textalign = right the print of text is right too or if textboxalign.textalign = left the print of text is left

The code is

Private Sub document_PrintPage(ByVal sender _
       As System.Object, ByVal e As PrintPageEventArgs)

        Dim fontObject As Font ' variable to store font
        ' store a control's x- and y-coordinates
        Dim yPosition As Single
        Dim xPosition As Single
        ' represent left margin of page 
        Dim leftMargin As Single = 0
        ' represent top margin of page 
        Dim topMargin As Single = 0
        ' store a control's text
        Dim controlText As String = Nothing
        ' iterate over the controls on the Form,
        ' printing the text displayed in each control
        For Each controlObject As Control In Me.Controls
            ' do not print Buttons 
            If Not (TypeOf controlObject Is Button) Then
                controlText = controlObject.Text
                fontObject = controlObject.Font ' default font

                ' set string positions relative to page margins
                xPosition = leftMargin + _
               controlObject.Location.X

                yPosition = topMargin + _
                   controlObject.Location.Y

                ' draw text in graphics object
                
                    Using sf As New StringFormat
                        Dim rect As New Rectangle(xPosition, yPosition, controlObject.Width, controlObject.Height)

                        e.Graphics.DrawString(controlText, fontObject, Brushes.Black, rect, sf)

                    End Using
                End Using

            End If
        Next controlObject

    End Sub 



Tanks



Tanks

推荐答案

一个更好的解决方案是使用对齐的字体,例如Consolas.大多数字体的宽度不是恒定的.
A better solution would be to use a font that aligns such as Consolas. Most fonts are not constant widths.


这篇关于如何使用align vb.net打印文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆