打印时按需要自动缩放文本尺寸且强制换行
来源:互联网 发布:细说php微盘 编辑:程序博客网 时间:2024/06/05 19:01
Dim mark As Single
Dim g As Graphics = e.Graphics
Dim str As String
Dim i As Integer
Dim temp() As String
Dim myfix As Drawing2D.Matrix = New Drawing2D.Matrix
Dim size As SizeF
Dim length As Single
str = ttbBuildName.Text.TrimStart("、") '所有文本
size = g.MeasureString(str, myfont3)
length = size.Width '所有文本在myfont3状态下的长度(像素)
If length > 4082 Then '4082:供打印的文本框的长度(像素)
mark = 4082 / length
Else
mark = 1
End If
myfix.Scale(mark, 1) '按比例压缩宽度
g.Transform = myfix
Dim j As Integer = 0
Dim from As Integer = 0
Dim strtemp As String = " "
'第一行
Do While (g.MeasureString(strtemp, myfont3).Width < 302 * (1 / mark) And 302 * (1 / mark) - g.MeasureString(strtemp, myfont3).Width >= g.MeasureString(str.Substring(from + j, 1), myfont3).Width)
j = j + 1
strtemp = str.Substring(from, j)
If (j + from) = str.Length Then Exit Do
Loop
from = from + j
g.DrawString(strtemp, myfont3, Brushes.Black, New RectangleF((x1 + 679) * (1 / mark), y1 + 80, length, 30), formatl)
j = 0
'后9行
If (j + from) <= str.Length - 1 Then
For i = 1 To 9
strtemp = " "
Do While (g.MeasureString(strtemp, myfont3).Width < 420 * (1 / mark) And 420 * (1 / mark) - g.MeasureString(strtemp, myfont3).Width >= g.MeasureString(str.Substring(from + j, 1), myfont3).Width)
j = j + 1
strtemp = str.Substring(from, j)
If (j + from) = str.Length Then Exit Do
Loop
from = from + j
g.DrawString(strtemp, myfont3, Brushes.Black, New RectangleF((x1 + 561) * (1 / mark), y1 + 130 + 51 * (i - 1), length, 30), formatl)
j = 0
If (j + from) = str.Length Then Exit For
Next
End If
myfix.Scale(1 / mark, 1) '恢复原始比例(1:1)
g.Transform = myfix
Dim g As Graphics = e.Graphics
Dim str As String
Dim i As Integer
Dim temp() As String
Dim myfix As Drawing2D.Matrix = New Drawing2D.Matrix
Dim size As SizeF
Dim length As Single
str = ttbBuildName.Text.TrimStart("、") '所有文本
size = g.MeasureString(str, myfont3)
length = size.Width '所有文本在myfont3状态下的长度(像素)
If length > 4082 Then '4082:供打印的文本框的长度(像素)
mark = 4082 / length
Else
mark = 1
End If
myfix.Scale(mark, 1) '按比例压缩宽度
g.Transform = myfix
Dim j As Integer = 0
Dim from As Integer = 0
Dim strtemp As String = " "
'第一行
Do While (g.MeasureString(strtemp, myfont3).Width < 302 * (1 / mark) And 302 * (1 / mark) - g.MeasureString(strtemp, myfont3).Width >= g.MeasureString(str.Substring(from + j, 1), myfont3).Width)
j = j + 1
strtemp = str.Substring(from, j)
If (j + from) = str.Length Then Exit Do
Loop
from = from + j
g.DrawString(strtemp, myfont3, Brushes.Black, New RectangleF((x1 + 679) * (1 / mark), y1 + 80, length, 30), formatl)
j = 0
'后9行
If (j + from) <= str.Length - 1 Then
For i = 1 To 9
strtemp = " "
Do While (g.MeasureString(strtemp, myfont3).Width < 420 * (1 / mark) And 420 * (1 / mark) - g.MeasureString(strtemp, myfont3).Width >= g.MeasureString(str.Substring(from + j, 1), myfont3).Width)
j = j + 1
strtemp = str.Substring(from, j)
If (j + from) = str.Length Then Exit Do
Loop
from = from + j
g.DrawString(strtemp, myfont3, Brushes.Black, New RectangleF((x1 + 561) * (1 / mark), y1 + 130 + 51 * (i - 1), length, 30), formatl)
j = 0
If (j + from) = str.Length Then Exit For
Next
End If
myfix.Scale(1 / mark, 1) '恢复原始比例(1:1)
g.Transform = myfix
- 打印时按需要自动缩放文本尺寸且强制换行
- 强制文本自动换行
- 强制文本换行
- 强制不换行,自动换行
- div强制、自动换行
- [cnblogs镜像]页面定制CSS代码初探(一):页面变宽 文本自动换行 图片按比缩放
- css实现强制不换行/自动换行/强制换行
- css实现强制不换行/自动换行/强制换行
- css实现强制不换行/自动换行/强制换行
- css实现强制不换行/自动换行/强制换行
- css实现强制不换行/自动换行/强制换行
- css实现强制不换行/自动换行/强制换行
- css实现强制不换行/自动换行/强制换行
- css实现强制不换行/自动换行/强制换行
- css实现强制不换行/自动换行/强制换行
- css实现强制不换行/自动换行/强制换行
- css实现强制不换行/自动换行/强制换行
- css实现强制不换行/自动换行/强制换行
- C++ STL之list入门实例
- windows"新建连接向导"大阅兵----第4集:建立直接电缆连接
- 斯蒂夫·乔布斯的讲演
- C#中8位BMP转8位JPG出问题
- DSP C语言基础要点
- 打印时按需要自动缩放文本尺寸且强制换行
- XML快速入门
- 电脑的140个终极技巧之21-40
- ORA 02436 sysdate oracle
- 文本分页(待修改)
- OSPod.Forum 先睹为快
- 趣谈MySQL
- 智力题
- C# 设计模式之生成器模式