网上找了段代码,我把它编译成dll,都没有问题,为何一添加到程序里面 就提示 未将对象引用设置到对象的实例 ?public class ToolBarXP : System.Windows.Forms.ToolBar { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; private Color fillColorHover = Color.FromArgb(182,189,210); private Color borderColorHover = Color.Navy; private Color fillDownColor = Color.RosyBrown; private Color borderDownColor = Color.SeaGreen; public ToolBarXP(System.ComponentModel.IContainer container) { /// /// Required for Windows.Forms Class Composition Designer support /// container.Add(this); InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // this.SetStyle(ControlStyles.UserPaint,true); } public ToolBarXP() { /// /// Required for Windows.Forms Class Composition Designer support /// InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // this.SetStyle(ControlStyles.UserPaint,true); } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } /// <summary> /// 鼠标在按钮之上时,按钮呈现的背景色 /// </summary> // [Description("鼠标在按钮之上时,按钮呈现的背景色"),Category("Natrpan")] public Color FillColorHover { get { return fillColorHover;} set { fillColorHover = value;} } /// <summary> /// 鼠标在按钮之上时,按钮呈现的边框色 /// </summary> // [Description("鼠标在按钮之上时,按钮呈现的边框色"), // Category("Natrpan")] public Color BorderColorHover { get {return borderColorHover;} set { borderColorHover = value;} } /// <summary> /// 按钮被按下时的填充背景色 /// </summary> //[Description("按钮被按下时的背景色"), //Category("Natrpan")] public Color FillDownColor { get {return fillDownColor;} set { fillDownColor = value;} } /// <summary> /// 按钮被按下时的边框色 /// </summary> //[Description("按钮被按下时的边框色"), //Category("Natrpan")] public Color BorderDownColor { get {return borderDownColor;} set { borderDownColor = value;} } protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; for(int i=0;i<this.Buttons.Count;i++) { if(this.Buttons[i].Rectangle.Contains(PointToClient(MousePosition))) { g.FillRectangle(new SolidBrush(this.fillColorHover),this.Buttons[i].Rectangle); g.DrawImage(this.ImageList.Images[i],this.Buttons[i].Rectangle.X+1,this.Buttons[i].Rectangle.Y+1); g.DrawRectangle(new Pen(this.borderColorHover),this.Buttons[i].Rectangle.X,this.Buttons[i].Rectangle.Y,this.Buttons[i].Rectangle.Width-2,this.Buttons[i].Rectangle.Height-2); continue; } // g.DrawRectangle(Pens.Red,this.Buttons[i].Rectangle); g.DrawImage(this.ImageList.Images[i],this.Buttons[i].Rectangle.X,this.Buttons[i].Rectangle.Y); } // g.FillRectangle(new SolidBrush(Color.Purple),this.ClientRectangle); // base.OnPaint(e); } // protected override void onMouseHover(EventArgs e)
//
// {
//
// // Graphics g = this.CreateGraphics();
//
// // g.DrawRectangle(Pens.SaddleBrown,this.Buttons[0].Rectangle);
//
// // g.Dispose();
//
// } #region Component Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { components = new System.ComponentModel.Container(); } #endregion }
//
// {
//
// // Graphics g = this.CreateGraphics();
//
// // g.DrawRectangle(Pens.SaddleBrown,this.Buttons[0].Rectangle);
//
// // g.Dispose();
//
// } #region Component Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { components = new System.ComponentModel.Container(); } #endregion }
解决方案 »
- 为什么用as进行类型转换被那么推崇?
- 问一个SendMessage的问题(C#)(第四贴)
- c# enter键的捕获
- 怎样能提高windows窗口的绘制效率?
- 怎么在 DataGrid中实现插入可编辑行?
- delrec.Attributes.Add("onclick", "return confirm('Are you sure to delete this record?');")应该怎么用?
- 菜鸟问一个怎么在textBox中删除DataGrid中的数据,然后数据库里也删除了
- 怎么获取系统屏幕放大比例
- C# 重新实例?
- 关于网页HttpWebRequest出错请教
- 公司不让用QQ,MSN,,,能不能自己写个聊天工具啊(只要2个人可以聊的就可以了)?
- 怎么样才能在C#中实现OUTLOOK滚动工具栏效果呢
谢谢
[email protected]
[email protected]