jonathana jonathana - 2 months ago 7
Vb.net Question

is there a way to divide groups of fields into "sub structures" inside a class

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.

Answer

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
Comments