博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
VB.NET 开发ColorPicker例子
阅读量:6201 次
发布时间:2019-06-21

本文共 30679 字,大约阅读时间需要 102 分钟。

这个colorPicker是继承control来写的。如果大家在写时候可以继承control 或usercontrol来写。

难度并不是很大,只要耐心一点就可认写出来。

用vb.net 写的,代码如下:

view plaincopy to clipboardprint?

Imports System.Drawing  
 
Imports System.Drawing.Drawing2D  
 
Imports System.Drawing.Imaging  
 
Imports System.Collections  
 
Imports System.ComponentModel  
 
Imports System.Collections.Generic  
 
Public Class ColorControl  
 
 
 
    Dim bit As New Bitmap(200, 230)  
 
    Dim isDraw As Boolean = False 
 
    Dim index As Integer = 0  
 
    Dim g As Graphics = Graphics.FromImage(bit)  
 
    Dim _NowColor As Color = Color.Transparent '现在颜色  
 
    Dim _CurrentColor As Color = Color.Transparent '当前颜前  
 
 
 
    '输出颜色  
 
    Public Event OutputColorEvent(ByVal NColor As Color, ByVal CColor As Color)  
 
 
 
    '触发事件  
 
    Sub OutcolorHander(ByVal nColor As Color, ByVal CColor As Color)  
 
        RaiseEvent OutputColorEvent(nColor, CColor)  
 
    End Sub 
 
 
 
    '颜色表  
 
    Dim ColorList() As Integer = {&HFF003366, &HFF336699, &HFF3366CC, &HFF003399, &HFF000099, &HFF0000CC, &HFF000066, _  
 
&HFF006666, &HFF006699, &HFF0099CC, &HFF0066CC, &HFF0033CC, &HFF0000FF, &HFF3333FF, &HFF333399, _  
 
&HFF008080, &HFF009999, &HFF33CCCC, &HFF00CCFF, &HFF0099FF, &HFF0066FF, &HFF3366FF, &HFF3333CC, &HFF666699, _  
 
&HFF339966, &HFF00CC99, &HFF00FFCC, &HFF00FFFF, &HFF33CCFF, &HFF3399FF, &HFF6699FF, &HFF6666FF, &HFF6600FF, &HFF6600CC, _  
 
&HFF339933, &HFF00CC66, &HFF00FF99, &HFF66FFCC, &HFF66FFFF, &HFF66CCFF, &HFF9999FF, &HFF9999FF, &HFF9966FF, &HFF9933FF, &HFF9900FF, _  
 
&HFF006600, &HFF00CC00, &HFF00FF00, &HFF66FF99, &HFF99FFCC, &HFFCCFFFF, &HFFCCECFF, &HFFCCCCFF, &HFFCC99FF, &HFFCC66FF, &HFFCC00FF, &HFF9900CC, _  
 
&HFF003300, &HFF008000, &HFF33CC33, &HFF66FF66, &HFF99FF99, &HFFCCFFCC, &HFFFFFFFF, &HFFFFCCFF, &HFFFF99FF, &HFFFF66FF, &HFFFF00FF, &HFFCC00CC, &HFF660066, _  
 
&HFF336600, &HFF009900, &HFF66FF33, &HFF99FF66, &HFFCCFF99, &HFFFFFFCC, &HFFFFCCCC, &HFFFF99CC, &HFFFF66CC, &HFFFF33CC, &HFFCC0099, &HFF800080, _  
 
&HFF333300, &HFF669900, &HFF99FF33, &HFFCCFF66, &HFFFFFF99, &HFFFFCC99, &HFFFF9999, &HFFFF6699, &HFFFF3399, &HFFCC3399, &HFF800080, _  
 
&HFF666633, &HFF99CC00, &HFFCCFF33, &HFFFFFF66, &HFFFFCC66, &HFFFF9966, &HFFFF7C80, &HFFFF0066, &HFFD60093, &HFF993366, _  
 
&HFF808000, &HFFCCCC00, &HFFFFFF00, &HFFFFCC00, &HFFFF9933, &HFFFF6600, &HFFFF5050, &HFFCC0066, &HFF660033, _  
 
&HFF996633, &HFFCC9900, &HFFFF9900, &HFFCC6600, &HFFFF3300, &HFFFF0000, &HFFCC0000, &HFF990033, _  
 
&HFF663300, &HFF996600, &HFFCC3300, &HFF993300, &HFF990000, &HFF800000, &HFFA50021, _  
 
&HFFFFFFFF, _  
 
&HFFF8F8F8, &HFFDDDDDD, &HFFB2B2B2, &HFF808080, &HFF5F5F5F, &HFF333333, &HFF1C1C1C, &HFF080808, _  
 
&HFFEAEAEA, &HFFC0C0C0, &HFF969696, &HFF777777, &HFF4D4D4D, &HFF292929, &HFF111111, _  
 
&HFF000000}  
 
 
 
    Sub New()  
 
        ' This call is required by the Windows Form Designer.  
 
        InitializeComponent()  
 
        ' Add any initialization after the InitializeComponent() call.  
 
        SetStyle(ControlStyles.AllPaintingInWmPaint, True)  
 
        SetStyle(ControlStyles.StandardDoubleClick, True)  
 
        SetStyle(ControlStyles.ResizeRedraw, True)  
 
        SetStyle(ControlStyles.UserPaint, True)  
 
        SetStyle(ControlStyles.OptimizedDoubleBuffer, True)  
 
        g.SmoothingMode = SmoothingMode.HighQuality  
 
    End Sub 
 
 
 
    <Description("现在颜色")> _  
 
    <Browsable(True)> _  
 
    Public Property NowColor() As Color  
 
        Get 
 
            Return _NowColor  
 
        End Get 
 
        Set(ByVal value As Color)  
 
            _NowColor = value  
 
        End Set 
 
    End Property 
 
 
 
    <Description("现在颜色")> _  
 
    <Browsable(True)> _  
 
    Public Property CurrentColor() As Color  
 
        Get 
 
            Return _CurrentColor  
 
        End Get 
 
        Set(ByVal value As Color)  
 
            _CurrentColor = value  
 
        End Set 
 
    End Property 
 
 
 
 
 
    ''' <summary>  
 
    '''绘制六角形上方   
 
    ''' </summary>  
 
    ''' <param name="gridSize">绘制六角形的长宽</param>  
 
    ''' <param name="mapSize">绘制个数</param>  
 
    ''' <param name="e">绘制对象</param>  
 
    ''' <remarks></remarks>  
 
    Public Sub BulidHexes(ByVal gridSize As Size, ByVal mapSize As Size, ByVal e As PaintEventArgs)  
 
        If isDraw = True Then 
 
            e.Graphics.DrawImage(bit, 0, 0)  
 
            Exit Sub 
 
        End If 
 
        Dim lindes As List(Of PointF) = Nothing 
 
        '六角格的水平半径各垂直半径  
 
        Dim wRad As Single = gridSize.Width / 2  
 
        Dim HRad As Single = gridSize.Height / 2  
 
 
 
        '六角格的水平直线,垂直线  
 
        Dim WLine As Single = Math.Sqrt(Math.Pow(wRad, 2) - Math.Pow(wRad / 2, 2))  
 
        Dim hLine As Single = Math.Sqrt(Math.Pow(HRad, 2) - Math.Pow(HRad / 2, 2))  
 
        '进行蜂窝式切合所必要的位偏移量  
 
        Dim wSpce As Single = (wRad - WLine) * 2  
 
        Dim hspce As Single = (HRad - hLine) * 2  
 
        '六角格的中心点  
 
        Dim cx As Single 
 
        Dim cy As Single 
 
        Dim isCenter As Boolean = False 
 
        Dim result As GraphicsPath  
 
        For y As Integer = 0 To mapSize.Height - 1  
 
            If isCenter = False Then 
 
                mapSize.Width += 1  
 
            Else 
 
                mapSize.Width -= 1  
 
            End If 
 
 
 
            If y = 6 Then 
 
                isCenter = True 
 
            End If 
 
            For x As Integer = 0 To mapSize.Width - 1  
 
                '计当前六角格的中心点  
 
                cx = (gridSize.Width * (x + 1) - wRad) + 100  
 
                cy = (gridSize.Height * (y + 1) - HRad)  
 
                cx = cx - wSpce * x  
 
                cy = cy - hspce * y * 2  
 
 
 
                If isCenter = False Then 
 
                    cx = cx - WLine * mapSize.Width  
 
                Else 
 
                    cx = cx - WLine * mapSize.Width  
 
                End If 
 
 
 
                '保存六角格的六个角的位置  
 
                lindes = New List(Of PointF)(6)  
 
                '北  
 
                Dim start As New PointF(cx, cy - HRad)  
 
                lindes.Add(start)  
 
                '东北  
 
                lindes.Add(New PointF(cx + WLine, cy - HRad / 2))  
 
 
 
                '东南  
 
                lindes.Add(New PointF(cx + WLine, cy + HRad / 2))  
 
 
 
                '南  
 
                lindes.Add(New PointF(cx, cy + HRad))  
 
 
 
                '西南  
 
                lindes.Add(New Point(cx - WLine, cy + HRad / 2))  
 
 
 
                '西北  
 
                lindes.Add(New Point(cx - WLine, cy - HRad / 2))  
 
 
 
                '回到起点:北  
 
                lindes.Add(start)  
 
                result = New GraphicsPath()  
 
                result.AddLines(lindes.ToArray())  
 
                result.CloseFigure()  
 
                Dim solidB As SolidBrush  
 
                solidB = New SolidBrush(Color.FromArgb(ColorList(index)))  
 
                index += 1  
 
                g.FillPath(solidB, result)  
 
            Next 
 
        Next 
 
 
 
 
 
        '=======================  
 
        '下左  
 
        wRad = 31 / 2  
 
        HRad = 32 / 2  
 
        '六角格的水平直线,垂直线  
 
        WLine = Math.Sqrt(Math.Pow(wRad, 2) - Math.Pow(wRad / 2, 2))  
 
        hLine = Math.Sqrt(Math.Pow(HRad, 2) - Math.Pow(HRad / 2, 2))  
 
        '进行蜂窝式切合所必要的位偏移量  
 
        wSpce = (wRad - WLine) * 2  
 
        hspce = (HRad - hLine) * 2  
 
      
 
            '计当前六角格的中心点  
 
        cx = 32 - wRad + 10  
 
        cy = 32 - HRad + 190  
 
        cx = cx - wSpce  
 
        cy = cy - hspce * 2  
 
            '保存六角格的六个角的位置  
 
            lindes = New List(Of PointF)(6)  
 
        '北  
 
        Dim START1 As New PointF(cx, cy - HRad)  
 
        lindes.Add(START1)  
 
            '东北  
 
            lindes.Add(New PointF(cx + WLine, cy - HRad / 2))  
 
 
 
            '东南  
 
            lindes.Add(New PointF(cx + WLine, cy + HRad / 2))  
 
 
 
            '南  
 
            lindes.Add(New PointF(cx, cy + HRad))  
 
 
 
            '西南  
 
            lindes.Add(New Point(cx - WLine, cy + HRad / 2))  
 
 
 
            '西北  
 
            lindes.Add(New Point(cx - WLine, cy - HRad / 2))  
 
 
 
            '回到起点:北  
 
        lindes.Add(START1)  
 
            result = New GraphicsPath()  
 
            result.AddLines(lindes.ToArray())  
 
            result.CloseFigure()  
 
        Dim solidX As SolidBrush  
 
        solidX = New SolidBrush(Color.FromArgb(ColorList(index)))  
 
        index += 1  
 
        g.FillPath(solidX, result)  
 
 
 
 
 
        '================  
 
        '下中  
 
        wRad = gridSize.Width / 2  
 
        HRad = gridSize.Height / 2  
 
        '六角格的水平直线,垂直线  
 
        WLine = Math.Sqrt(Math.Pow(wRad, 2) - Math.Pow(wRad / 2, 2))  
 
        hLine = Math.Sqrt(Math.Pow(HRad, 2) - Math.Pow(HRad / 2, 2))  
 
        '进行蜂窝式切合所必要的位偏移量  
 
        wSpce = (wRad - WLine) * 2  
 
        hspce = (HRad - hLine) * 2  
 
 
 
        Dim len As Integer = 7  
 
        For y As Integer = 0 To 1  
 
            If y = 1 Then 
 
                len = 6  
 
            End If 
 
            For x As Integer = 0 To len  
 
                '计当前六角格的中心点  
 
                cx = (gridSize.Width * (x + 1) - wRad) + 45  
 
                cy = (gridSize.Height * (y + 1) - HRad) + 180  
 
                cx = cx - wSpce * x  
 
                cy = cy - hspce * y * 2  
 
                If y = 1 Then 
 
                    cx = cx + WLine  
 
                End If 
 
                '保存六角格的六个角的位置  
 
                lindes = New List(Of PointF)(6)  
 
                '北  
 
                Dim start As New PointF(cx, cy - HRad)  
 
                lindes.Add(start)  
 
                '东北  
 
                lindes.Add(New PointF(cx + WLine, cy - HRad / 2))  
 
 
 
                '东南  
 
                lindes.Add(New PointF(cx + WLine, cy + HRad / 2))  
 
 
 
                '南  
 
                lindes.Add(New PointF(cx, cy + HRad))  
 
 
 
                '西南  
  
                lindes.Add(New Point(cx - WLine, cy + HRad / 2))  
 
 
 
                '西北  
 
                lindes.Add(New Point(cx - WLine, cy - HRad / 2))  
 
 
 
                '回到起点:北  
 
                lindes.Add(start)  
 
                result = New GraphicsPath()  
 
                result.AddLines(lindes.ToArray())  
 
                Dim solidY As SolidBrush  
 
                solidY = New SolidBrush(Color.FromArgb(ColorList(index)))  
 
                index += 1  
 
                g.FillPath(solidY, result)  
 
            Next 
 
        Next 
 
 
 
 
 
        '==============  
 
        '下右  
 
        wRad = 31 / 2  
 
        HRad = 32 / 2  
 
        '六角格的水平直线,垂直线  
 
        WLine = Math.Sqrt(Math.Pow(wRad, 2) - Math.Pow(wRad / 2, 2))  
 
        hLine = Math.Sqrt(Math.Pow(HRad, 2) - Math.Pow(HRad / 2, 2))  
 
        '进行蜂窝式切合所必要的位偏移量  
 
        wSpce = (wRad - WLine) * 2  
 
        hspce = (HRad - hLine) * 2  
 
 
 
        '计当前六角格的中心点  
 
        cx = 32 - wRad + 165  
 
        cy = 32 - HRad + 190  
 
        cx = cx - wSpce  
 
        cy = cy - hspce * 2  
 
        '保存六角格的六个角的位置  
 
        lindes = New List(Of PointF)(6)  
 
        '北  
 
        Dim START2 As New PointF(cx, cy - HRad)  
 
        lindes.Add(START2)  
 
        '东北  
 
        lindes.Add(New PointF(cx + WLine, cy - HRad / 2))  
 
 
 
        '东南  
 
        lindes.Add(New PointF(cx + WLine, cy + HRad / 2))  
 
 
 
        '南  
 
        lindes.Add(New PointF(cx, cy + HRad))  
 
 
 
        '西南  
 
        lindes.Add(New Point(cx - WLine, cy + HRad / 2))  
 
 
 
        '西北  
 
        lindes.Add(New Point(cx - WLine, cy - HRad / 2))  
 
 
 
        '回到起点:北  
 
        lindes.Add(START2)  
 
        result = New GraphicsPath()  
 
 
 
        result.AddLines(lindes.ToArray())  
 
        result.CloseFigure()  
 
        Dim solidE As SolidBrush  
 
 
 
        solidE = New SolidBrush(Color.Black)  
 
        g.FillPath(solidE, result)  
 
        e.Graphics.DrawImage(bit, 0, 0)  
 
        isDraw = True 
 
 
 
    End Sub 
 
 
 
 
 
    Dim _PenColor As Color = Color.White  
 
    Dim _penSize As Single = 2  
 
    <Description("移动外边六角形的颜色")> _  
 
    <Browsable(True)> _  
 
     Public Property PenColor() As Color  
 
        Get 
 
            Return _PenColor  
 
        End Get 
 
        Set(ByVal value As Color)  
 
            _PenColor = value  
 
        End Set 
 
    End Property 
 
 
 
    <Description("画笔的大小")> _  
 
    Public Property PenSize() As Single 
 
        Get 
 
            Return _penSize  
 
        End Get 
 
        Set(ByVal value As Single)  
 
            _penSize = value  
 
        End Set 
 
    End Property 
 
 
 
 
 
 
 
 
 
 
 
 
 
    ''' <summary>  
 
    ''' 重绘方法  
 
    ''' </summary>  
 
    ''' <param name="e"></param>  
 
    ''' <remarks></remarks>  
 
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)  
 
        MyBase.OnPaint(e)  
 
        BulidHexes(New Size(16, 17), New Size(6, 13), e)  
 
        If ISContent = True Then 
 
            Dim pen As New Pen(PenColor, PenSize)  
 
            Dim GContent As Graphics = e.Graphics  
 
            GContent.SmoothingMode = SmoothingMode.AntiAlias  
 
            GContent.DrawPolygon(pen, lindes.ToArray())  
 
            NowColor = Color.FromArgb(ColorList(index))  
 
            OutcolorHander(NowColor, CurrentColor)  
 
 
 
        End If 
 
    End Sub 
 
 
 
    Dim MovePoint As PointF  
 
    Dim ISContent As Boolean = False 
 
    Dim lindes As List(Of PointF) = Nothing 
 
    ''' <summary>  
 
    ''' 鼠标的移动  
 
    ''' </summary>  
 
    ''' <param name="e"></param>  
 
    ''' <remarks></remarks>  
 
    Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)  
 
        MyBase.OnMouseMove(e)  
 
        If e.Button = Windows.Forms.MouseButtons.Left Then 
 
            MovePoint.X = e.X  
 
            MovePoint.Y = e.Y  
 
            PointInContent(MovePoint)  
 
        End If 
 
    End Sub 
 
    ''' <summary>  
 
    ''' 鼠标的单击  
 
    ''' </summary>  
 
    ''' <param name="e"></param>  
 
    ''' <remarks></remarks>  
 
    Protected Overrides Sub OnMouseClick(ByVal e As System.Windows.Forms.MouseEventArgs)  
 
        MyBase.OnMouseClick(e)  
 
        If e.Button = Windows.Forms.MouseButtons.Left Then 
 
            MovePoint.X = e.X  
 
            MovePoint.Y = e.Y  
 
            PointInContent(MovePoint)  
 
        End If 
 
    End Sub 
 
 
 
 
 
    Protected Overrides Sub OnMouseDoubleClick(ByVal e As System.Windows.Forms.MouseEventArgs)  
 
        MyBase.OnMouseDoubleClick(e)  
 
        If e.Button = Windows.Forms.MouseButtons.Left Then 
 
            MovePoint.X = e.X  
 
            MovePoint.Y = e.Y  
 
            PointInContent(MovePoint)  
 
            If ISContent = True Then 
 
                CurrentColor = Color.FromArgb(ColorList(index))  
 
                OutcolorHander(NowColor, CurrentColor)  
 
            End If 
 
        End If 
 
    End Sub 
 
 
 
 
 
    ''' <summary>  
 
    ''' 判断当前点所在的六角形位置  
 
    ''' </summary>  
 
    ''' <param name="Mpoint"></param>  
 
    ''' <remarks></remarks>  
 
    Sub PointInContent(ByVal Mpoint As PointF)  
 
        index = 0  
 
        Dim gridsize As Size = New Size(16, 17)  
 
        Dim mapsize As Size = New Size(6, 13)  
 
        '六角格的水平半径各垂直半径  
 
 
 
        Dim wRad As Single = gridsize.Width / 2  
 
        Dim HRad As Single = gridsize.Height / 2  
 
        '六角格的水平直线,垂直线  
 
 
 
        Dim WLine As Single = Math.Sqrt(Math.Pow(wRad, 2) - Math.Pow(wRad / 2, 2))  
 
        Dim hLine As Single = Math.Sqrt(Math.Pow(HRad, 2) - Math.Pow(HRad / 2, 2))  
 
        '进行蜂窝式切合所必要的位偏移量  
 
 
 
        Dim wSpce As Single = (wRad - WLine) * 2  
 
        Dim hspce As Single = (HRad - hLine) * 2  
 
        '六角格的中心点  
 
        Dim cx As Single 
 
        Dim cy As Single 
 
        Dim boo As Boolean = False 
 
 
 
        For y As Integer = 0 To mapsize.Height - 1  
 
 
 
            If boo = False Then 
 
                mapsize.Width += 1  
 
            Else 
 
                mapsize.Width -= 1  
 
            End If 
 
 
 
            If y = 6 Then 
 
                boo = True 
 
            End If 
 
 
 
            For x As Integer = 0 To mapsize.Width - 1  
 
                '计当前六角格的中心点  
 
                cx = (gridsize.Width * (x + 1) - wRad) + 100  
 
                cy = (gridsize.Height * (y + 1) - HRad)  
 
                cx = cx - wSpce * x  
 
                cy = cy - hspce * y * 2  
 
                If boo = False Then 
 
 
 
                    cx = cx - WLine * mapsize.Width  
 
                Else 
 
                    cx = cx - WLine * mapsize.Width  
 
                End If 
 
                '保存六角格的六个角的位置  
 
                lindes = New List(Of PointF)(6)  
 
                '北  
 
                Dim start As New PointF(cx, cy - HRad)  
 
                lindes.Add(start)  
 
                '东北  
 
                lindes.Add(New PointF(cx + WLine, cy - HRad / 2))  
 
 
 
                '东南  
 
                lindes.Add(New PointF(cx + WLine, cy + HRad / 2))  
 
 
 
                '南  
 
                lindes.Add(New PointF(cx, cy + HRad))  
 
 
 
                '西南  
 
                lindes.Add(New Point(cx - WLine, cy + HRad / 2))  
 
 
 
                '西北  
 
                lindes.Add(New Point(cx - WLine, cy - HRad / 2))  
 
                '回到起点:北  
 
                lindes.Add(start)  
 
 
 
 
 
                '判断点  
 
                If Mpoint.Y > lindes(0).Y And Mpoint.X < lindes(1).X And Mpoint.Y < lindes(3).Y And Mpoint.X > lindes(4).X Then 
 
                    ISContent = True 
 
                    Me.Invalidate()  
 
                    Exit Sub 
 
                End If 
 
 
 
                index += 1  
 
            Next 
 
        Next 
 
 
 
        '=======================  
 
        '下左  
 
        wRad = 31 / 2  
 
        HRad = 32 / 2  
 
        '六角格的水平直线,垂直线  
 
        WLine = Math.Sqrt(Math.Pow(wRad, 2) - Math.Pow(wRad / 2, 2))  
 
        hLine = Math.Sqrt(Math.Pow(HRad, 2) - Math.Pow(HRad / 2, 2))  
 
        '进行蜂窝式切合所必要的位偏移量  
 
        wSpce = (wRad - WLine) * 2  
 
        hspce = (HRad - hLine) * 2  
 
 
 
        '计当前六角格的中心点  
 
        cx = 32 - wRad + 10  
 
        cy = 32 - HRad + 190  
 
        cx = cx - wSpce  
 
        cy = cy - hspce * 2  
 
        '保存六角格的六个角的位置  
 
        lindes = New List(Of PointF)(6)  
 
        '北  
 
        Dim START1 As New PointF(cx, cy - HRad)  
 
        lindes.Add(START1)  
 
        '东北  
 
        lindes.Add(New PointF(cx + WLine, cy - HRad / 2))  
 
 
 
        '东南  
 
        lindes.Add(New PointF(cx + WLine, cy + HRad / 2))  
 
 
 
        '南  
 
        lindes.Add(New PointF(cx, cy + HRad))  
 
 
 
        '西南  
 
        lindes.Add(New Point(cx - WLine, cy + HRad / 2))  
 
 
 
        '西北  
 
        lindes.Add(New Point(cx - WLine, cy - HRad / 2))  
 
 
 
        '回到起点:北  
 
        lindes.Add(START1)  
 
 
 
        '判断点  
 
        If Mpoint.Y > lindes(0).Y And Mpoint.X < lindes(1).X And Mpoint.Y < lindes(3).Y And Mpoint.X > lindes(4).X Then 
 
            ISContent = True 
 
            Me.Invalidate()  
 
            Exit Sub 
 
        End If 
 
        index += 1  
 
 
 
        '================  
 
        '下中  
 
        wRad = gridsize.Width / 2  
 
        HRad = gridsize.Height / 2  
 
        '六角格的水平直线,垂直线  
 
        WLine = Math.Sqrt(Math.Pow(wRad, 2) - Math.Pow(wRad / 2, 2))  
 
        hLine = Math.Sqrt(Math.Pow(HRad, 2) - Math.Pow(HRad / 2, 2))  
 
        '进行蜂窝式切合所必要的位偏移量  
 
        wSpce = (wRad - WLine) * 2  
 
        hspce = (HRad - hLine) * 2  
 
        Dim len As Integer = 7  
 
        For y As Integer = 0 To 1  
 
            If y = 1 Then 
 
                len = 6  
 
            End If 
 
            For x As Integer = 0 To len  
 
                '计当前六角格的中心点  
 
                cx = (gridsize.Width * (x + 1) - wRad) + 45  
 
                cy = (gridsize.Height * (y + 1) - HRad) + 180  
 
                cx = cx - wSpce * x  
 
                cy = cy - hspce * y * 2  
 
                If y = 1 Then 
 
 
 
                    cx = cx + WLine  
 
                End If 
 
                '保存六角格的六个角的位置  
 
                lindes = New List(Of PointF)(6)  
 
                '北  
 
                Dim start As New PointF(cx, cy - HRad)  
 
                lindes.Add(start)  
 
                '东北  
 
                lindes.Add(New PointF(cx + WLine, cy - HRad / 2))  
 
 
 
                '东南  
 
                lindes.Add(New PointF(cx + WLine, cy + HRad / 2))  
 
 
 
                '南  
 
                lindes.Add(New PointF(cx, cy + HRad))  
 
 
 
                '西南  
 
                lindes.Add(New Point(cx - WLine, cy + HRad / 2))  
 
 
 
                '西北  
 
                lindes.Add(New Point(cx - WLine, cy - HRad / 2))  
 
 
 
                '回到起点:北  
 
                lindes.Add(start)  
 
 
 
                '判断点  
 
                If Mpoint.Y > lindes(0).Y And Mpoint.X < lindes(1).X And Mpoint.Y < lindes(3).Y And Mpoint.X > lindes(4).X Then 
 
                    ISContent = True 
 
                    Me.Invalidate()  
 
                    Exit Sub 
 
                End If 
 
                index += 1  
 
            Next 
 
        Next 
 
 
 
 
 
        '==============  
 
        '下右  
 
        wRad = 31 / 2  
 
        HRad = 32 / 2  
 
        '六角格的水平直线,垂直线  
 
        WLine = Math.Sqrt(Math.Pow(wRad, 2) - Math.Pow(wRad / 2, 2))  
 
        hLine = Math.Sqrt(Math.Pow(HRad, 2) - Math.Pow(HRad / 2, 2))  
 
        '进行蜂窝式切合所必要的位偏移量  
 
        wSpce = (wRad - WLine) * 2  
 
        hspce = (HRad - hLine) * 2  
 
 
 
        '计当前六角格的中心点  
 
        cx = 32 - wRad + 165  
 
        cy = 32 - HRad + 190  
 
        cx = cx - wSpce  
 
        cy = cy - hspce * 2  
 
        '保存六角格的六个角的位置  
 
        lindes = New List(Of PointF)(6)  
 
        '北  
 
        Dim START2 As New PointF(cx, cy - HRad)  
 
        lindes.Add(START2)  
 
        '东北  
 
        lindes.Add(New PointF(cx + WLine, cy - HRad / 2))  
 
 
 
        '东南  
 
        lindes.Add(New PointF(cx + WLine, cy + HRad / 2))  
 
 
 
        '南  
 
        lindes.Add(New PointF(cx, cy + HRad))  
 
 
 
        '西南  
 
        lindes.Add(New Point(cx - WLine, cy + HRad / 2))  
 
 
 
        '西北  
 
        lindes.Add(New Point(cx - WLine, cy - HRad / 2))  
 
 
 
        '回到起点:北  
 
        lindes.Add(START2)  
 
 
 
 
 
        '判断点  
 
        If Mpoint.Y > lindes(0).Y And Mpoint.X < lindes(1).X And Mpoint.Y < lindes(3).Y And Mpoint.X > lindes(4).X Then 
 
            ISContent = True 
 
            Me.Invalidate()  
 
            Exit Sub 
 
        End If 
 
        
 
    End Sub 
 
 
 
End Class 

Imports System.Drawing

Imports System.Drawing.Drawing2D

Imports System.Drawing.Imaging

Imports System.Collections

Imports System.ComponentModel

Imports System.Collections.Generic

Public Class ColorControl

    Dim bit As New Bitmap(200, 230)

    Dim isDraw As Boolean = False

    Dim index As Integer = 0

    Dim g As Graphics = Graphics.FromImage(bit)

    Dim _NowColor As Color = Color.Transparent '现在颜色

    Dim _CurrentColor As Color = Color.Transparent '当前颜前

    '输出颜色

    Public Event OutputColorEvent(ByVal NColor As Color, ByVal CColor As Color)

    '触发事件

    Sub OutcolorHander(ByVal nColor As Color, ByVal CColor As Color)

        RaiseEvent OutputColorEvent(nColor, CColor)

    End Sub

    '颜色表

    Dim ColorList() As Integer = {&HFF003366, &HFF336699, &HFF3366CC, &HFF003399, &HFF000099, &HFF0000CC, &HFF000066, _

&HFF006666, &HFF006699, &HFF0099CC, &HFF0066CC, &HFF0033CC, &HFF0000FF, &HFF3333FF, &HFF333399, _

&HFF008080, &HFF009999, &HFF33CCCC, &HFF00CCFF, &HFF0099FF, &HFF0066FF, &HFF3366FF, &HFF3333CC, &HFF666699, _

&HFF339966, &HFF00CC99, &HFF00FFCC, &HFF00FFFF, &HFF33CCFF, &HFF3399FF, &HFF6699FF, &HFF6666FF, &HFF6600FF, &HFF6600CC, _

&HFF339933, &HFF00CC66, &HFF00FF99, &HFF66FFCC, &HFF66FFFF, &HFF66CCFF, &HFF9999FF, &HFF9999FF, &HFF9966FF, &HFF9933FF, &HFF9900FF, _

&HFF006600, &HFF00CC00, &HFF00FF00, &HFF66FF99, &HFF99FFCC, &HFFCCFFFF, &HFFCCECFF, &HFFCCCCFF, &HFFCC99FF, &HFFCC66FF, &HFFCC00FF, &HFF9900CC, _

&HFF003300, &HFF008000, &HFF33CC33, &HFF66FF66, &HFF99FF99, &HFFCCFFCC, &HFFFFFFFF, &HFFFFCCFF, &HFFFF99FF, &HFFFF66FF, &HFFFF00FF, &HFFCC00CC, &HFF660066, _

&HFF336600, &HFF009900, &HFF66FF33, &HFF99FF66, &HFFCCFF99, &HFFFFFFCC, &HFFFFCCCC, &HFFFF99CC, &HFFFF66CC, &HFFFF33CC, &HFFCC0099, &HFF800080, _

&HFF333300, &HFF669900, &HFF99FF33, &HFFCCFF66, &HFFFFFF99, &HFFFFCC99, &HFFFF9999, &HFFFF6699, &HFFFF3399, &HFFCC3399, &HFF800080, _

&HFF666633, &HFF99CC00, &HFFCCFF33, &HFFFFFF66, &HFFFFCC66, &HFFFF9966, &HFFFF7C80, &HFFFF0066, &HFFD60093, &HFF993366, _

&HFF808000, &HFFCCCC00, &HFFFFFF00, &HFFFFCC00, &HFFFF9933, &HFFFF6600, &HFFFF5050, &HFFCC0066, &HFF660033, _

&HFF996633, &HFFCC9900, &HFFFF9900, &HFFCC6600, &HFFFF3300, &HFFFF0000, &HFFCC0000, &HFF990033, _

&HFF663300, &HFF996600, &HFFCC3300, &HFF993300, &HFF990000, &HFF800000, &HFFA50021, _

&HFFFFFFFF, _

&HFFF8F8F8, &HFFDDDDDD, &HFFB2B2B2, &HFF808080, &HFF5F5F5F, &HFF333333, &HFF1C1C1C, &HFF080808, _

&HFFEAEAEA, &HFFC0C0C0, &HFF969696, &HFF777777, &HFF4D4D4D, &HFF292929, &HFF111111, _

&HFF000000}

    Sub New()

        ' This call is required by the Windows Form Designer.

        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        SetStyle(ControlStyles.AllPaintingInWmPaint, True)

        SetStyle(ControlStyles.StandardDoubleClick, True)

        SetStyle(ControlStyles.ResizeRedraw, True)

        SetStyle(ControlStyles.UserPaint, True)

        SetStyle(ControlStyles.OptimizedDoubleBuffer, True)

        g.SmoothingMode = SmoothingMode.HighQuality

    End Sub

    <Description("现在颜色")> _

    <Browsable(True)> _

    Public Property NowColor() As Color

        Get

            Return _NowColor

        End Get

        Set(ByVal value As Color)

            _NowColor = value

        End Set

    End Property

    <Description("现在颜色")> _

    <Browsable(True)> _

    Public Property CurrentColor() As Color

        Get

            Return _CurrentColor

        End Get

        Set(ByVal value As Color)

            _CurrentColor = value

        End Set

    End Property

    ''' <summary>

    '''绘制六角形上方

    ''' </summary>

    ''' <param name="gridSize">绘制六角形的长宽</param>

    ''' <param name="mapSize">绘制个数</param>

    ''' <param name="e">绘制对象</param>

    ''' <remarks></remarks>

    Public Sub BulidHexes(ByVal gridSize As Size, ByVal mapSize As Size, ByVal e As PaintEventArgs)

        If isDraw = True Then

            e.Graphics.DrawImage(bit, 0, 0)

            Exit Sub

        End If

        Dim lindes As List(Of PointF) = Nothing

        '六角格的水平半径各垂直半径

        Dim wRad As Single = gridSize.Width / 2

        Dim HRad As Single = gridSize.Height / 2

        '六角格的水平直线,垂直线

        Dim WLine As Single = Math.Sqrt(Math.Pow(wRad, 2) - Math.Pow(wRad / 2, 2))

        Dim hLine As Single = Math.Sqrt(Math.Pow(HRad, 2) - Math.Pow(HRad / 2, 2))

        '进行蜂窝式切合所必要的位偏移量

        Dim wSpce As Single = (wRad - WLine) * 2

        Dim hspce As Single = (HRad - hLine) * 2

        '六角格的中心点

        Dim cx As Single

        Dim cy As Single

        Dim isCenter As Boolean = False

        Dim result As GraphicsPath

        For y As Integer = 0 To mapSize.Height - 1

            If isCenter = False Then

                mapSize.Width += 1

            Else

                mapSize.Width -= 1

            End If

            If y = 6 Then

                isCenter = True

            End If

            For x As Integer = 0 To mapSize.Width - 1

                '计当前六角格的中心点

                cx = (gridSize.Width * (x + 1) - wRad) + 100

                cy = (gridSize.Height * (y + 1) - HRad)

                cx = cx - wSpce * x

                cy = cy - hspce * y * 2

                If isCenter = False Then

                    cx = cx - WLine * mapSize.Width

                Else

                    cx = cx - WLine * mapSize.Width

                End If

                '保存六角格的六个角的位置

                lindes = New List(Of PointF)(6)

                '北

                Dim start As New PointF(cx, cy - HRad)

                lindes.Add(start)

                '东北

                lindes.Add(New PointF(cx + WLine, cy - HRad / 2))

                '东南

                lindes.Add(New PointF(cx + WLine, cy + HRad / 2))

                '南

                lindes.Add(New PointF(cx, cy + HRad))

                '西南

                lindes.Add(New Point(cx - WLine, cy + HRad / 2))

                '西北

                lindes.Add(New Point(cx - WLine, cy - HRad / 2))

                '回到起点:北

                lindes.Add(start)

                result = New GraphicsPath()

                result.AddLines(lindes.ToArray())

                result.CloseFigure()

                Dim solidB As SolidBrush

                solidB = New SolidBrush(Color.FromArgb(ColorList(index)))

                index += 1

                g.FillPath(solidB, result)

            Next

        Next

        '=======================

        '下左

        wRad = 31 / 2

        HRad = 32 / 2

        '六角格的水平直线,垂直线

        WLine = Math.Sqrt(Math.Pow(wRad, 2) - Math.Pow(wRad / 2, 2))

        hLine = Math.Sqrt(Math.Pow(HRad, 2) - Math.Pow(HRad / 2, 2))

        '进行蜂窝式切合所必要的位偏移量

        wSpce = (wRad - WLine) * 2

        hspce = (HRad - hLine) * 2

   

            '计当前六角格的中心点

        cx = 32 - wRad + 10

        cy = 32 - HRad + 190

        cx = cx - wSpce

        cy = cy - hspce * 2

            '保存六角格的六个角的位置

            lindes = New List(Of PointF)(6)

        '北

        Dim START1 As New PointF(cx, cy - HRad)

        lindes.Add(START1)

            '东北

            lindes.Add(New PointF(cx + WLine, cy - HRad / 2))

            '东南

            lindes.Add(New PointF(cx + WLine, cy + HRad / 2))

            '南

            lindes.Add(New PointF(cx, cy + HRad))

            '西南

            lindes.Add(New Point(cx - WLine, cy + HRad / 2))

            '西北

            lindes.Add(New Point(cx - WLine, cy - HRad / 2))

            '回到起点:北

        lindes.Add(START1)

            result = New GraphicsPath()

            result.AddLines(lindes.ToArray())

            result.CloseFigure()

        Dim solidX As SolidBrush

        solidX = New SolidBrush(Color.FromArgb(ColorList(index)))

        index += 1

        g.FillPath(solidX, result)

        '================

        '下中

        wRad = gridSize.Width / 2

        HRad = gridSize.Height / 2

        '六角格的水平直线,垂直线

        WLine = Math.Sqrt(Math.Pow(wRad, 2) - Math.Pow(wRad / 2, 2))

        hLine = Math.Sqrt(Math.Pow(HRad, 2) - Math.Pow(HRad / 2, 2))

        '进行蜂窝式切合所必要的位偏移量

        wSpce = (wRad - WLine) * 2

        hspce = (HRad - hLine) * 2

        Dim len As Integer = 7

        For y As Integer = 0 To 1

            If y = 1 Then

                len = 6

            End If

            For x As Integer = 0 To len

                '计当前六角格的中心点

                cx = (gridSize.Width * (x + 1) - wRad) + 45

                cy = (gridSize.Height * (y + 1) - HRad) + 180

                cx = cx - wSpce * x

                cy = cy - hspce * y * 2

                If y = 1 Then

                    cx = cx + WLine

                End If

                '保存六角格的六个角的位置

                lindes = New List(Of PointF)(6)

                '北

                Dim start As New PointF(cx, cy - HRad)

                lindes.Add(start)

                '东北

                lindes.Add(New PointF(cx + WLine, cy - HRad / 2))

                '东南

                lindes.Add(New PointF(cx + WLine, cy + HRad / 2))

                '南

                lindes.Add(New PointF(cx, cy + HRad))

                '西南

                lindes.Add(New Point(cx - WLine, cy + HRad / 2))

                '西北

                lindes.Add(New Point(cx - WLine, cy - HRad / 2))

                '回到起点:北

                lindes.Add(start)

                result = New GraphicsPath()

                result.AddLines(lindes.ToArray())

                Dim solidY As SolidBrush

                solidY = New SolidBrush(Color.FromArgb(ColorList(index)))

                index += 1

                g.FillPath(solidY, result)

            Next

        Next

        '==============

        '下右

        wRad = 31 / 2

        HRad = 32 / 2

        '六角格的水平直线,垂直线

        WLine = Math.Sqrt(Math.Pow(wRad, 2) - Math.Pow(wRad / 2, 2))

        hLine = Math.Sqrt(Math.Pow(HRad, 2) - Math.Pow(HRad / 2, 2))

        '进行蜂窝式切合所必要的位偏移量

        wSpce = (wRad - WLine) * 2

        hspce = (HRad - hLine) * 2

        '计当前六角格的中心点

        cx = 32 - wRad + 165

        cy = 32 - HRad + 190

        cx = cx - wSpce

        cy = cy - hspce * 2

        '保存六角格的六个角的位置

        lindes = New List(Of PointF)(6)

        '北

        Dim START2 As New PointF(cx, cy - HRad)

        lindes.Add(START2)

        '东北

        lindes.Add(New PointF(cx + WLine, cy - HRad / 2))

        '东南

        lindes.Add(New PointF(cx + WLine, cy + HRad / 2))

        '南

        lindes.Add(New PointF(cx, cy + HRad))

        '西南

        lindes.Add(New Point(cx - WLine, cy + HRad / 2))

        '西北

        lindes.Add(New Point(cx - WLine, cy - HRad / 2))

        '回到起点:北

        lindes.Add(START2)

        result = New GraphicsPath()

        result.AddLines(lindes.ToArray())

        result.CloseFigure()

        Dim solidE As SolidBrush

        solidE = New SolidBrush(Color.Black)

        g.FillPath(solidE, result)

        e.Graphics.DrawImage(bit, 0, 0)

        isDraw = True

    End Sub

    Dim _PenColor As Color = Color.White

    Dim _penSize As Single = 2

    <Description("移动外边六角形的颜色")> _

    <Browsable(True)> _

     Public Property PenColor() As Color

        Get

            Return _PenColor

        End Get

        Set(ByVal value As Color)

            _PenColor = value

        End Set

    End Property

    <Description("画笔的大小")> _

    Public Property PenSize() As Single

        Get

            Return _penSize

        End Get

        Set(ByVal value As Single)

            _penSize = value

        End Set

    End Property

    ''' <summary>

    ''' 重绘方法

    ''' </summary>

    ''' <param name="e"></param>

    ''' <remarks></remarks>

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

        MyBase.OnPaint(e)

        BulidHexes(New Size(16, 17), New Size(6, 13), e)

        If ISContent = True Then

            Dim pen As New Pen(PenColor, PenSize)

            Dim GContent As Graphics = e.Graphics

            GContent.SmoothingMode = SmoothingMode.AntiAlias

            GContent.DrawPolygon(pen, lindes.ToArray())

            NowColor = Color.FromArgb(ColorList(index))

            OutcolorHander(NowColor, CurrentColor)

        End If

    End Sub

    Dim MovePoint As PointF

    Dim ISContent As Boolean = False

    Dim lindes As List(Of PointF) = Nothing

    ''' <summary>

    ''' 鼠标的移动

    ''' </summary>

    ''' <param name="e"></param>

    ''' <remarks></remarks>

    Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)

        MyBase.OnMouseMove(e)

        If e.Button = Windows.Forms.MouseButtons.Left Then

            MovePoint.X = e.X

            MovePoint.Y = e.Y

            PointInContent(MovePoint)

        End If

    End Sub

    ''' <summary>

    ''' 鼠标的单击

    ''' </summary>

    ''' <param name="e"></param>

    ''' <remarks></remarks>

    Protected Overrides Sub OnMouseClick(ByVal e As System.Windows.Forms.MouseEventArgs)

        MyBase.OnMouseClick(e)

        If e.Button = Windows.Forms.MouseButtons.Left Then

            MovePoint.X = e.X

            MovePoint.Y = e.Y

            PointInContent(MovePoint)

        End If

    End Sub

    Protected Overrides Sub OnMouseDoubleClick(ByVal e As System.Windows.Forms.MouseEventArgs)

        MyBase.OnMouseDoubleClick(e)

        If e.Button = Windows.Forms.MouseButtons.Left Then

            MovePoint.X = e.X

            MovePoint.Y = e.Y

            PointInContent(MovePoint)

            If ISContent = True Then

                CurrentColor = Color.FromArgb(ColorList(index))

                OutcolorHander(NowColor, CurrentColor)

            End If

        End If

    End Sub

    ''' <summary>

    ''' 判断当前点所在的六角形位置

    ''' </summary>

    ''' <param name="Mpoint"></param>

    ''' <remarks></remarks>

    Sub PointInContent(ByVal Mpoint As PointF)

        index = 0

        Dim gridsize As Size = New Size(16, 17)

        Dim mapsize As Size = New Size(6, 13)

        '六角格的水平半径各垂直半径

        Dim wRad As Single = gridsize.Width / 2

        Dim HRad As Single = gridsize.Height / 2

        '六角格的水平直线,垂直线

        Dim WLine As Single = Math.Sqrt(Math.Pow(wRad, 2) - Math.Pow(wRad / 2, 2))

        Dim hLine As Single = Math.Sqrt(Math.Pow(HRad, 2) - Math.Pow(HRad / 2, 2))

        '进行蜂窝式切合所必要的位偏移量

        Dim wSpce As Single = (wRad - WLine) * 2

        Dim hspce As Single = (HRad - hLine) * 2

        '六角格的中心点

        Dim cx As Single

        Dim cy As Single

        Dim boo As Boolean = False

        For y As Integer = 0 To mapsize.Height - 1

            If boo = False Then

                mapsize.Width += 1

            Else

                mapsize.Width -= 1

            End If

            If y = 6 Then

                boo = True

            End If

            For x As Integer = 0 To mapsize.Width - 1

                '计当前六角格的中心点

                cx = (gridsize.Width * (x + 1) - wRad) + 100

                cy = (gridsize.Height * (y + 1) - HRad)

                cx = cx - wSpce * x

                cy = cy - hspce * y * 2

                If boo = False Then

                    cx = cx - WLine * mapsize.Width

                Else

                    cx = cx - WLine * mapsize.Width

                End If

                '保存六角格的六个角的位置

                lindes = New List(Of PointF)(6)

                '北

                Dim start As New PointF(cx, cy - HRad)

                lindes.Add(start)

                '东北

                lindes.Add(New PointF(cx + WLine, cy - HRad / 2))

                '东南

                lindes.Add(New PointF(cx + WLine, cy + HRad / 2))

                '南

                lindes.Add(New PointF(cx, cy + HRad))

                '西南

                lindes.Add(New Point(cx - WLine, cy + HRad / 2))

                '西北

                lindes.Add(New Point(cx - WLine, cy - HRad / 2))

                '回到起点:北

                lindes.Add(start)

                '判断点

                If Mpoint.Y > lindes(0).Y And Mpoint.X < lindes(1).X And Mpoint.Y < lindes(3).Y And Mpoint.X > lindes(4).X Then

                    ISContent = True

                    Me.Invalidate()

                    Exit Sub

                End If

                index += 1

            Next

        Next

        '=======================

        '下左

        wRad = 31 / 2

        HRad = 32 / 2

        '六角格的水平直线,垂直线

        WLine = Math.Sqrt(Math.Pow(wRad, 2) - Math.Pow(wRad / 2, 2))

        hLine = Math.Sqrt(Math.Pow(HRad, 2) - Math.Pow(HRad / 2, 2))

        '进行蜂窝式切合所必要的位偏移量

        wSpce = (wRad - WLine) * 2

        hspce = (HRad - hLine) * 2

        '计当前六角格的中心点

        cx = 32 - wRad + 10

        cy = 32 - HRad + 190

        cx = cx - wSpce

        cy = cy - hspce * 2

        '保存六角格的六个角的位置

        lindes = New List(Of PointF)(6)

        '北

        Dim START1 As New PointF(cx, cy - HRad)

        lindes.Add(START1)

        '东北

        lindes.Add(New PointF(cx + WLine, cy - HRad / 2))

        '东南

        lindes.Add(New PointF(cx + WLine, cy + HRad / 2))

        '南

        lindes.Add(New PointF(cx, cy + HRad))

        '西南

        lindes.Add(New Point(cx - WLine, cy + HRad / 2))

        '西北

        lindes.Add(New Point(cx - WLine, cy - HRad / 2))

        '回到起点:北

        lindes.Add(START1)

        '判断点

        If Mpoint.Y > lindes(0).Y And Mpoint.X < lindes(1).X And Mpoint.Y < lindes(3).Y And Mpoint.X > lindes(4).X Then

            ISContent = True

            Me.Invalidate()

            Exit Sub

        End If

        index += 1

        '================

        '下中

        wRad = gridsize.Width / 2

        HRad = gridsize.Height / 2

        '六角格的水平直线,垂直线

        WLine = Math.Sqrt(Math.Pow(wRad, 2) - Math.Pow(wRad / 2, 2))

        hLine = Math.Sqrt(Math.Pow(HRad, 2) - Math.Pow(HRad / 2, 2))

        '进行蜂窝式切合所必要的位偏移量

        wSpce = (wRad - WLine) * 2

        hspce = (HRad - hLine) * 2

        Dim len As Integer = 7

        For y As Integer = 0 To 1

            If y = 1 Then

                len = 6

            End If

            For x As Integer = 0 To len

                '计当前六角格的中心点

                cx = (gridsize.Width * (x + 1) - wRad) + 45

                cy = (gridsize.Height * (y + 1) - HRad) + 180

                cx = cx - wSpce * x

                cy = cy - hspce * y * 2

                If y = 1 Then

                    cx = cx + WLine

                End If

                '保存六角格的六个角的位置

                lindes = New List(Of PointF)(6)

                '北

                Dim start As New PointF(cx, cy - HRad)

                lindes.Add(start)

                '东北

                lindes.Add(New PointF(cx + WLine, cy - HRad / 2))

                '东南

                lindes.Add(New PointF(cx + WLine, cy + HRad / 2))

                '南

                lindes.Add(New PointF(cx, cy + HRad))

                '西南

                lindes.Add(New Point(cx - WLine, cy + HRad / 2))

                '西北

                lindes.Add(New Point(cx - WLine, cy - HRad / 2))

                '回到起点:北

                lindes.Add(start)

                '判断点

                If Mpoint.Y > lindes(0).Y And Mpoint.X < lindes(1).X And Mpoint.Y < lindes(3).Y And Mpoint.X > lindes(4).X Then

                    ISContent = True

                    Me.Invalidate()

                    Exit Sub

                End If

                index += 1

            Next

        Next

        '==============

        '下右

        wRad = 31 / 2

        HRad = 32 / 2

        '六角格的水平直线,垂直线

        WLine = Math.Sqrt(Math.Pow(wRad, 2) - Math.Pow(wRad / 2, 2))

        hLine = Math.Sqrt(Math.Pow(HRad, 2) - Math.Pow(HRad / 2, 2))

        '进行蜂窝式切合所必要的位偏移量

        wSpce = (wRad - WLine) * 2

        hspce = (HRad - hLine) * 2

        '计当前六角格的中心点

        cx = 32 - wRad + 165

        cy = 32 - HRad + 190

        cx = cx - wSpce

        cy = cy - hspce * 2

        '保存六角格的六个角的位置

        lindes = New List(Of PointF)(6)

        '北

        Dim START2 As New PointF(cx, cy - HRad)

        lindes.Add(START2)

        '东北

        lindes.Add(New PointF(cx + WLine, cy - HRad / 2))

        '东南

        lindes.Add(New PointF(cx + WLine, cy + HRad / 2))

        '南

        lindes.Add(New PointF(cx, cy + HRad))

        '西南

        lindes.Add(New Point(cx - WLine, cy + HRad / 2))

        '西北

        lindes.Add(New Point(cx - WLine, cy - HRad / 2))

        '回到起点:北

        lindes.Add(START2)

        '判断点

        If Mpoint.Y > lindes(0).Y And Mpoint.X < lindes(1).X And Mpoint.Y < lindes(3).Y And Mpoint.X > lindes(4).X Then

            ISContent = True

            Me.Invalidate()

            Exit Sub

        End If

     

    End Sub

End Classview plaincopy to clipboardprint?

  

 view plaincopy to  clipboardprint?

<FONT size=4>在窗体是使用这个控件</FONT> 

在窗体是使用这个控件view plaincopy to clipboardprint?

<FONT size=2>效果如下图:</FONT> 

效果如下图:

只要处理一个事件(OutcolorEvnet)就可以取得当前颜色与新增颜色.

下面是我的代码。大家在修改颜色时根据自己具体的设置修改一个就行了。使用起来挺方便的

view plaincopy to clipboardprint?

Private Sub ColorControl1_OutputColorEvent(ByVal NColor As System.Drawing.Color, ByVal CColor As System.Drawing.Color) Handles ColorControl1.OutputColorEvent  
 
       Panel1.BackColor = NColor  
 
       Panel2.BackColor = CColor  
 
   End Sub 

 Private Sub ColorControl1_OutputColorEvent(ByVal NColor As System.Drawing.Color, ByVal CColor As System.Drawing.Color) Handles ColorControl1.OutputColorEvent

        Panel1.BackColor = NColor

        Panel2.BackColor = CColor

    End Sub

转载于:https://www.cnblogs.com/aspxnets/archive/2011/06/29/2093811.html

你可能感兴趣的文章
梭子鱼推出AI解决方案实时防御鱼叉式网络钓鱼和网络欺诈
查看>>
无边界安全成新趋势,志翔科技推出首个体系化“无边界”安全产品
查看>>
Saas云应用趋势及企业网盘选型建议
查看>>
全球能源互联与智慧城市建设论坛举行
查看>>
《Linux内核精髓:精通Linux内核必会的75个绝技》一HACK #9 RT Group Scheduling 与RT Throttling...
查看>>
共建华为网络学院
查看>>
阿里、腾讯有意收购西班牙媒体Imagina股份
查看>>
深度学习在人脸识别中的应用——优图祖母模型的“进化”
查看>>
北京工业云成为国家工业云一面旗帜
查看>>
《可穿戴创意设计:技术与时尚的融合》一一2.2 仿生学与生体模仿学
查看>>
企业如何实现云计算中的负载平衡?
查看>>
微软Windows Insider团队:Win10M将会留在Feature2分支
查看>>
为个人信息安全加“保险锁” 多家快递公司启用隐私面单
查看>>
微软全面推出Windows Server 2016
查看>>
中国移动:SDN/NFV发展要与未来5G网络架构创新深度结合
查看>>
浙企先行军阿里:智慧“新丝路”的全球化理想
查看>>
IT历史观:这就是中国第一台计算机
查看>>
大数据时代,我们是不是在“裸奔”?
查看>>
智慧城市时空基础设施国家标准通过审查
查看>>
英特尔第二财季利润锐减 受重组支出拖累
查看>>