I am trying to create a class of windows forms objects, but I can't seem to get it to work right. I'm fairly new to programming, so I imagine I'm just missing a basic concept. Any help would be appreciated.
I want to have a group of objects consisting of a listview, a textbox, 4 buttons, and a label. I then want to be able to run a function within my form code to call this group of objects (called "SearchSection") and specify where to place it on the form.
Could you please elaborate on "class of windows forms objects"? Did you mean a container control that will host a few windows forms objects?
RMRyan MilliganApril 16, 2003 02:54 AM UTC
> Could you please elaborate on "class of windows forms objects"? Did you mean a container control that will host a few windows forms objects?
I think that is what I'm looking for. Basically what I need is a Label above a text box which is above 4 buttons lined in a row. Each button would perform a particular function. There would also be a listview that has a few items in it that when selected would change the text of the label to the text of the selected item. This is the group of Windows forms objects that I would like as my "class of windows forms objects".
I may be completely off with how I have it set up, but here is what I have tried so far:
public class SearchSection
public System.Windows.Forms.Label SearchesTitle;
public System.Windows.Forms.TextBox Input;
public System.Windows.Forms.Button Submit;
public System.Windows.Forms.Button Copy;
public System.Windows.Forms.Button Paste;
public System.Windows.Forms.Button Type;
public System.Windows.Forms.ListView SearchesList;
private System.Windows.Forms.ListViewItem listViewItem1;
public int left;
public int top;
public void placeStuff(int x,int y)
this.SearchesTitle = new System.Windows.Forms.Label();
this.Input = new System.Windows.Forms.TextBox();
this.Submit = new System.Windows.Forms.Button();
this.Copy = new System.Windows.Forms.Button();
this.Paste = new System.Windows.Forms.Button();
this.Type = new System.Windows.Forms.Button();
this.SearchesList = new System.Windows.Forms.ListView();
// Search Title.
this.SearchesTitle.Text = "Skippy (User ID/Email)";
this.SearchesTitle.Location = new System.Drawing.Point(x,y);
this.Input.Location = new System.Drawing.Point(x, y+16);
this.Input.Size = new System.Drawing.Size(128, 20);
this.Input.Click += new System.EventHandler(this.Input_Click);
// Submit Button
this.Submit.Location = new System.Drawing.Point(x+2,y+36);
this.Copy.Location = new System.Drawing.Point(x+36,y+36);
this.Paste.Location = new System.Drawing.Point(x+72,y+36);
this.Type.Location = new System.Drawing.Point(x+108,y+36);
//Search list box
this.SearchesList.Location = new System.Drawing.Point(x,y);
this.SearchesList.Size = new System.Drawing.Size(0,0);
private void Input_Click(object sender, System.EventArgs e)
this.Input.Text = Clipboard.GetDataObject().GetData(DataFormats.Text).ToString();
Ramesh PraveenApril 16, 2003 07:32 PM UTC
I think you should create a custom UserControl in teh designer filling it with all those Controls. Then, you could instantiate it and place it in your form just like any other control.
RMRyan MilliganApril 17, 2003 03:25 AM UTC
Being new to this, I didn't even think about that. It worked great. Thanks. This will open many other doors for me in the future.