本文介绍了如何使用align vb打印文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮助我,我正在使用此代码在表单中打印文本框,它可以正常工作,但是对齐问题,因为每个文本框都有不同的对齐方式,所以我想在文本框对齐时打印文本对齐方式,例如如果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 SubTanks
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打印文本框
发布评论