当前位置:编程学习 > wap >>

C# 无法引用System.Drawing.Drawing2D

在用C#编写Windows Mobile程序时,需要调用GraphicsPath()方法绘图,已经引用了System.Drawing.Drawing2D(using System.Drawing.Drawing2D),但是当编译GraphicsPath gx = new GraphicsPath();时仍然报错,显示“找不到类型或命名空间名称“GraphicsPath“(是否缺少using指令或程序及引用)”在两台电脑上都试验过了,C#初学者,希望给出具体的解决方案,谢谢 --------------------编程问答-------------------- GraphicsPath这个类在Windows Mobile当中不支持。 --------------------编程问答--------------------
引用 1 楼 jiangyongtao 的回复:
GraphicsPath这个类在Windows Mobile当中不支持。
那在Windows Mobile中如何绘制圆角矩形啊,想做个按钮 --------------------编程问答-------------------- 下面的DrawRoundedRect方法,LZ自己参考下。
C# code
   
//画圆角
public static void DrawRoundedRect(Graphics g, Pen p, Color backColor, Rectangle rc, Size size)
        {
            Point[] points = new Point[8];

            //圆角的八个点
            points[0].X = rc.Left + size.Width / 2;
            points[0].Y = rc.Top + 1;   
            points[1].X = rc.Right - size.Width / 2;
            points[1].Y = rc.Top + 1;

            points[2].X = rc.Right;
            points[2].Y = rc.Top + size.Height / 2;
            points[3].X = rc.Right;
            points[3].Y = rc.Bottom - size.Height / 2;

            points[4].X = rc.Right - size.Width / 2;
            points[4].Y = rc.Bottom;
            points[5].X = rc.Left + size.Width / 2;
            points[5].Y = rc.Bottom;

            points[6].X = rc.Left + 1;
            points[6].Y = rc.Bottom - size.Height / 2;
            points[7].X = rc.Left + 1;
            points[7].Y = rc.Top + size.Height / 2;

            //圆角矩形的填充背景色
            Brush fillBrush = new SolidBrush(backColor);

            //画转角的线
            g.DrawLine(p, rc.Left + size.Width / 2, rc.Top,
             rc.Right - size.Width / 2, rc.Top);
                       
            g.FillEllipse(fillBrush, rc.Right - size.Width, rc.Top,
             size.Width, size.Height);

            g.DrawEllipse(p, rc.Right - size.Width, rc.Top,
            size.Width, size.Height);


            g.DrawLine(p, rc.Right, rc.Top + size.Height / 2,
             rc.Right, rc.Bottom - size.Height / 2);

            g.FillEllipse(fillBrush, rc.Right - size.Width, rc.Bottom - size.Height,
            size.Width, size.Height);

            g.DrawEllipse(p, rc.Right - size.Width, rc.Bottom - size.Height,
             size.Width, size.Height);

           

            g.DrawLine(p, rc.Right - size.Width / 2, rc.Bottom,
             rc.Left + size.Width / 2, rc.Bottom);

            g.FillEllipse(fillBrush, rc.Left, rc.Bottom - size.Height,
            size.Width, size.Height);

            g.DrawEllipse(p, rc.Left, rc.Bottom - size.Height,
             size.Width, size.Height);
           
            

            g.DrawLine(p, rc.Left, rc.Bottom - size.Height / 2,
             rc.Left, rc.Top + size.Height / 2);
            g.FillEllipse(fillBrush, rc.Left, rc.Top,
             size.Width, size.Height);

            g.DrawEllipse(p, rc.Left, rc.Top,
            size.Width, size.Height);
                  
            //填充多边形,以消去不连续区
            g.FillPolygon(fillBrush, points);
            //Dispose 资源
            fillBrush.Dispose();
        } 
--------------------编程问答-------------------- 你说的是在手机上不支持吧。有这个可能 --------------------编程问答-------------------- 手机不支持GraphicsPath。。。。。 --------------------编程问答-------------------- 这个看msdn, 里面很清楚标识哪些API是wm下开发所支持的 --------------------编程问答-------------------- 用于Windows Mobile平台免费的图形开发包

.Net Framework提供了 System.Drawing ,System.Drawing.Drawing2D 用于二维图形开发,但有相当一部分没有在 Windows Compact Framework 得到支持。
如 Pen的 .LineJoin .LineCap 已及 各种二维图形类。如 Arc, Area, Polyline, Polygon, Path.

这里提供一个免费的 用于Windows Mobile平台图形开发包。基本提供了 Desktop 平台 System.Drawing.Drawing2D 功能。

下面是一个简单的实例,用各种几何图形拼出一个Pear.(来源于经典Java示例),其他例子 Colors, Polys, Pahts, LineJoin,LineCap 见附件 http://download.csdn.net/source/2736333 --------------------编程问答--------------------

 
            Ellipse circle, oval, leaf, stem;
            Area circ, ov, leaf1, leaf2, st1, st2;
            circle = new Ellipse();
            oval = new Ellipse();
            leaf = new Ellipse();
            stem = new Ellipse();
            circ = new Area(circle);
            ov = new Area(oval);
            leaf1 = new Area(leaf);
            leaf2 = new Area(leaf);
            st1 = new Area(stem);
            st2 = new Area(stem);
            graphics2D.Reset();
            graphics2D.Clear(Color.White);
            int w = screenWidth;
            int h = screenHeight;
            int ew = w / 2;
            int eh = h / 2;
            SolidBrush brush = new SolidBrush(Color.Green);
            graphics2D.DefaultBrush = brush;
            // Creates the first leaf by filling the intersection of two Area
            //objects created from an ellipse.
            leaf.SetFrame(ew - 16, eh - 29, 15, 15);
            leaf1 = new Area(leaf);
            leaf.SetFrame(ew - 14, eh - 47, 30, 30);
            leaf2 = new Area(leaf);
            leaf1.Intersect(leaf2);
            graphics2D.Fill(null, leaf1);

            // Creates the second leaf.
            leaf.SetFrame(ew + 1, eh - 29, 15, 15);
            leaf1 = new Area(leaf);
            leaf2.Intersect(leaf1);
            graphics2D.Fill(null, leaf2);

            brush = new SolidBrush(Color.Black);
            graphics2D.DefaultBrush = brush;

            // Creates the stem by filling the Area resulting from the
            //subtraction of two Area objects created from an ellipse.
            stem.SetFrame(ew, eh - 42, 40, 40);
            st1 = new Area(stem);
            stem.SetFrame(ew + 3, eh - 47, 50, 50);
            st2 = new Area(stem);
            st1.Subtract(st2);
            graphics2D.Fill(null, st1);

            brush = new SolidBrush(Color.Yellow);
            graphics2D.DefaultBrush = brush;

            // Creates the pear itself by filling the Area resulting from the
            //union of two Area objects created by two different ellipses.
            circle.SetFrame(ew - 25, eh, 50, 50);
            oval.SetFrame(ew - 19, eh - 20, 40, 70);
            circ = new Area(circle);
            ov = new Area(oval);
            circ.Add(ov);
            graphics2D.Fill(null, circ);
            Invalidate();


--------------------编程问答--------------------
补充:移动开发 ,  Windows Phone
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,