Question Class Libraries and Enums

Phix

Member
Joined
Apr 9, 2010
Messages
15
Location
San Jose
Programming Experience
3-5
I'm a huge fan of creating centralized, reusable libraries for any project, be it flash, php, or whatever, so I'd like to make a lib for some common functions I do in VB, and the one I like using so far is centering the Form on the screen when it starts. Problem is, I'm not sure how to reference them (in code) just yet...

But here's my Logic
VB.NET:
Imports System.Drawing
Imports System.Windows.Forms

Namespace Common
    Public Class Location
        Shared ReadOnly Screen As Rectangle = My.Computer.Screen.WorkingArea
        Shared ReadOnly TOP_LEFT = New Point(0, 0)
        Shared ReadOnly TOP_RIGHT = New Point(0, Screen.Width)
        Shared ReadOnly BOTTOM_LEFT = New Point(0, Screen.Height)
        Shared ReadOnly BOTTOM_RIGHT = New Point(Screen.Width, Screen.Height)
        Shared ReadOnly SCREEN_CENTER = New Point(Screen.Width, Screen.Height)
    End Class
End Namespace

I know how to reference this in other projects, but I don't know exactly how to get it set up to how I want. I'd assume it would go something like this:

VB.NET:
Me.Location = Common.Location.TOP_LEFT

But I'm not sure exactly how to reference this all correctly with the namespaces, Public vs. Shared stuff, and the like. Also, how would I create an Enum (or something comparable) so when I go to put something in constValue the intellisense gives me only the ReadOnly's I've declared?
 
Heya Phix,

I have created a quick example of how I would go about achieving what you are trying to do, hopefully it will help you.
Its not a perfect solution for example you briefly see the form flash from one location to another, but its the principle of how you could do it. (FYI I created this in Visual Studio 2008)

Another way that you could do it (I haven't created an example for this one), is to create your own form which you extend to include an Enum and a property that deals with the positioning of the form, then on either Load or Show/ShowDialog you can have the form deal with the positioning of itself. This is probably the better solution for that particular example, but as you are thinking of creating a library of things that you regularly find yourself doing you might not bother with this.

I hope that has been helpful.

Satal :D
 

Attachments

  • WindowsApplication1.zip
    17.8 KB · Views: 18
Last edited by a moderator:
Back
Top