以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]单元格描绘的内容怎样居中  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=119700)

--  作者:天一生水
--  发布时间:2018/5/30 14:50:00
--  [求助]单元格描绘的内容怎样居中

 DrawCell  代码:

 

If e.Col.Name = "邮寄状态" Then
    e.StartDraw()
    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("黑体",9)
    Dim br As object
    Dim msg As String
    If e.Row("邮寄") = True Then
        n = New Pen(Color.Blue,2)
        br = New SolidBrush(color.Blue)
        msg = "已邮寄"
    Else
        n = New Pen(Color.Red,2)
        br = New SolidBrush(color.red)
        msg = "未邮寄"
    End If
   
    e.Graphics.DrawRectangle(n,x,e.y + 2,w,h)
    e.Graphics.DrawString(msg,fnt,br,x + 10,e.y + 15)
    e.Text = ""
    e.EndDraw()
End If


图片点击可在新窗口打开查看此主题相关图片如下:image 2.png
图片点击可在新窗口打开查看

--  作者:有点甜
--  发布时间:2018/5/30 14:56:00
--  

    Dim sf As new StringFormat
    sf.Alignment = StringAlignment.Center
    sf.LineAlignment = StringAlignment.Center

    
    e.Graphics.DrawString(msg,fnt,br,  new Rectangle(e.x, e.y, e.width, e.height), sf)

[此贴子已经被作者于2018/5/30 14:56:19编辑过]