[บทเรียน,B4XCustomView] การเพิ่มคุณสมบัติ BackgroundColor ให้แก่ปุ่มกด เป็น โปร่งใส

Theera

Expert
Licensed User
Longtime User
จากการทดลอง ปุ่มที่สร้างขึ้นที่มีรูปร่างไม่เป็นสี่เหลี่ยม มักแสดงส่วนเงาเป็นลักษณะสี่เหลี่ยมออกมาให้เห็น ซึ่งทำให้ได้รูปทรงของปุ่มกด ไม่สวยงาม
จึงจำเป็นต้องเพิ่มคุณสมบัติ BackgroundColor ให้แก่ปุ่มกด เป็น โปร่งใส

'The Code in B4XCustomView Class Module
B4X:
#DesignerProperty: Key: BackgroundColor, DisplayName: Background Color, FieldType: Color, DefaultValue: 0x0000000F

Sub Class_Globals
   
     '::::::
    Public  backgroundColor As Int
End Sub
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
    '::::::
    backgroundColor = xui.PaintOrColorToColor(Props.GetDefault("BackgroundColor", 0x0000000F))
    '::::::
End Sub

Public Sub SetBackgroundColor(color As Int)
    backgroundColor = color
    Draw
End Sub

'No Code for getBackgroundColor Module

Private Sub Draw
    cvs.ClearRect(cvs.TargetRect)
    
    ' Fill background
    cvs.DrawRect(cvs.TargetRect, backgroundColor, True, 0)

   ':::::::
End Sub
 
Top