c#中关于当前上下文不存在名称的问题

caicia_1 2017-07-26 10:47:36
我是新手,用c#复制网上的代码总提示上下文不存名称XXX,能帮忙解释一下是哪的原因吗?代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NPlot;

namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void plot_Click(object sender, EventArgs e)
{
// --- Plotting ---
plot.Clear(); //对象名称为plot
// --- Grid Code ---
Grid mygrid = new Grid();
mygrid.HorizontalGridType = Grid.GridType.None;
mygrid.VerticalGridType = Grid.GridType.Fine;
plot.Add(mygrid);
plot.Title = "chulai啊";
StepPlot line = new StepPlot();
line.Pen = new Pen(Color.Blue, 1);
line.OrdinateData = new int[] { 0, 1, 0, 1, 1, 0 };
line.HideVerticalSegments = false;
plot.Add(line);
plot.Refresh();
return;
}

private void button1_Click(object sender, EventArgs e)
{
plot_Click(sender, e);
}

private void button2_Click(object sender, EventArgs e)
{
// --- Plotting ---
plot.Clear();
plot.Refresh();
}
////////对所绘的图进行打印与保存//////////
private void print()
{
myPlot.Print(true);
}
private void save()
{
saveFileDialog1.Filter = "位图(*.bmp)|*.bmp|JPEG(*.jpg)|*.jpg;*.jpeg;*,jpe|Gif(*.gif)|*.gif|Tiff(*.tiff)|*.tiff|Png(*.png)|*.png|Exif(*.exif)|*.exif|所有文件(*.*)|*.*";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
int h = myPlot.Size.Height;
int w = myPlot.Size.Width;
Bitmap bm = new Bitmap(w, h);
Bitmap bm1 = new Bitmap(w, h);
Rectangle rt = new Rectangle(1, 1, w, h);
saveFileDialog1.RestoreDirectory = true;
saveFileDialog1.CreatePrompt = true;
myPlot.DrawToBitmap(bm, rt);
if (saveFileDialog1.FilterIndex == 1)
{
bm.Save(saveFileDialog1.FileName);
}
if (saveFileDialog1.FilterIndex == 2)
{
bm.Save(saveFileDialog1.FileName, ImageFormat.Jpeg);
}
if (saveFileDialog1.FilterIndex == 3)
{
bm.Save(saveFileDialog1.FileName, ImageFormat.Gif);
}
if (saveFileDialog1.FilterIndex == 4)
{
bm.Save(saveFileDialog1.FileName, ImageFormat.Tiff);
}
if (saveFileDialog1.FilterIndex == 5)
{
bm.Save(saveFileDialog1.FileName, ImageFormat.Png);
}
if (saveFileDialog1.FilterIndex == 6)
{
bm.Save(saveFileDialog1.FileName, ImageFormat.Exif);
}
}
catch (Exception MyEx)
{
MessageBox.Show(MyEx.ToString(), "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
}
}


错误报告:当前上下文中不存在"saveFileDialog1"
当前上下文中不存在"myplot"
当前上下文中不存在"ImageFormat"
...全文
3218 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
CPU不够了 2017-07-26
  • 打赏
  • 举报
回复
明显前台有控件你没加
xdashewan 2017-07-26
  • 打赏
  • 举报
回复
明显代码不全

111,083

社区成员

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

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

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