微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

打印 TableLayoutPanel、标签属性不适用于 Drawstring

如何解决打印 TableLayoutPanel、标签属性不适用于 Drawstring

我一直在尝试使用 PrintDocument 打印 TableLayoutPanel。 但是当我使用 DrawtoBitmap 时,TableLayoutPanel 是模糊的,搜索后我发现 Drawstring 是要走的路。 当我使用以下代码标签添加到 TableLayoutPanel 时:

TableLayoutPanel.Controls.Add(New Label() With {.Text = "This is a very very long string that needs to be cut off at some point",.AutoSize = False,.Width = 100},1 )

但是当我使用以下代码打印时

Dim sf = New StringFormat()
For Each ctrl As Control In TableLayoutPanel.Controls
sf.Alignment = If(TableLayoutPanel.GetColumn(ctrl) < 2,Stringalignment.Near,Stringalignment.Far)
e.Graphics.DrawString(ctrl.Text,ctrl.Font,Brushes.Black,Panel.PointToClient(TableLayoutPanel.PointToScreen(ctrl.Bounds.Location)),sf)
Next

为什么 DrawString 会忽略我设置的标签属性,例如 Autosize = False en Width? 在设计器中一切正常,但 DrawString 把一切都搞砸了。

我只想打印带有标签的 TableLayoutPanel。 我在这里做错了什么? 感谢您的时间!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。