Page 1 of 1

ต้องการส่ง parameter ที่เป็น textbox ไปกับ subroutine ต้องปรับโค้ดอย่างไรครับ

Posted: Fri Apr 07, 2023 6:07 am
by 10idlnw
ผมใช้โค้ดประมาณนี้ครับ

Code: Select all

Private Sub SetIfToTextbox(textbox As TextBox, text As String)
    If textbox.Text = text Then
        textbox.Text = ""
    End If
End Sub
แล้วก็เอาไปใช้กับ event textbox ประมาณนี้

Code: Select all


Private Sub txbCarbrand_GotFocus(sender As Object, e As EventArgs) Handles txbCarbrand.GotFocus
    SetIfToTextbox(txbCarbrand, "กรอกยี่ห้อรถตรงนี้")
End Sub

Private Sub txbCarno_GotFocus(sender As Object, e As EventArgs) Handles txbCarno.GotFocus
    SetPlaceholderText(txbCarno, "ใส่เลขทะเบียนตรงนี้")
End Sub
แต่มันฟ้อง error ว่า Value of type 'VisualStyleElement.TextBox' cannot be converted to 'String'. ผมต้องปรับโค้ดอย่างไรครับ

Re: ต้องการส่ง parameter ที่เป็น textbox ไปกับ subroutine ต้องปรับโค้ดอย่างไรครับ

Posted: Fri Apr 07, 2023 6:26 am
by 10idlnw
ผมแก้ได้แล้วครับ เปลี่ยนจาก as textbox เป็น as control