以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 文字居中,不会了 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=140789) |
-- 作者:yifan3429 -- 发布时间:2019/9/14 8:20:00 -- 文字居中,不会了 需要增加文字居中控制代码 If e.Col.Name = "项目校对" Or e.Col.Name = "确认复核" Or e.Col.Name = "审核" Or e.Col.Name = "结账" Then \'If e.Col.Name = "审核" Or e.Col.Name = "核销" Then e.StartDraw() Dim msg As String Dim tl As Integer = e.Text.Length Select Case tl Case 2 msg = " " & e.Text & " " Case 3 msg = " " & e.Text & " " Case Else msg = e.Text End Select If msg = "" Then Return If tl <= 4 Then e.Col.Width = 70 Else e.Col.width = tl*15+1 End If Dim w As Integer = e.Width - 4 Dim h As Integer = e.Height - 4 Dim x As Integer = e.x + (e.Width - w)/2 Dim n As Pen Dim fnt As New Font("宋体",12,FontStyle.Bold) Dim br As Brush If e.Text.Contains("已") Then n = New Pen(Color.Green,2) br = New SolidBrush(color.ForestGreen) Else n = New Pen(Color.Red,2) br = New SolidBrush(color.red) End If e.Graphics.DrawRectangle(n,x,e.y + 2,w,h) e.Graphics.DrawString(msg,fnt,br,x + 1,e.y + 4) e.Text = "" e.EndDraw() End If |
-- 作者:有点蓝 -- 发布时间:2019/9/15 15:58:00 -- 这个有点麻烦,需要计算文字占用的宽度,试试 dim w2 as integer = e.Graphics.MeasureString(msg, fnt).width x = e.x + (e.Width - w2)/2 e.Graphics.DrawString(msg,fnt,br,x + 1,e.y + 4)
|