小菜请教:
在窗体A中打开了窗体B,窗体B中有TeeChart控件,打开B的代码:
B b = new B();
b.Owner = this;
b.ShowDialog();
点击窗体B中某按钮(调用TeeChart控件进行画线操作),然后在b.ShowDialog();处报错 未将对象引用设置到对象的实例。我删掉TeeChart控件,点按钮不报错。是不是画完线后,TeeChart为空了,应该怎样处理?
在窗体A中打开了窗体B,窗体B中有TeeChart控件,打开B的代码:
B b = new B();
b.Owner = this;
b.ShowDialog();
点击窗体B中某按钮(调用TeeChart控件进行画线操作),然后在b.ShowDialog();处报错 未将对象引用设置到对象的实例。我删掉TeeChart控件,点按钮不报错。是不是画完线后,TeeChart为空了,应该怎样处理?
你A打开B的时候B b = new B();
b.Owner = this;
b.ShowDialog();
这个时候你的B已经show出来了吧
不然你怎么 点击窗体B中某按钮(调用TeeChart控件进行画线操作)呢
但奇怪的是你点B窗体的按钮,A窗体代码报错吗不知道是不是我理解错了
{
DataTable table = this.zedSource.Tables[0];
string fdjwz = this.radioButton3.Checked ? "左" : "右";
if (this.checkedListBox1.CheckedItems.Count == 0)
{
MessageBox.Show("请至少选择一个参数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
this.tChart1.Header.Text = fdjwz;
foreach (object obj in this.checkedListBox1.CheckedItems)
{
string itemValue = "ABC".Contains(obj.ToString()) ? fdjwz + obj.ToString() : obj.ToString();
if (dicParm.ContainsKey(obj.ToString()))
{
Points p = new Points(); //是不是这句话有问题
foreach (DataRow row in table.Rows)
{
if (table.Columns[itemValue] != null)
{
double fxsj = Convert.ToDouble(row["时间"]);
double ynum = Convert.ToDouble(row[itemValue]);
p.Add(fxsj, ynum);
}
}
Color c = new CustomCode().GetRandomColor() //还有这句
CustomCode.drawLine(this.tChart1, p, itemValue, c);
Model.FCParamter parMod = this.dicParm[obj.ToString()];
double minx = this.tChart1.Axes.Bottom.MinXValue;
double maxx = this.tChart1.Axes.Bottom.MaxXValue;
if (parMod.UpperLimit != -1) CustomCode.DrawWarLine(this.tChart1, minx, maxx, Convert.ToDouble(parMod.UpperLimit), itemValue + "警戒线(上限)", c, 1);
if (parMod.LowerLimit != -1) CustomCode.DrawWarLine(this.tChart1, minx, maxx, Convert.ToDouble(parMod.LowerLimit), itemValue + "警戒线(下限)", c, 1);
}
}
}
}
你在new b对象那里设置断点,调试一下。
估计是b对象那里没执行或者其他原因导致没创建,所以就报那个错误。
这个错误一看就要想到对象没实例的问题。
理解的正确
B出现后,没有任何错误,当我点击按钮进行画线操作后,TeeChart出现线条,但随即就在A窗体的b.ShowDialog();处报错
{
//...
}
catch (Exception error)
{
throw error;
}
//看看哪一句报错
try
{
B b = new B();
b.Owner = this;
b.ShowDialog();
}
catch (Exception error)
{
throw error;
}报错
er.Source TeeChart
er.StackTrace 在 Steema.TeeChart.Styles.Series.CalcXPosValue(Double value)
在 Steema.TeeChart.Styles.Series.CalcXPos(Int32 index)
在 Steema.TeeChart.Styles.CustomPoint.CalcXPos(Int32 valueIndex)
在 Steema.TeeChart.Styles.CustomPoint.Clicked(Int32 x, Int32 y)
在 Steema.TeeChart.Tools.MarksTip.MouseEvent(MouseEventKinds kind, MouseEventArgs e, Cursor& c)
在 Steema.TeeChart.Chart.BroadcastMouseEvent(MouseEventKinds kind, MouseEventArgs e, Cursor& c)
在 Steema.TeeChart.Chart.BroadcastMouseEvent(MouseEventKinds kind, MouseEventArgs e, Keys modKeys)
在 Steema.TeeChart.TChart.OnMouseMove(MouseEventArgs e)
在 System.Windows.Forms.Control.WmMouseMove(Message& m)
在 System.Windows.Forms.Control.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.RunDialog(Form form)
在 System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
在 System.Windows.Forms.Form.ShowDialog()
在 EIMAS.JKSJGL_FC.dataGridView1_CellClick(Object sender, DataGridViewCellEventArgs e) 位置 E:\Microsoft\Visual Studio 2005\EIMAS_Solution\WinApp\JKSJGL_FC.cs:行号 143
zed这个对象的类代码贴出来。
代码太多了,您的意思是不关TeeChart的事,是B窗体的代码有问题?