CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Faltering Windows support
  • Internet Explorer 8 Click Clever Click Safe
  • Release Candidate 2 for ASP.NET MVC 2
  • Learn How to Create Dual Mode Windows Services

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual Basic Programming > Visual Basic .NET
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual Basic .NET Microsoft Visual Basic .NET and related questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 20th, 2009, 06:30 AM
    SB4 SB4 is offline
    Junior Member
     
    Join Date: Jun 2007
    Location: Q8
    Posts: 9
    SB4 is an unknown quantity at this point (<10)
    Create Custom Button using Class ?

    Hello CG members,



    I use this code to create the same Button in multiple Forms:

    Code:
    Dim btnClick As New Button
    btnClick.Location = New Point(106, 150)
    btnClick.Size = New Size(75, 23)
    btnClick.BackColor = Color.Brown
    btnClick.ForeColor = Color.White
    btnClick.Text = "Ok"


    I don't want to add the same code to all Forms. So i want to use Class to do the same work. How to do that ?



    Best Regards,
    SB4
    Reply With Quote
      #2    
    Old November 20th, 2009, 07:42 AM
    HanneSThEGreaT's Avatar
    HanneSThEGreaT HanneSThEGreaT is online now
    The Moody Mod
    Power Poster
     
    Join Date: Jul 2001
    Location: Vereeniging, South Africa
    Posts: 8,005
    HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+)
    Re: Create Custom Button using Class ?

    Create a new class ( Project, Add Class )

    Type this into that class :
    Code:
    Public Class ClsButton
        Inherits Button
        Public Sub New()
            '  Dim btnClick As New Button
            Me.Location = New Point(106, 150)
            Me.Size = New Size(75, 23)
            Me.BackColor = Color.Brown
            Me.ForeColor = Color.White
            Me.Text = "Ok"
        End Sub
    
    End Class
    Once that is done, and your project is saved, the ClsButton component will be available in your Toolbox during Design time, and you could just drag it from there onto every form.

    Have a look at the attachment
    Attached Files
    File Type: zip Button_Thingy.zip (68.6 KB, 11 views)
    __________________
    My Latest Articles :
    Changing Mouse Settings with VB.NET || Creating Your Own Encryption / Decryption Program Using VB.NET 2005 || Autorun Menu Creator in VB.NET || Creating Your Own Tetris Game With VB.NET Part 1
    Find All My Articles : Here

    FAQs :
    .NET FrameWork FAQs || Visual Basic.NET FAQs || C# FAQs

    Be The Change That You Want To See In The World - Michael Scofield, Prison Break; Season 1 Episode 1

    Read This Before You Post || Acceptable Use Policy
    Reply With Quote
      #3    
    Old November 20th, 2009, 08:12 AM
    SB4 SB4 is offline
    Junior Member
     
    Join Date: Jun 2007
    Location: Q8
    Posts: 9
    SB4 is an unknown quantity at this point (<10)
    Re: Create Custom Button using Class ?

    thanks HanneSThEGreaT


    I test your file but it seems don't work with me I'm using Visual Stdio 2008.

    I have question Why you type New after you define the sub Procedure ? the keyword Me refer to what ?


    Best Regards,
    SB4
    Reply With Quote
      #4    
    Old November 20th, 2009, 08:19 AM
    HanneSThEGreaT's Avatar
    HanneSThEGreaT HanneSThEGreaT is online now
    The Moody Mod
    Power Poster
     
    Join Date: Jul 2001
    Location: Vereeniging, South Africa
    Posts: 8,005
    HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+)
    Re: Create Custom Button using Class ?

    OK, in future you must please specify what version of VB you are using, as stated here :
    http://www.codeguru.com/forum/showthread.php?t=403073


    New, is used for the class' initialisation, where it is given default startup values.
    Me refers to the current class, in this case, clsButton
    __________________
    My Latest Articles :
    Changing Mouse Settings with VB.NET || Creating Your Own Encryption / Decryption Program Using VB.NET 2005 || Autorun Menu Creator in VB.NET || Creating Your Own Tetris Game With VB.NET Part 1
    Find All My Articles : Here

    FAQs :
    .NET FrameWork FAQs || Visual Basic.NET FAQs || C# FAQs

    Be The Change That You Want To See In The World - Michael Scofield, Prison Break; Season 1 Episode 1

    Read This Before You Post || Acceptable Use Policy
    Reply With Quote
      #5    
    Old November 20th, 2009, 09:05 AM
    SB4 SB4 is offline
    Junior Member
     
    Join Date: Jun 2007
    Location: Q8
    Posts: 9
    SB4 is an unknown quantity at this point (<10)
    Re: Create Custom Button using Class ?

    Ok, i'm using Visual Basic.NET 2008 Pro / .NET Framework 3.5 SP1 How to modify the code to work
    Reply With Quote
      #6    
    Old November 21st, 2009, 02:08 AM
    HanneSThEGreaT's Avatar
    HanneSThEGreaT HanneSThEGreaT is online now
    The Moody Mod
    Power Poster
     
    Join Date: Jul 2001
    Location: Vereeniging, South Africa
    Posts: 8,005
    HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+) HanneSThEGreaT has a reputation beyond repute (3000+)
    Re: Create Custom Button using Class ?

    I can't understand that this code is not presumably compatible with .NET 3.5. It is just a normal Class file, with code still compatible in all versions of .NET.
    Post your program ( in .zip format ) here, as an attachment, so that we can have a closer look.
    __________________
    My Latest Articles :
    Changing Mouse Settings with VB.NET || Creating Your Own Encryption / Decryption Program Using VB.NET 2005 || Autorun Menu Creator in VB.NET || Creating Your Own Tetris Game With VB.NET Part 1
    Find All My Articles : Here

    FAQs :
    .NET FrameWork FAQs || Visual Basic.NET FAQs || C# FAQs

    Be The Change That You Want To See In The World - Michael Scofield, Prison Break; Season 1 Episode 1

    Read This Before You Post || Acceptable Use Policy
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual Basic Programming > Visual Basic .NET


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 09:54 AM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.