如何使用align vb.net打印文本框

编程入门 行业动态 更新时间:2024-10-24 01:53:25
本文介绍了如何使用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 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打印文本框

本文发布于:2023-11-03 20:33:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556019.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   文本框   vb   align   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!