have the handles .click in another .vb

vextout

New member
Joined
Oct 4, 2008
Messages
3
Programming Experience
1-3
Hey,

I am wondering if this is possible or i guesst best practice.

I have my main tab control with 3 tabs with each tab having another tab control inside (frmMain.vb)
tabA has 11 inner tabs (so to speak)
tabB has 6 inner tabs
tabC has 4 inner tabs.

Each tab as a few controls with each pretty much requiring some type of coding, i was wondering instead of having around 50+ sub routines in frmMainm that I can create 21 class (.vb files - one for each inner tab), no gui, just a class and link the a few "handles *.click" routine to each of the seperate vb file.

It seems it would be cleaner coding. I tried using inherits on my new .vb file (ex: cmdExport.vb) with

VB.NET:
Public Class toolsExport
    Inherits myProject.frmMain

    Protected Overloads Sub cmdExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExport.Click
        MessageBox.Show("testing 1 2 3")
    End Sub
End Class

In my frmMain, I have no routine there. When i test this, clicking of the cmdExport does nothing

Is there another way to practice cleaner code / even more object oriented using event driven methods?

Thanks
 
Declare the class Partial and use same class name as your form class name.
VB.NET:
Partial Public Class frmMain

    Private Sub Buttons_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click
        Dim b As Button = CType(sender, Button)
        MsgBox(b.Name & " clicked")
    End Sub

End Class
 
Nice that worked - thanks

Regarding performance for this, I have I have 20 "Partial Public Class frmMain", will that effect the application performance significantly in any way. I tried two and it seems fine
 
Creating additional classes will use more resources but it may be negligible.

If you are doing this for the sole purpose of easier reading of code, one option would be to define regions within your form.

VB.NET:
[COLOR="Blue"]#Region[/COLOR] " [COLOR="Red"]tabA [/COLOR]"

[COLOR="blue"]#Region[/COLOR] " [COLOR="red"]tabA - InnerTab1 [/COLOR]"

    [COLOR="teal"]'tabA Inner tab1 events here[/COLOR]

[COLOR="blue"]#End Region[/COLOR]

[COLOR="blue"]#Region [/COLOR]" [COLOR="red"]tabA - InnerTab2 [/COLOR]"

   [COLOR="Teal"] 'tabA Inner tab2 events here[/COLOR]

[COLOR="blue"]#End Region

#End Region[/COLOR]
 
Thanks for the reply Tom

I am aware of the Region code, but the classes somehow make more sense to me for structure and ease of use. (thats just me I guess) - especially when debugging
 
Thanks for the reply Tom

I am aware of the Region code, but the classes somehow make more sense to me for structure and ease of use. (thats just me I guess) - especially when debugging

Agreed :)

Again the classes will use some resources but may be negligible.

The mention of regions was just an additional option that could be used.
 
Back
Top