我在面板中顯示項目時出現問題,即附加到數據流佈局,面板具有標籤,文本框,按鈕,複選框和圖像,但是當我運行程序時,只有圖像消失,儘管我已經在面板中設置了每個控件的位置,並且面板從數據流佈局控件的數據庫中循環,當我嘗試更改面板的大小時不顯示。在面板中顯示組項目
我只是希望有人能指向正確的方向,任何幫助表示讚賞
謝謝
我做了什麼做的遠:
foreach ("looped according to the database")
{
Panel pan = new Panel();
PictureBox img = new PictureBox();
Button btn = new Button();
Label house = new Label();
TextBox Street = new TextBox();
CheckBox check = new CheckBox();
pan.Location = new Point();
pan.Size = new System.Drawing.Size();
MemoryStream ms = new MemoryStream();
img .Image = Image.FromStream(ms);
img .Tag = Product.ID;
img .SizeMode = PictureBoxSizeMode.StretchImage;
img .Location = new System.Drawing.Point();
img .Size = new System.Drawing.Size();
img .TabIndex = 0;
house .Text = Product.Name;
house .Location = new System.Drawing.Point();
house .Size = new System.Drawing.Size();
house .AutoSize = true;
house .TabIndex = 1;
Street.Location = new System.Drawing.Point();
Street.Size = new System.Drawing.Size();
Street.TabIndex = 2;
btn.Text = "info";
btn.Size = new System.Drawing.Size();
btn.Location = new System.Drawing.Point();
btn.ForeColor = Color.Green;
btn.TabIndex = 2;
pan.Controls.Add(img);
pan.Controls.Add(check);
pan.Controls.Add(House);
pan .Controls.Add(Street);
pan.Controls.Add(btn);
this.ProductsFlowPanel.Controls.Add(pan);
}
}
我想實現類似的東西對此; image
行'泛=新的點();'甚至不會編譯,因爲'pan'已經被聲明爲變量輸入'Panel' – Fabio
這是我創建表單時的參考,可以請看看https://msdn.microsoft.com/en-us/library/system.windows.forms.panel(v=vs.110) .aspx#示例 – SSSS
Line'Panel pan = new Panel();' - 創建'Panel'類型的實例。你的命令'pan = new Point();'會嘗試將'Point'的新實例設置爲'pan' - 這在C#中是不可能的,因爲'pan'已經被聲明爲'Panel'的類型。顯然你試圖寫'pan.Location = new Point()' – Fabio