Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2017-04-17
5
Medium Priority
?
111 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

650 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