c#求助,未将对象引用到实例化
如题:这是错误代码提示:
未处理 System.NullReferenceException
Message=未将对象引用设置到对象的实例。
Source=testwinfrm
StackTrace:
在 testwinfrm.Mainfrm.DrawTop_Left(Graphics g) 位置 C:\Documents and Settings\Administrator\桌面\testwinfrm\testwinfrm\Mainfrm.cs:行号 126
在 testwinfrm.Mainfrm.OnPaint(PaintEventArgs e) 位置 C:\Documents and Settings\Administrator\桌面\testwinfrm\testwinfrm\Mainfrm.cs:行号 110
在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
在 System.Windows.Forms.Control.WmPaint(Message& m)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.ContainerControl.WndProc(Message& m)
在 System.Windows.Forms.Form.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 testwinfrm.Program.Main() 位置 C:\Documents and Settings\Administrator\桌面\testwinfrm\testwinfrm\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
程序代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Resources;
namespace testwinfrm
{
public partial class Mainfrm : Form
{
///
/// 定义一个资源管理器
///
private ResourceManager rm;
private Image Top_Left;
private Image SysButton_Re;
private int TITLE_WIDTH = 200;
//private bool Resource = false;
private static string Skin_Path = Environment.CurrentDirectory + "\\Skin\\";//皮肤文件夹路径
//创建一个Resource文件
public static void Create()
{
if (!System.IO.File.Exists("skin.Resource"))
{
ResourceWriter rw = new ResourceWriter("skin.Resource");//创建一个资源文件
try
{
Image Top_Left = Image.FromFile(Skin_Path + "Top_Left.png");
rw.AddResource("Top_Left.png", Top_Left);
rw.AddResource("Mystr", "从资源文件中读取字符串!");
rw.Generate();
rw.Close();
}
catch
{
rw.Close();
throw new ArgumentException(Skin_Path);
}
}
}
public Mainfrm()
{
Create();
try
{
rm = new ResourceManager("SkinWindow.Skin", this.GetType().Assembly);
//读取图片
Top_Left = (Image)rm.GetObject("Top_Left.png");
}
catch
{
}
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
//手工画窗体的各个部分
DrawTop_Left(e.Graphics);//
}
private void DrawTop_Left(Graphics g)
{
//Rectangle Rect1 = new Rectangle(0, 0, Top_Left.Width, Top_Left.Height);
Brush brush = new TextureBrush(Top_Left, new Rectangle(0, 0, Top_Left.Width, Top_Left.Height));
g.FillRectangle(brush, 0, TITLE_WIDTH, Top_Left.Width,Height - Top_Left.Height - TITLE_WIDTH);
}
}
}
就在有颜色地方报错的,急需解决方法,再次谢谢大虾。
本人菜鸟,希望大大们帮我解决下,小弟不胜感激,留下邮箱:pl369@163.com顺便讨点c#编程资料,关于winform和oracle方面的。
未处理 System.NullReferenceException
Message=未将对象引用设置到对象的实例。
Source=testwinfrm
StackTrace:
在 testwinfrm.Mainfrm.DrawTop_Left(Graphics g) 位置 C:\Documents and Settings\Administrator\桌面\testwinfrm\testwinfrm\Mainfrm.cs:行号 126
在 testwinfrm.Mainfrm.OnPaint(PaintEventArgs e) 位置 C:\Documents and Settings\Administrator\桌面\testwinfrm\testwinfrm\Mainfrm.cs:行号 110
在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
在 System.Windows.Forms.Control.WmPaint(Message& m)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.ContainerControl.WndProc(Message& m)
在 System.Windows.Forms.Form.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 testwinfrm.Program.Main() 位置 C:\Documents and Settings\Administrator\桌面\testwinfrm\testwinfrm\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
程序代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Resources;
namespace testwinfrm
{
public partial class Mainfrm : Form
{
///
/// 定义一个资源管理器
///
private ResourceManager rm;
private Image Top_Left;
private Image SysButton_Re;
private int TITLE_WIDTH = 200;
//private bool Resource = false;
private static string Skin_Path = Environment.CurrentDirectory + "\\Skin\\";//皮肤文件夹路径
//创建一个Resource文件
public static void Create()
{
if (!System.IO.File.Exists("skin.Resource"))
{
ResourceWriter rw = new ResourceWriter("skin.Resource");//创建一个资源文件
try
{
Image Top_Left = Image.FromFile(Skin_Path + "Top_Left.png");
rw.AddResource("Top_Left.png", Top_Left);
rw.AddResource("Mystr", "从资源文件中读取字符串!");
rw.Generate();
rw.Close();
}
catch
{
rw.Close();
throw new ArgumentException(Skin_Path);
}
}
}
public Mainfrm()
{
Create();
try
{
rm = new ResourceManager("SkinWindow.Skin", this.GetType().Assembly);
//读取图片
Top_Left = (Image)rm.GetObject("Top_Left.png");
}
catch
{
}
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
//手工画窗体的各个部分
DrawTop_Left(e.Graphics);//
}
private void DrawTop_Left(Graphics g)
{
//Rectangle Rect1 = new Rectangle(0, 0, Top_Left.Width, Top_Left.Height);
Brush brush = new TextureBrush(Top_Left, new Rectangle(0, 0, Top_Left.Width, Top_Left.Height));
g.FillRectangle(brush, 0, TITLE_WIDTH, Top_Left.Width,Height - Top_Left.Height - TITLE_WIDTH);
}
}
}
就在有颜色地方报错的,急需解决方法,再次谢谢大虾。
本人菜鸟,希望大大们帮我解决下,小弟不胜感激,留下邮箱:pl369@163.com顺便讨点c#编程资料,关于winform和oracle方面的。
...全文
相关推荐
未将对象引用设置到对象的实例(C#出現的錯誤)
"未将对象引用设置到对象的实例"錯誤個人總結
c# DataGridView 导出数据到sql中出现错误“未将对象引用设置到对象实例中”
c# DataGridView 导出数据到sql中出现错误“未将对象引用设置到对象实例中”
asp.net运行提示未将对象引用设置到对象的实例错误解决方法
asp.net运行提示未将对象引用设置到对象的实例错误解决方法,需要的朋友可以参考下
C# 实例化接口对象的方法
在head first 设计模式中 用到了很多很多接口对象 首先澄清一个问题,就是接口不仅可以声明对象,而且可以把对象实例化,还可以当做参数被传入。 一、接口回调 这就是继承中的向上转型。父类 FL=new 子类();只不过这里的父类就是interface接口。(个人认为这里不管是class的override还是interface的重写,都是一样的用法) 可以把实现某一接口类创建的对象的引用赋给该接口声明的接口变量,那么该 接口变量就可以调用被类实现的接口中的方法。实际上,当接口变量调用被类实现的接口中的方法时,就是通知相应的对象调用接口方法 直接上代码 using System; usin
错误:对象引用未设置为对象的实例。 请帮忙
Request.QueryS ...


