你是画在picturebox上吧 而没有给Picturebox。Image 赋值吧
解决方案 »
- C#如何实现自动登陆网站(带验证码)
- 类型“System.Data.Common.DbConnection”在未被引用的程序集中定义。
- 用Post方式如果采集
- TreeView css
- 帮个忙,我在程序中写了一条修改表的语句,运行之后,总是提示@ColumnName附近有错误.
- 事件冒泡能不能解决用户控件中的服务器控件不响应事件问题---请教高手
- 怎么动态的声明HtmlTableCell?
- 我装了studio.net 2003,我打开项目文件时报错,急救!!!
- c# socket 如何让多个客户端 同时传文件给服务器
- usb设备安全停止问题
- 有会用sql语句实现分页的朋友
- socket接受数据时候如何区分是我发的消息,还是要传的文件!
{
MessageBox.Show("没有图片");
}
已经在pictureBox1中画过图像,为什么还会出现NULL例外?这个需要看你的代码。你贴上来
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication2
{
public partial class Form1 : Form
{
Pen MyPen = new System.Drawing.Pen(System.Drawing.Color.Red, 1);
PointF pStart;
PointF pEnd;
PointF pWork;
Boolean working;
Boolean brushmode;
String dmode = "line";
void Drawshape(Graphics e,PointF startp,PointF endp,Boolean brushmode,Pen penmode,String dmode)
{
Rectangle rect1=new Rectangle ((int)startp.X ,(int)startp.Y,(int)(endp.X -startp .X ),(int)(endp.Y -startp.Y ));
switch (dmode )
{
case "line":
e.DrawLine(penmode,startp.X,startp.Y,endp.X ,endp.Y);
break ;
case "rect":
if(brushmode==true) e.FillRectangle(penmode.Brush ,rect1);
else e.DrawRectangle(penmode,rect1);
break;
case "circle":
if(brushmode ==true ) e.FillEllipse(penmode.Brush,rect1);
else e.DrawEllipse(penmode,rect1);
break;
default:break;
}
}
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
System.Drawing.Drawing2D.HatchBrush brush2 = new
System.Drawing.Drawing2D.HatchBrush(
System.Drawing.Drawing2D.HatchStyle.DarkDownwardDiagonal,
Color.Brown);
//BtnSetColor.BackColor =Color .MediumBlue;
} private void BtnSetColor_Click(object sender, EventArgs e)
{
colorDialog1.ShowDialog();
BtnSetColor.BackColor = colorDialog1.Color;
} private void BntClear_Click(object sender, EventArgs e)
{
pictureBox1.CreateGraphics().Clear(Color.White);
} private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
working = true;
pStart.X = e.X;
pStart.Y = e.Y;
toolStripStatusLabel1 .Text = "[" + e.X + "," + e.Y + "]";
} private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if(working==true )
{
pEnd.X =e.X;
pEnd .Y=e.Y;
MyPen.Color=BtnSetColor.BackColor ;
MyPen.Width=(int)numericUpDown1.Value;
brushmode=checkBox1 .Checked ;
if(radioButton1 .Checked==true )
MyPen .DashStyle =System .Drawing .Drawing2D .DashStyle .Solid ;
if(radioButton2 .Checked==true )
MyPen .DashStyle =System .Drawing .Drawing2D .DashStyle .Dot ;
if(radioButton3 .Checked==true )
MyPen .DashStyle =System .Drawing .Drawing2D .DashStyle .Dash;
if(radioButton4.Checked==true )
MyPen .DashStyle =System .Drawing .Drawing2D .DashStyle .Custom ;
if(radioButton5 .Checked==true )
MyPen .DashStyle =System .Drawing .Drawing2D .DashStyle .DashDotDot;
if(radioButton6 .Checked==true )
MyPen .DashStyle =System .Drawing .Drawing2D .DashStyle .DashDot;
if(radioButton7 .Checked==true )
dmode ="line";
if(radioButton8 .Checked==true )
dmode ="circle";
if(radioButton9.Checked==true )
dmode ="rect";
if(radioButton10 .Checked==true )
MyPen .Brush =new System .Drawing .Drawing2D .HatchBrush (
System.Drawing.Drawing2D.HatchStyle .DarkDownwardDiagonal ,
MyPen.Color );
if(radioButton11 .Checked==true )
MyPen .Brush =new
System .Drawing .Drawing2D .HatchBrush (
System.Drawing.Drawing2D.HatchStyle .Cross ,MyPen .Color );
if(radioButton12 .Checked==true )
MyPen .Brush =new SolidBrush(MyPen .Color );
Drawshape (pictureBox1 .CreateGraphics (),
pStart ,pEnd,brushmode ,MyPen ,dmode );
working =false ;
} } private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (working == true)
{
pWork.X = e.X;
pWork.Y = e.Y;
toolStripStatusLabel1.Text = "[" + e.X + "," + e.Y + "]";
}
} //前面为一个简单画图程序 private void button1_Click(object sender, EventArgs e)
{//剪切按钮
Clipboard.SetDataObject(pictureBox1.Image, true);
pictureBox1.CreateGraphics().Clear(pictureBox1.BackColor);
} private void button2_Click(object sender, EventArgs e)
{//复制按钮 Clipboard.SetDataObject(pictureBox1.Image, true);
} private void button3_Click(object sender, EventArgs e)
{//粘贴按钮
IDataObject clipbord_data;
Image tmp;
clipbord_data = Clipboard.GetDataObject();
if (clipbord_data.GetDataPresent(DataFormats.Bitmap))
{
tmp = (Image)clipbord_data.GetData(DataFormats.Bitmap);
pictureBox2.CreateGraphics().DrawImage(tmp, 0, 0);
}
}
}
}