| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 848 人关注过本帖
标题:VB.NET 中用API函数Polygon画多边形错误问题
只看楼主 加入收藏
kwgllw
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-1-6
收藏
 问题点数:0 回复次数:0 
VB.NET 中用API函数Polygon画多边形错误问题
为了工作方便.想把以前用VB6写的工具转换成主要是为界面好看.但是今在用到API函数Polygon绘多边形的时候,提示错误了.值不在预期范围内
 

具体代代码如下,请各位指导一下了.
程序代码:
Public Class Form1
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Integer) As Integer
    Private Declare Function SelectObject Lib "gdi32" Alias "SelectObject" (ByVal hdc As Integer, ByVal hObject As Integer) As Integer
    Private Declare Function CreateSolidBrush Lib "gdi32.dll" (ByVal crColor As Integer) As Integer
    Private Declare Function CreatePen Lib "gdi32.dll" (ByVal nPenStyle As Integer, ByVal nWidth As Integer, ByVal crColor As Integer) As Integer
    Private Const PS_SOLID = 0
    Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Integer, ByVal lpPoint As Object, ByVal nCount As Integer) As Integer
    Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Integer, ByVal X1 As Integer, ByVal Y1 As Integer, ByVal X2 As Integer, ByVal Y2 As Integer) As Integer
    Public Declare Function GetDC Lib "user32" (ByVal hWnd As Integer) As Integer
    Public Mur As MapXLib.Layer
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        AxMap1.CurrentTool = MapXLib.ToolConstants.miPanTool
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        AxMap1.CurrentTool = MapXLib.ToolConstants.miZoomInTool
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        AxMap1.CurrentTool = MapXLib.ToolConstants.miZoomOutTool
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        AxMap1.Layers.LayersDlg()
    End Sub
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Mur = AxMap1.Layers.AddUserDrawLayer("CELL", 1) '添加在最上层
    End Sub
    Private Sub AxMap1_DrawUserLayer(ByVal sender As Object, ByVal e As AxMapXLib.CMapXEvents_DrawUserLayerEvent) Handles AxMap1.DrawUserLayer
        Dim Smp As Integer
        Dim Smb As Integer
        Dim Nmp As Integer
        Dim Nmb As Integer
        Dim Points(16) As PointAPI
        Dim x0 As Double
        Dim y0 As Double
        Dim px As Single
        Dim py As Single
        Dim beam As Integer
        Dim radiu As Integer
        Dim Per_Azimuth As Integer
        Dim Calc_azi As Double
        x0 = 109.0
        y0 = 30.0
        AxMap1.ConvertCoord(px, py, x0, y0, MapXLib.ConversionConstants.miMapToScreen)      '坐标转换
        Points(1).x = px : Points(1).y = py
        beam = 80
        radiu = 80
        Calc_azi = beam - beam / 2
        Per_Azimuth = (beam + beam / 15) / 15
        For Counter = 2 To 15
            Points(Counter).x = Points(1).x + Math.Sin(Calc_azi * 3.141592654 / 180) * radiu
            Points(Counter).y = Points(1).y - Math.Cos(Calc_azi * 3.141592654 / 180) * radiu
            Calc_azi = (90 - beam / 2) + Per_Azimuth * (Counter - 1)
        Next Counter
        Points(16).x = px : Points(16).y = py
        Smp = CreatePen(PS_SOLID, 3, RGB(255, 0, 0))
        Smb = CreateSolidBrush(RGB(0, 255, 0))
        Dim hwd As Integer
        hwd = GetDC(AxMap1.Handle.ToInt32)
        Nmp = SelectObject(e.hOutputDC, Smp)
        Nmb = SelectObject(e.hOutputDC, Smb)
        Polygon(e.hOutputDC, Points(1), 16)    '这里出错,值不在预期范围内
        Ellipse(e.hOutputDC, Points(1).x, Points(1).y, Points(5).x, Points(5).y)
    End Sub

End Class


Module Module1

    Public Structure PointAPI
        Public x As Integer
        Public y As Integer
    End Structure
End Module

2014-01-06 18:41
快速回复:VB.NET 中用API函数Polygon画多边形错误问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021402 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved