We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Class of Windows forms objects

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.

4 Replies

Ramesh Praveen April 14, 2003 11:35 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? Thanks Praveen

RM Ryan Milligan April 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? > > Thanks > Praveen > 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: using System; namespace The_Omega_Tool { 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 SearchSection() { placeStuff(this.left, this.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); //Input box 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); //Copy Button this.Copy.Location = new System.Drawing.Point(x+36,y+36); //Paste button this.Paste.Location = new System.Drawing.Point(x+72,y+36); //Type button 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) { if(Clipboard.GetDataObject().GetDataPresent(DataFormats.Text)) this.Input.Text = Clipboard.GetDataObject().GetData(DataFormats.Text).ToString(); } } }

Ramesh Praveen April 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. Regards, Praveen Ramesh

RM Ryan Milligan April 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. --Ryan
Loader.
Live Chat Icon For mobile
Up arrow icon