2010-06-11 64 views
-6

如何添加列在C#中的Windows应用程序C#Windows应用程序

+0

你说的列是什么意思? – rahul 2010-06-11 12:08:07

+1

添加列到什么? DataGridView,ListView等 – SwDevMan81 2010-06-11 12:08:27

+3

嗨,欢迎来到Stack Overflow,但恐怕在发布任何有意义的答案之前,您都必须发布更多信息。 – 2010-06-11 12:08:34

回答

1

使用。例如ListView,它有一个Columns属性...你可以用ListViewItems的SubItems属性添加列。虽然有其他的可能性(控制),但是(如DataGridView)。

也许你应该看看这个组件(=谷歌)。任何一本体面的书都会涵盖它们。

+0

感谢你对精神能力的惩罚 – 2010-06-11 13:55:26

+1

+1。 – 2010-06-11 15:28:39

1
public class Coloumn : Control 
{ 
} 

//in your Form Load 
for(int i=0;i<100;i++) 
    this.Controls.Add(new Coloumn()); 
//when the control comes here, your form is flooded with Coloumns.. 

我这样做,因为你的requirements are not clear

+0

雅它的'罚款填充列 – 2010-06-11 13:54:22

6

像这样:

using System.Drawing; 
using System.Windows.Forms; 
using System.IO; 
using System.Net; 

namespace WithColumns 
{ 
    public class FormWithColumns : Form 
    { 
     public FormWithColumns() 
     { 
      Label label1 = new Label(); 
       Label label2 = new Label(); 

      SuspendLayout(); 


      WebRequest req = WebRequest.Create("http://www.bc.edu/bc_org/avp/cas/fnart/arch/greek/doric1.jpg"); 
      WebResponse response = req.GetResponse(); 
      Stream stream = response.GetResponseStream(); 
      Image img = Image.FromStream(stream); 

      stream.Close(); 

      ClientSize = new Size(img.Width * 3, img.Height); 

      label1.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom; 
      label1.Location = new System.Drawing.Point(0, 0); 
      label1.Size = img.Size; 
      label1.Image = img; 

      label2.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom; 
      label2.Location = new System.Drawing.Point(img.Width * 2, 0); 
      label2.Size = img.Size; 
      label2.Image = img; 

      Controls.Add(label1); 
      Controls.Add(label2); 
      Text = "Form With Columns"; 
      BackColor = Color.White; 
      ResumeLayout(false); 
     } 
    } 
} 
+1

+1 - 绝对天才 – 2010-06-11 13:38:14

+0

+1感谢您的笑! – Odrade 2010-06-11 13:51:12

+0

看到我需要datagridview列 – 2010-06-11 13:51:39