สร้างปุ่ม
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 331   1
URL.หัวข้อ / URL
สร้างปุ่ม

ถามไว้ที่ http://www.utteraccess.com/forums/showflat.php?Cat=&Board=access_97&Number=156691&page=0&view=collapsed&sb=5&o=7&fpart=&vc=1&PHPSESSID= 
 
ผมเดาว่าเขาได้สร้างปุ่ม Command Button ขึ้นมาใน Form แล้ว โดยใช้คำสั่ง CreateControl แต่เขาต้องการที่จะเปลี่ยนชื่อของปุ่มนี้ พร้อมกับแทรกรูปภาพเข้าไปในปุ่มด้วย ผมเลยให้โค้ดเขาไปดังนี้ครับ 
 
Sub CreateCommandButton1() 
    Dim frm As Form 
    Dim ctlCmdButton As Control 
    Dim intLeft As Integer, intTop As Integer 
 
    ' Create new blank form. 
    Set frm = CreateForm 
    ' Set positioning values for a new control. 
    intLeft = 2 * 567 ' In Twips, 1 cm. = 567 twips 
    intTop = 3 * 567 
    ' Create a command butoon in detail section. 
    Set ctlCmdButton = CreateControl(frm.Name, acCommandButton, , "", "", _ 
        intLeft, intTop) 
    ' Attach a bitmap image as a linked type and rename the command button. 
    With ctlCmdButton 
        .Picture = "J:\star.bmp" 
        .PictureType = 1 
        .Name = "cmdNewCommandButton" 
    End With 
    ' Restore form. 
    DoCmd.Restore 
End Sub 
 
ลองนำโค้ดนี้ไปใส่ใน Module แล้วเปลี่ยนห้องที่เก็บรูปภาพที่เป็น Bitmap ให้ตรงกับเครื่องของท่าน ถ้าไม่มี ก็ให้ Rem บันทัดนี้ออกก็ได้ แล้วลอง Run ดูครับ 
 
*** Edited by Supap Chaiya *** 8/4/2546 11:04:36

1 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R01200
และถ้าต้องการใสโค้ดกับปุ่มนี้ด้วย เช่น Private Sub cmdNewCommandButton_Click() MsgBox "Hello World" End Sub จะทำอย่างไร นี่คือโค้ดที่ผมได้ปรับปรุงครับ Sub CreateCommandButton1() Dim frm As Form Dim ctlCmdButton As Control Dim intLeft As Integer, intTop As Integer Dim strMyCode As String Dim mdl As Module, strCmdName As String ' Create new blank form. Set frm = CreateForm ' Set positioning values for a new control. intLeft = 2 * 567 ' In Twips, 1 cm. = 567 twips intTop = 3 * 567 ' Create a command butoon in detail section. Set ctlCmdButton = CreateControl(frm.Name, acCommandButton, , "", "", _ intLeft, intTop) ' Attach a bitmap image as a linked type and rename the command button. strCmdName = "cmdNewCommandButton" With ctlCmdButton .Picture = "J:\star.bmp" .PictureType = 1 .Name = strCmdName End With ' Restore form. DoCmd.Restore ' Attach OnClick code to the button. Set mdl = Forms(0).Module strMyCode = "Private Sub " & strCmdName & "_Click()" _ & vbCrLf & vbTab & "MsgBox " & Chr(34) & "Hello World" & Chr(34) & vbCrLf & "End Sub" With mdl .InsertText strMyCode End With End Sub
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0460s