Create a button class for use in all vb.net apps

Ive looked at some of the tutorials on YT but missing something. Ive created 3 images for a button and created a new project and selected class library.

ive added the 3 images and they show under resources.

In the video tutorial the person added a new item to the project this item was a form, then after adding he deleted it and suggested that this was enough for the class to know it was a windows form control.

I get a lot of errors so not sure how to proceed now I am in visual studio 2015 using vb.

I didnt want any issues with copyright with regard to buttons yet didnt want standard toolbox buttons either so created my own images which of course I would like to import that in every windows app I make.
A shove in the right direction would be appreciated.
ex
my code thus far:
Imports System.Drawing
Public Class Class1
    Inherits Windows.Forms.Button
    Public Sub New()
        Me.Size = New Point(32, 32)
        Me.FlatStyle = Windows.Forms.FlatStyle.Flat
        Me.FlatAppearance.BorderSize = 0
        Me.FlatAppearance.BorderColor = System.Drawing.Color.Gray
        Me.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Transparent
        Me.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent
        Me.BackColor = System.Drawing.Color.Transparent
        Me.BackgroundImage = My.Resources.Btn1Normal
        Me.BackgroundImageLayout = Windows.Forms.ImageLayout.Stretch
        Me.Font = New System.Drawing.Font("Tahoma", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    End Sub

    Private Sub Backbutton_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        Me.BackgroundImage = My.Resources.Btn1MouseClick
    End Sub
    Private Sub Backbutton_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseEnter
        Me.BackgroundImage = My.Resources.Btn1MouseOn
    End Sub
    Private Sub Backbutton_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
        Me.BackgroundImage = My.Resources.Btn1Normal
    End Sub
    Private Sub Backbutton_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
        Me.BackgroundImage = My.Resources.Btn1MouseOn
    End Sub

End Class

Open in new window


ex2
PeterBaileyUkAsked:
Who is Participating?
 
it_saigeConnect With a Mentor DeveloperCommented:
Try changing your code file to this:
Imports System.Drawing
Imports System.Windows.Forms

Public Class Class1
    Inherits Button
    Public Sub New()
        Me.Size = New Point(32, 32)
        Me.FlatStyle = FlatStyle.Flat
        Me.FlatAppearance.BorderSize = 0
        Me.FlatAppearance.BorderColor = Color.Gray
        Me.FlatAppearance.MouseDownBackColor = Color.Transparent
        Me.FlatAppearance.MouseOverBackColor = Color.Transparent
        Me.BackColor = Color.Transparent
        Me.BackgroundImage = My.Resources.Btn1Normal
        Me.BackgroundImageLayout = ImageLayout.Stretch
        Me.Font = New Font("Tahoma", 9.0!, FontStyle.Regular, GraphicsUnit.Point, CType(0, Byte))
    End Sub

    Private Sub Backbutton_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        Me.BackgroundImage = My.Resources.Btn1MouseClick
    End Sub
    Private Sub Backbutton_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseEnter
        Me.BackgroundImage = My.Resources.Btn1MouseOn
    End Sub
    Private Sub Backbutton_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.MouseLeave
        Me.BackgroundImage = My.Resources.Btn1Normal
    End Sub
    Private Sub Backbutton_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
        Me.BackgroundImage = My.Resources.Btn1MouseOn
    End Sub
End Class

Open in new window


-saige-
0
 
it_saigeDeveloperCommented:
Looking at your code, I can't find any glaring mistakes.  You probably need to import System.Windows.Forms.  Other than that, let's start with the errors you are getting.

-saige-
0
 
PeterBaileyUkAuthor Commented:
Ive added that to the top above class:
Imports System.Windows.Forms

Open in new window


everything in sub New is underlined red the errors are below hopefully thatll point to something silly ive done

Severity	Code	Description	Project	File	Line	Suppression State
Error	BC30002	Type 'Windows.Forms.Button' is not defined.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	4	Active
Error	BC30590	Event 'MouseDown' cannot be found.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	18	Active
Error	BC30590	Event 'MouseEnter' cannot be found.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	21	Active
Error	BC30590	Event 'MouseLeave' cannot be found.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	24	Active
Error	BC30590	Event 'MouseUp' cannot be found.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	27	Active
Error	BC30456	'Size' is not a member of 'Class1'.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	6	Active
Error	BC30456	'FlatStyle' is not a member of 'Class1'.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	7	Active
Error	BC30456	'Forms' is not a member of 'Windows'.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	7	Active
Error	BC30456	'FlatAppearance' is not a member of 'Class1'.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	8	Active
Error	BC30456	'FlatAppearance' is not a member of 'Class1'.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	9	Active
Error	BC30456	'FlatAppearance' is not a member of 'Class1'.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	10	Active
Error	BC30456	'FlatAppearance' is not a member of 'Class1'.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	11	Active
Error	BC30456	'BackColor' is not a member of 'Class1'.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	12	Active
Error	BC30456	'BackgroundImage' is not a member of 'Class1'.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	13	Active
Error	BC30456	'BackgroundImageLayout' is not a member of 'Class1'.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	14	Active
Error	BC30456	'Forms' is not a member of 'Windows'.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	14	Active
Error	BC30456	'Font' is not a member of 'Class1'.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	15	Active
Error	BC30456	'BackgroundImage' is not a member of 'Class1'.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	19	Active
Error	BC30456	'BackgroundImage' is not a member of 'Class1'.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	22	Active
Error	BC30456	'BackgroundImage' is not a member of 'Class1'.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	25	Active
Error	BC30456	'BackgroundImage' is not a member of 'Class1'.	CButton	C:\Users\peter\Documents\Visual Studio 2015\Projects\CButton\CButton\Class1.vb	28	Active

Open in new window

0
 
PeterBaileyUkAuthor Commented:
that worked so does a normal save now create the .dll which I can then import into other projects?
0
 
PeterBaileyUkAuthor Commented:
thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.