Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2017-04-17
5
Medium Priority
?
160 Views
Last Modified: 2017-04-17
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
0
Comment
Question by:PeterBaileyUk
  • 3
  • 2
5 Comments
 
LVL 35

Expert Comment

by:it_saige
ID: 42095494
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
 

Author Comment

by:PeterBaileyUk
ID: 42095509
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
 
LVL 35

Accepted Solution

by:
it_saige earned 2000 total points
ID: 42095519
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
 

Author Comment

by:PeterBaileyUk
ID: 42095525
that worked so does a normal save now create the .dll which I can then import into other projects?
0
 

Author Closing Comment

by:PeterBaileyUk
ID: 42095537
thank you!
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month15 days, 5 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question