我已經(jīng)在 Visual C#設(shè)計(jì)中創(chuàng)建了一個(gè)面板到我的表單中,現(xiàn)在我想顯示與我擁有的數(shù)據(jù)庫表中的注冊一樣多的面板。我有這個(gè)腳本,但結(jié)果是: User login_user = new User(); login_user.SelectThisMember(); lblHello.Text = "Hello, " + login_user.username + " !"; Booking user_bookings = new Booking(); Booking[] user_bookings_list; user_bookings_list = user_bookings.MyBookings(); lblTest.Text = user_bookings_list.Length.ToString(); Panel[] panelBookingList = new Panel[user_bookings_list.Length]; for (int i = 0; i < user_bookings_list.Length; i++) { panelBookingList[i] = panelBooking; } for (int i=0; i< panelBookingList.Length; i++) { panelBookingList[i].Location = new Point(193, 128+128); this.Controls.Add(panelBookingList[i]); }帶有“ 3 ”的標(biāo)簽表示我在數(shù)據(jù)庫中的行數(shù)。另外,當(dāng)我按下表中用于該注冊的刪除按鈕時(shí),我該怎么做才能知道?
1 回答

湖上湖
TA貢獻(xiàn)2003條經(jīng)驗(yàn) 獲得超2個(gè)贊
如果我沒記錯(cuò)的話,您不會(huì)更新面板的位置。
panelBookingList[i].Location = new Point(193, 128+128);
位置應(yīng)取決于您的變量“i”
最好的方法是使用堆棧面板,只需將面板轉(zhuǎn)儲(chǔ)到其中,而無需設(shè)置它們的位置。這樣,如果您更改面板的布局,您就不必進(jìn)一步編輯代碼來考慮面板的新高度。堆棧面板只是一個(gè)接一個(gè)地放置控件。
否則,您需要對(duì)面板的高度進(jìn)行硬編碼
double myPanelHeight = 100;// hardcoded height of your panel
panelBookingList[i].Location = new Point(193, 128+ (i * myPanelHeight));
- 1 回答
- 0 關(guān)注
- 163 瀏覽
添加回答
舉報(bào)
0/150
提交
取消