public void ReflashWave2Thread(object _tn) { string tn = (string)_tn; int gap = 500; DrawWave dw = new DrawWave(ref pictureBox2); DataTable dttb = dtst.Tables[tn]; while (reflashWave2ThreadFlag) { lock (DrawWave.wavelock) { gap = wave2pram.timegap; try { int num = dttb.Rows.Count; num -= (dw.boxSize.X - 40) / 5 * gap; UInt16[] data = new UInt16[(dw.boxSize.X - 40) / 5]; if (num >= 51) { for (int i = 0; i < (dw.boxSize.X - 40) / 5; i++) { //int average = 0; //for (int j = 0; j < gap; j++) //{ // average += (UInt16)dttb.Rows[num - 51 + i * gap + j]["DataValue"]; //} //average = average / gap; //data[i] = (UInt16)average; data[i] = (UInt16)dttb.Rows[num - 1 + i * gap]["DataValue"]; } dw.Wave(ref data, ref pictureBox2, 1, 1); } else { int num0 = dttb.Rows.Count / gap; UInt16[] data0 = new UInt16[num0]; for (int i = 0; i < num0; i++) { data0[i] = (UInt16)dttb.Rows[i * gap]["DataValue"]; } dw.Wave(ref data0, ref pictureBox2, 1, 1); } } catch (Exception) { } } Thread.Sleep(100); } }
// select data point and draw wave void SelectShowData(string tablename, ref PictureBox pictureBox, ref HScrollBar hScrollBar, ref TrackBar trackBar) { DrawWave dw = new DrawWave(ref pictureBox); ushort[] data; int gap; //x axis timegap int datanum = (dw.boxSize.X - 40) / 5; gap = timgap[trackBar.Value]; data = new ushort[datanum]; // set hScrollBar hScrollBar.LargeChange = 50 * gap; hScrollBar.SmallChange = 5 * gap; hScrollBar.Maximum = ds.Tables[tablename].Rows.Count - (datanum + 1) * gap; hScrollBar.Minimum = 0; if (hScrollBar.Maximum < 0) { hScrollBar.Maximum = 0; } for (int i = 0; i < datanum; i++) { try { data[i] = (ushort)ds.Tables[tablename].Rows[i * gap + hScrollBar.Value][2]; } catch (Exception) { break; } } dw.ClearToBackcolor(ref pictureBox); dw.DrawXaxis(ref pictureBox, 1, 5); dw.DrawYaxis(ref pictureBox, 1, 5); dw.Wave(ref data, ref pictureBox, 1, 1); }