?
Solved

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

Posted on 2017-04-17
5
Medium Priority
?
82 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 34

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 34

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 free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

777 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