Visual Studio扩展问题以及使用扩展方法。我正在使用2017社区版。 [英] Visual Studio Extension question along with using extension methods. I am using the 2017 Community Edition.

查看:81
本文介绍了Visual Studio扩展问题以及使用扩展方法。我正在使用2017社区版。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


首先,我有点兴奋,微软已经
FINALLY
使用免费版本创建

Visual Studio扩展成为可能!! :-): - D

我正在使用 2017社区版


无论如何,我一直希望 - 我希望我的代码能够更改从一个扩展中使用而不是在DLL或单独的MODULE中使用的
CONTROL或FORM的SHAPE代码页。


代码在本文中。>>
$



点击此链接可查看如何将图片插入论坛帖子的新方式。




在Windows 7上安装VB6




适用于Windows Phone的App Hub &安培; XBOX 360开发人员。





保存

保存

保存

保存

Save

解决方案

嗨约翰。


很高兴再次见到你。我希望你一切都好。 :)


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,


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

解决方案

Hi John.

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


这篇关于Visual Studio扩展问题以及使用扩展方法。我正在使用2017社区版。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆