分不多了,请帮帮忙!急!立即结帖!

yangqi0218 2004-12-09 04:43:33
我写了段代码,可是就是调用不了,请问怎么调用啊?


using System;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
using System.Globalization;
using System.Drawing.Drawing2D;
using System.Collections;


namespace DrawTools
{
/// <summary>
/// DrawArc 的摘要说明。
/// </summary>
public class DrawArc : DrawTools.DrawPolygon
{
private Point startPoint;
private Point endPoint;

int width = 100;
int height = 200;
// Create start and sweep angles on ellipse.
int startAngle = 45;
int sweepAngle = 270;

private const string entryStart = "Start";
private const string entryEnd = "End";

public DrawArc()
{
ArrayList pointArray = new ArrayList();

startPoint.X = 0;
//startPoint.Y = 0;
//endPoint.X = 100;
endPoint.Y = 100;

Initialize();
}

public DrawArc(int x1, int y2)
{
ArrayList pointArray = new ArrayList();

startPoint.X = x1;
//startPoint.Y = y1;
//endPoint.X = x2;
endPoint.Y = y2;

Initialize();
}

public override void Draw(Graphics g)
{
g.SmoothingMode = SmoothingMode.AntiAlias;

Pen pen = new Pen(Color, PenWidth);

/// <summary>
///pen的DashStyle虚线样式的成员
///Custom 指定用户定义的自定义划线段样式。
///Dash 指定由划线段组成的直线。
///DashDot 指定由重复的划线点图案构成的直线。
///DashDotDot 指定由重复的划线点点图案构成的直线。
///Dot 指定由点构成的直线。
///Solid 指定实线。
/// </summary>
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;

g.DrawArc(pen, startPoint.X, endPoint.Y, width, height, startAngle, sweepAngle);

pen.Dispose();
}

public void AddPoint(Point point)
{
ArrayList pointArray = new ArrayList();
pointArray.Add(point);
}

}
}


我想画弧线,其实就需要用
g.DrawArc(pen, startPoint.X, endPoint.Y, width, height, startAngle, sweepAngle);
这句,我是在另一个类调用这个的,可是老是说g不存在,我加了这句
Graphics g = new Graphics();可是未获取又说0参数,郁闷中,高手们帮帮忙吧!
...全文
142 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangqi0218 2004-12-13
  • 打赏
  • 举报
回复
问题解决了,谢谢各位!
同时也谢谢楼上!
zhongshiguo 2004-12-09
  • 打赏
  • 举报
回复
太。。。
缺少最基础的知识,说了你也不能明白。
lucbesson 2004-12-09
  • 打赏
  • 举报
回复
那是段已经写好的代码 ,
你只需要 项目----添加现有项(选择所有文件) 选择然后调用就可以啦。
再另一个 xxx.cs文件中你要加上 using DrawTools ;


welshem 2004-12-09
  • 打赏
  • 举报
回复
Graphics g = new Graphics();?
不会吧,Graphics实质上是一个绘图权,不应新建的,应通过上级窗器获取的
比如建立一图片对象,获取其绘图权
tonybaobao 2004-12-09
  • 打赏
  • 举报
回复
Graphics对象相当于画板,你现在Graphics g = new Graphics();等于没有选定画板,当然无法绘画了。
一般是这样的:
Bitmap bitmap = new Bitmap( 400, 400 );//400X400大小的位图
Graphics g = Graphics.FromImage( bitmap );//把这个新建的位图当作画板
g.Clear( Color.White );//先清空画板,再用白色填充画板背景色

//绘图代码...

bitmap.Save( System.Web.HttpContext.Current.Response.OutputStream,ImageFormat.Jpeg );
//保存图片到输出流
jiangd 2004-12-09
  • 打赏
  • 举报
回复
学习
帮顶
yangqi0218 2004-12-09
  • 打赏
  • 举报
回复
1
yangqi0218 2004-12-09
  • 打赏
  • 举报
回复
UP

111,092

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧