2

I am adding a business dashboard module to my project management software.
the dashboard will be used Infrequently by a small group of users - because of that i would like to avoid using static/shared classes or every execution that will consume hardware resources.

my wish is that all dashboard colors will be initialized from fields inside instance Class: DashBoardGUI that will be Disposed / garbage collected in the end.

the goal of that is to provide the programmer the ability to change shared colors easily and also for the user to customize preferred colors and save them on database.

class is very basic, no constructors, no large or resource-intensive objects just fields with type of Color.

the problem is that there are a lot of fields (~35) so it is hard for me to recognize all fields when i am developing the GUI.

what i mean is that if i want to to call a field from DashBoardGUI instance its very confisung and looks like that:

Public Class CreateGUI
Inherits System.Windows.Forms.Panel

    Private ColorKit As New DashBoardGUI

    Protected Overridable Sub Init()
        RightFlowLayOutPannel.BackColor = ColorKit.someConfusingFieldName1
        LeftFlowLayOutPannel.BackColor = ColorKit.someConfusingFieldName2
        RightClockGraph.BackColor = ColorKit.someConfusingFieldName3
        LeftGroupBox.ForeColor = ColorKit.someConfusingFieldName4
    End Sub
End Class

My wish is to get the effect like using a namespace, "." sign that will reduce options and lead me to the requested fields:

Public Class CreateGUI
Inherits System.Windows.Forms.Panel

    Private ColorKit As New DashBoardGUI

    Protected Overridable Sub Init()
        RightFlowLayOutPannel.BackColor = ColorKit.FlPannels.FieldName
        LeftFlowLayOutPannel.BackColor = ColorKit.FlPannels.FieldName
        RightClockGraph.BackColor = ColorKit.Clocks.FieldName
        LeftGroupBox.ForeColor = ColorKit.GroupBoxes.FieldName
    End Sub
End Class

I have tried create nested Structures and nested Classes inside DashBoardGUI class, but the compiler is not letting me use them if they are declared as static/shared. if i declare them as shared its also impossible :

shared is not valid on a structure deceleration (i understand why).

so my question is: how can i get the effect that is similar as using a namespace with multiple shared classes - calling fields like: xxx.yyy.myfield when i am using instance class?
maybe somebody have a completely different approach and can advice me?
maybe my approach of saving resources (explained in top) is wrong and i should create namespace with static/shared classes?

thank you.

Jonathan Applebaum
  • 5,738
  • 4
  • 33
  • 52
  • You could make Flannels, Clocks, GroupBoxes inherit from DashBoardGUI. and put that in ColorKit Namespace. – Esselans Sep 15 '16 at 20:00
  • that is not a bad idea but i am already inheriting System.Windows.Forms.Panel - i will add it to my example in the question – Jonathan Applebaum Sep 15 '16 at 20:06
  • mmm you could try do a usercontrol based on Panel and add your own ColorKit property... I'm just thinking out loud – Esselans Sep 15 '16 at 20:24
  • its a creative idea but maybe there is more simple solution (?) – Jonathan Applebaum Sep 15 '16 at 20:29
  • there is no way to do nested Enum... best 'looking' way is nested classes http://stackoverflow.com/a/5992839/439371 It's simple but not effective I guess – Esselans Sep 15 '16 at 20:37
  • @Jaxedin nested classes wont work (i wrote it in the question), one answer in the link shows multiple classes and i would like to avoid declaring multiple instances and its also will cause more confusion and the answer that is marked in the link refers to `Type` its VBA i think.. – Jonathan Applebaum Sep 15 '16 at 20:47

2 Answers2

2

I didn't read the question, but maybe something like:

Class A
    Class B
        Public myfield%
    End Class
    Public yyy As New B
End Class

sample use:

Dim xxx As New A
xxx.yyy.myfield = 123
Slai
  • 22,144
  • 5
  • 45
  • 53
  • very nice! that is the answer! interestingly you need to expose B in that manner: `Public yyy As New B` – Jonathan Applebaum Sep 15 '16 at 21:03
  • @jonathana that's just short for `Public yyy As B = New B`. It can also be `Public yyy As B` and then `yyy = New B` before accessing `yyy` – Slai Sep 15 '16 at 22:04
0

You could group the fields you want in classes as displayed in

Define String ENUM in VB.Net

e.g.

Class FlPanels

    Private Key As String

    Public Shared ReadOnly confusingField1 As FlPanels = New FlPanels("confusingField1")
    Public Shared ReadOnly confusingField2 As FlPanels = New FlPanels("confusingField2")

    Private Sub New(key As String)
        Me.Key = key
    End Sub

    Public Function FieldName() As String
        Return Me.Key
    End Function
End Class

and use it like this:

FlPanels.confusingField1.FieldName
Community
  • 1
  • 1
GeorgeT
  • 484
  • 3
  • 5
  • tnx for the answer but shared properties can not be garbage collected: http://stackoverflow.com/questions/6600093/do-static-members-ever-get-garbage-collected. and i would like to consume minimum resources. – Jonathan Applebaum Sep 15 '16 at 20:19