c#求助,未将对象引用到实例化

xiaolong263 xiaolong263 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
如题:这是错误代码提示:

未处理 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方面的。
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
xiaolong263
C# 111,129 成员 642,538 内容