Shrink to fit ย่อข้อความให้ขนาดพอดีกับ Text box

เริ่มโดย sama, 24 ก.ค 18 , 18:15:50

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

sama

รบกวนสอบถามครับ พอดีผมทำรายงานแล้วข้อความมันยาวล้น Text box ถ้าต้องการ Format ย่อข้อความให้ขนาดพอดีกับ Text box เหมือนคำสั่ง Shrink to fit ใน Excel สามารถทำได้หรือเปล่าครับ
  •  

ปิ่นณรงค์

ที่ตัวรายงาน ส่วนของ Detail  ตรง Event On Print ใส่โค้ดนี้เข้าไปครับ
Private Sub Detail_Print(Cancel As Integer, PrintCount As Integer)
Dim ctl As Control, strText As Variant, strName As String
    Me.ScaleMode = 1
    For Each ctl In Me.Detail.Controls
        If ctl.ControlType = acTextBox Then
       
        strName = ctl.Name
            If Nz(ctl.Tag, "") = "" Then
                ctl.Tag = ctl.FontSize
            End If
            ctl.FontSize = ctl.Tag
            Me.FontSize = ctl.FontSize
            strText = ctl.Value
           If Len(strText) > 0 Then
            Do Until TextWidth(strText) < ctl.Width
                ctl.FontSize = ctl.FontSize - 1
                Me.FontSize = ctl.FontSize
            Loop
            Do Until TextHeight(strText) < ctl.Height - (ctl.Height * 0.26)
                ctl.FontSize = ctl.FontSize - 1
                Me.FontSize = ctl.FontSize
            Loop
        End If
        End If
       
    Next ctl
End Sub


ผลที่ได้
:love: :grin:
  •  
    โพสต์นี้ได้รับคำขอบคุณจาก: kitisak

sama

  •  

sama

เจอแล้วครับแต่มันขึ้น Error แบบนี้ครับ

  •  

ปิ่นณรงค์

ลองกดจากตัวอย่าง สามารถใช้งานได้ปกติไหมครับ

เพิ่ม โค้ดตรงส่วน Detail ของรายงานตรง On Print
:love: :grin:
  •  

sama

  •  

sama

  •  
    โพสต์นี้ได้รับคำขอบคุณจาก: Psong UN

ปิ่นณรงค์

อ้างถึงจาก: sama ใน 25 ก.ค 18 , 08:55:58

ตั้งค่า ขนาดฟ้อนของ Textbox ไว้ก่อนเอาทีกำลังดีกับ textbox
ถ้ายังไม่ได้ ลองส่งตัวอย่างมาผมดูให้
:love: :grin:
  •  

sama

  •  

sama

แนบเป็นไฟล์ zip มาแล้วครับ
  •  

sama

ได้แล้วครับ น่าจะเป็นเรื่องของการปรับ front ขอบคุณมากครับ
  •