VB visual studio class library

กระทู้คำถาม
สวัสดีครับ
ผมต้องการเขียน code ให้มัน return ค่า RGB ของหน้าจอ desktop ที่ตำแหน่ง mose ชี้อยู่ จากการไปค้นหา code ในเน็ตก็มีคนเขาเขียนไว้เป็น VB.net
ก็เลยเอา code เขามาทดลอง run ดู

  
Public Class Form1

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Dim bmp As New Bitmap(1, 1)
        Using g As Graphics = Graphics.FromImage(bmp)
            g.CopyFromScreen(Windows.Forms.Cursor.Position, New Point(0, 0), New Size(1, 1))
        End Using
        Dim pixel As Drawing.Color = bmp.GetPixel(0, 0)
        Dim RGB As String
        RGB = bmp.GetPixel(0, 0).ToString
        TextBox1.Text = RGB
        Dim p As New Point
        p.X = (Me.Width / 2) - (Label1.Width / 2)
        p.Y = Label1.Top
        Label1.Location = p '
        PictureBox1.BackColor = pixel '
        Me.Invalidate() '

    End Sub

End Class



แต่ผมต้องการเอาไปใช้กับ labview และผมก็ไม่เคยเขียน VB มาก่อนเลย. ผมเลยลองเขียนเป็น class library


Imports System.Drawing

Public Class RGB_color
    Dim bmp As New Bitmap(1, 1)
    Public Function test() As String
        Using g As Graphics = Graphics.FromImage(bmp)
            g.CopyFromScreen(Windows.Forms.Cursor.Position, New Point(0, 0), New Size(1, 1))
        End Using
        Dim pixel As Drawing.Color = bmp.GetPixel(0, 0)
        Dim RGB As String
        RGB = bmp.GetPixel(0, 0).ToString
        Return RGB
    End Function

End Class

Code ผมตอนที่เป็น class library มันจะ error ตรง g.CopyFromScreen(Windows.Forms.Cursor.Position, New Point(0, 0), New Size(1, 1))
Severity    Code    Description    Project    File    Line    Suppression State
Error    BC30451    'Windows' is not declared. It may be inaccessible due to its protection level.    ClassLibrary1    C:\Users\Appplay\source\repos\Solution3\ClassLibrary1\Class1.vb    7    Active

ช่วยชี้แนะด้วยครับเพิ่งเขียน Vb.net ครั้งแรกจริงๆ
แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่