110,533
社区成员
发帖
与我相关
我的任务
分享
private void initDesk()
{
string strSql = dkSql;
if (strSql == "") return;
if (dtDk == null)
{
dtDk = bm.GetUserAllDesk(strSql); //获得子控件个数
}
this.pnlDesk.Controls.Clear();//添加前先清空
if (dtDk.Rows.Count > 0)
{
// 分页片段==============================
if (dtDk.Rows.Count % dkPageSize == 0)
{
dkPageCount = dtDk.Rows.Count / dkPageSize;
}
else
{
dkPageCount = dtDk.Rows.Count / dkPageSize + 1;
}
int start = (dkPageIndex - 1) * dkPageSize;
int end = start + dkPageSize - 1;
if (end > dtDk.Rows.Count - 1) end = dtDk.Rows.Count - 1;
// 分页片段==============================
int cols = 9;//列数
int iLine = 0;//行数
int sum = end - start; //当前页需要显示数目
if ((sum + 1) % cols == 0)
{
iLine = (sum+1) / cols;
}
else
{
iLine = (sum + 1) / cols + 1;
}
//动态添加按钮
int i = 0;
int j = 0;
int s = start;
DeskControl btn;//自定义子控件
while (j < iLine)
{
btn = new DeskControl();//初始化
btn.Location = new System.Drawing.Point(100 * i +10*i + 20, 10 * j + 100*j + 3);//显示位置
btn.Size = new System.Drawing.Size(100, 100);//显示大小
btn.Name = dtDk.Rows[s]["dkID"].ToString();//名称
btn.DcDeskNum.Text = dtDk.Rows[s]["dkName"].ToString();
string isbusy = dtDk.Rows[s]["dkIsBusy"].ToString();
if (isbusy.ToLower() == "false")
{
// 这些都是子控件里一些属性和方法赋值,下同
btn.setEmpty();
btn.DcMoney.Visible = false;
btn.DcTime.Visible = false;
btn.DcPersonCount.Text = dtDk.Rows[s]["dktPrnCountLow"].ToString() + "-" + dtDk.Rows[s]["dktPrnCountHigh"].ToString();
}
else if (isbusy.ToLower() == "true")
{
btn.setBusy();
try
{
btn.DcMoney.Text = ((Decimal)dtDk.Rows[s]["slValue"]).ToString("f2");
btn.DcTime.Text = ((DateTime)dtDk.Rows[s]["slStartTime"]).ToString("HH:mm");
btn.DcPersonCount.Text = dtDk.Rows[s]["slPersonCount"].ToString();
}
catch{ }
}
else
{
btn.setEmpty();
btn.DcMoney.Visible = false;
btn.DcTime.Visible = false;
btn.DcPersonCount.Visible = false;
}
btn.ControlClik += new DeskControl.ControlClickEventHandler(Desk_Click);//子控件点击事件
this.pnlDesk.Controls.Add(btn);//添加子控件
// 以下控制换行
i++;
s++;
if (i > cols - 1)
{
i = 0;
j++;
}
if (s > end)
{
break;
}
}
}
}
应用程序出错:System.ComponentModel.Win32Exception: Error creating window handle.
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at Restaurant.FrmMainDesk.initDesk()
at Restaurant.FrmMainDesk.btnDkNext_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at Restaurant.Common.BitmapButton.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
错误描述:Application_ThreadException