none
Visual Studio Extension question along with using extension methods. I am using the 2017 Community Edition. RRS feed

  • Question

  • Hi ALL,

    Firstly I was getting a little excited that Microsoft have FINALLY made it possible to create
    Visual Studio extensions with the free version too!! :-) :-D
    I am using the 2017 Community Edition.

    Anyway, I have always wished - intended that my code to change the SHAPE of a
    CONTROL or FORM to be used from an extension rather than being used in a DLL or separate MODULE code page.

    The code is in this article.>>
    https://social.technet.microsoft.com/wiki/contents/articles/19859.vb-net-how-to-make-an-oval-triangle-pentagon-hexagon-or-octagon-for-a-control-or-a-form.aspx?Sort=MostUseful&PageIndex=1

     I recently tried to create a Visual Studio VSIX project in the 2017 edition under MODULE
    having to add the following references

    Imports System
    Imports System.Collections.Generic
    Imports System.Drawing
    Imports System.Windows.Forms
    Imports Microsoft.VisualBasic.Conversion


    so the code ended up looking like this.>>

    Option Strict On
    Option Explicit On
    Option Infer Off
    
    Imports System
    Imports System.Collections.Generic
    Imports System.Drawing
    Imports System.Windows.Forms
    Imports Microsoft.VisualBasic.Conversion
    Imports System.Runtime.CompilerServices
    
    Module ShapedControls
    
        Public Const Pi As Double = Math.PI
        Public Const DegreesToRadians As Double = 180 / Pi
    
        Public Enum TriangleDirection
            Up
            Right
            Down
            Left
            TopRight
            BottomRight
            BottomLeft
            TopLeft
        End Enum
    
        <Extension()> Public Sub Shape(ByVal ctrl As Control, Optional ByVal NumberOfSides As Integer = 3, Optional ByVal OffsetAngleInDegrees As Double = 0)
    
            If NumberOfSides < 2 Then Throw New Exception("Number of sides can only be 2 or more.")
    
            Dim MyPath As New Drawing2D.GraphicsPath
            Dim MyAngle As Double = OffsetAngleInDegrees / DegreesToRadians
    
            If NumberOfSides = 2 Then
    
                Dim MyPoints() As Point
                Dim MyPointsList As New List(Of Point)
    
                If ctrl.Width = ctrl.Height Then
                    MyPath.AddEllipse(New Rectangle(0, 0, ctrl.Width, ctrl.Height))
                ElseIf ctrl.Width > ctrl.Height Then
                    MyPointsList.Add(New Point(0, ctrl.Height \ 2))
                    MyPointsList.Add(New Point(ctrl.Width \ 2, 0))
                    MyPointsList.Add(New Point(ctrl.Width, ctrl.Height \ 2))
                    MyPoints = MyPointsList.ToArray
                    MyPath.AddCurve(MyPoints)
                    MyPointsList.Clear()
    
                    MyPointsList.Add(New Point(ctrl.Width, ctrl.Height \ 2))
                    MyPointsList.Add(New Point(ctrl.Width \ 2, ctrl.Height))
                    MyPointsList.Add(New Point(0, ctrl.Height \ 2))
                    MyPoints = MyPointsList.ToArray
                    MyPath.AddCurve(MyPoints)
                    MyPointsList.Clear()
                ElseIf ctrl.Width < ctrl.Height Then
                    MyPointsList.Add(New Point(ctrl.Width \ 2, 0))
                    MyPointsList.Add(New Point(ctrl.Width, ctrl.Height \ 2))
                    MyPointsList.Add(New Point(ctrl.Width \ 2, ctrl.Height))
                    MyPoints = MyPointsList.ToArray
                    MyPath.AddCurve(MyPoints)
                    MyPointsList.Clear()
    
                    MyPointsList.Add(New Point(ctrl.Width \ 2, ctrl.Height))
                    MyPointsList.Add(New Point(0, ctrl.Height \ 2))
                    MyPointsList.Add(New Point(ctrl.Width \ 2, 0))
                    MyPoints = MyPointsList.ToArray
                    MyPath.AddCurve(MyPoints)
                    MyPointsList.Clear()
                End If
            End If
    
            Dim radius1 As Integer = ctrl.Height \ 2
            Dim radius2 As Integer = ctrl.Width \ 2
            Dim xInt, yInt As Integer
            Dim xDoub, yDoub As Double
    
            For angle As Double = MyAngle To ((2 * Pi) + MyAngle) Step ((2 * Pi) / NumberOfSides)
    
                xDoub = radius2 * Math.Cos(angle) + radius2
                yDoub = radius1 * Math.Sin(angle) + radius1
                xInt = CInt((Int(xDoub)))
                yInt = CInt(Int(yDoub))
                MyPath.AddLine(New Point(xInt, yInt), New Point(xInt, yInt))
    
            Next
    
            MyPath.CloseFigure()
            ctrl.Region = New Region(MyPath)
            MyPath.Dispose()
    
        End Sub
    
        <Extension()> Public Sub MakeTriangular(ByVal ctrl As Control, ByVal Triangle_Direction As TriangleDirection)
    
            Dim MyPath As New Drawing2D.GraphicsPath
    
            Select Case Triangle_Direction
                Case Is = TriangleDirection.Up
                    MyPath.AddLine(0, ctrl.Height, 0, ctrl.Height)
                    MyPath.AddLine(0, ctrl.Height, ctrl.Width \ 2, 0)
                    MyPath.AddLine(ctrl.Width \ 2, 0, ctrl.Width, ctrl.Height)
                Case TriangleDirection.Right
                    MyPath.AddLine(0, ctrl.Height, 0, 0)
                    MyPath.AddLine(0, 0, ctrl.Width, ctrl.Height \ 2)
    
                Case TriangleDirection.Down
                    MyPath.AddLine(0, 0, ctrl.Width, 0)
                    MyPath.AddLine(ctrl.Width, 0, ctrl.Width \ 2, ctrl.Height)
    
                Case TriangleDirection.Left
                    MyPath.AddLine(ctrl.Width, 0, ctrl.Width, ctrl.Height)
                    MyPath.AddLine(ctrl.Width, ctrl.Height, 0, ctrl.Height \ 2)
    
                Case TriangleDirection.TopRight
                    MyPath.AddLine(0, 0, ctrl.Width, 0)
                    MyPath.AddLine(ctrl.Width, 0, ctrl.Width, ctrl.Height)
    
                Case TriangleDirection.TopLeft
                    MyPath.AddLine(0, 0, ctrl.Width, 0)
                    MyPath.AddLine(ctrl.Width, 0, 0, ctrl.Height)
    
                Case TriangleDirection.BottomRight
                    MyPath.AddLine(ctrl.Width, 0, ctrl.Width, ctrl.Height)
                    MyPath.AddLine(ctrl.Width, ctrl.Height, 0, ctrl.Height)
    
                Case TriangleDirection.BottomLeft
                    MyPath.AddLine(0, 0, ctrl.Width, ctrl.Height)
                    MyPath.AddLine(ctrl.Width, ctrl.Height, 0, ctrl.Height)
    
            End Select
            MyPath.CloseFigure()
            ctrl.Region = New Region(MyPath)
    
        End Sub
    
    End Module

    Now then the code normally works like this. for example, which will show a FORM in the shape of a hexagon.>>

    Public Class Form1
    	Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            Me.Shape(6, 0)
    
        End Sub
    End Class

    When I build and add the extension for Visual Studio though the .Shape extension method does not appear to be available. Is there a step I am missing here please?



    P.S:    A big HELLO AGAIN to all forum members that may remember me from the past.
    P.P.S: I think my goals and ambitions in life have now changed from when I first tinkered with .Net back in 2003.

    Specs:
    4GB RAM on an HP ProBook 4530s
    892 GB SSD drive with 16GB of FREE space.
    Windows 10 Professional, 64 bit edition.
    Intel i7-2670QM 2.2GHz quad core processor ( 8 threads )


    Regards,

    profile for John Anthony Oliver at Stack Overflow, Q&A for professional and enthusiast programmers

    Click this link to see the NEW way of how to insert a picture into a forum post.

    Installing VB6 on Windows 7

    App Hub for Windows Phone & XBOX 360 developers.


    Save
    Save
    Save
    Save
    Save
    Wednesday, April 12, 2017 10:22 PM

All replies

  • Hi John.

    Nice to see you around again. I hope you are well. :)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Wednesday, April 12, 2017 10:49 PM
  • Hi John.

    Nice to see you around again. I hope you are well. :)


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Hi Frank,

    Yeah I'm not too bad considering I'm now on the downward slope towards 100 after passing 50.
    LOL!! I'll be 52 in August. :-/ LOL!! I'm still "managing" with my neuralgia, I'm on Pregablin now which takes the severe edge off the pain on most days. I certainly notice the difference if I try to stop taking the tablets. I soldier on....

     I hope you and all your Family and Friends are okay too. :-) :-D

    Best wishes from somewhere in the North East of England ( unless I'm in the Matrix ), LOL!!


    Regards,

    profile for John Anthony Oliver at Stack Overflow, Q&A for professional and enthusiast programmers

    Click this link to see the NEW way of how to insert a picture into a forum post.

    Installing VB6 on Windows 7

    App Hub for Windows Phone & XBOX 360 developers.


    Save
    Wednesday, April 12, 2017 11:27 PM
  • Hello, John,

    What I see Visual Studio IDE extensions are for things like enhanced IntelliSense, IDE code refactoring are some examples but not for housing language extension methods

    High level overview

    https://msdn.microsoft.com/en-us/library/bb166030.aspx

    Github Microsoft/VSSDK-Extensibility-Samples.

    Personally I have my common language extension methods in a team library with project specific extensions in their project.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, April 13, 2017 12:13 AM
  • Hi John,

    Since this forum is discussing and asking questions about the Visual Basic programming language, IDE, libraries, samples, and tools, And your issue is more related to Visual Studio Extension. I will move your issue to this forum for professional help. Link: https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vsx

    Thank you for participating in the forum activities.

    Best Regards,

    Cherry Bu



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 13, 2017 1:56 AM