• 0

From Combo Boxes to Group Box


Question

6 answers to this question

Recommended Posts

  • 0

Im using C#

This is my code:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication1
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
  private System.Windows.Forms.ComboBox comboBox1;
  private System.Windows.Forms.ComboBox comboBox2;
  private System.Windows.Forms.ComboBox comboBox3;
  private System.Windows.Forms.ComboBox comboBox4;
  private System.Windows.Forms.ComboBox comboBox5;
  private System.Windows.Forms.ComboBox comboBox6;
  private System.Windows.Forms.ComboBox comboBox7;
  private System.Windows.Forms.ComboBox comboBox8;
  private System.Windows.Forms.Label label1;
  private System.Windows.Forms.Label label2;
  private System.Windows.Forms.TextBox textBox1;
  private System.Windows.Forms.Label label3;
  private System.Windows.Forms.TextBox textBox2;
  private System.Windows.Forms.PictureBox pictureBox1;
  private System.Windows.Forms.Panel panel1;
  private System.Windows.Forms.GroupBox groupBox1;
  /// <summary>
  /// Required designer variable.
  /// </summary>
  private System.ComponentModel.Container components = null;

  public Form1()
  {
  	//
  	// Required for Windows Form Designer support
  	//
  	InitializeComponent();

  	//
  	// TODO: Add any constructor code after InitializeComponent call
  	//
  }

  /// <summary>
  /// Clean up any resources being used.
  /// </summary>
  protected override void Dispose( bool disposing )
  {
  	if( disposing )
  	{
    if (components != null) 
    {
    	components.Dispose();
    }
  	}
  	base.Dispose( disposing );
  }

  #region Windows Form Designer generated code
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {
  	System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
  	this.comboBox1 = new System.Windows.Forms.ComboBox();
  	this.comboBox2 = new System.Windows.Forms.ComboBox();
  	this.comboBox3 = new System.Windows.Forms.ComboBox();
  	this.comboBox4 = new System.Windows.Forms.ComboBox();
  	this.comboBox5 = new System.Windows.Forms.ComboBox();
  	this.comboBox6 = new System.Windows.Forms.ComboBox();
  	this.comboBox7 = new System.Windows.Forms.ComboBox();
  	this.comboBox8 = new System.Windows.Forms.ComboBox();
  	this.label1 = new System.Windows.Forms.Label();
  	this.label2 = new System.Windows.Forms.Label();
  	this.textBox1 = new System.Windows.Forms.TextBox();
  	this.label3 = new System.Windows.Forms.Label();
  	this.textBox2 = new System.Windows.Forms.TextBox();
  	this.pictureBox1 = new System.Windows.Forms.PictureBox();
  	this.panel1 = new System.Windows.Forms.Panel();
  	this.groupBox1 = new System.Windows.Forms.GroupBox();
  	this.panel1.SuspendLayout();
  	this.SuspendLayout();
  	// 
  	// comboBox1
  	// 
  	this.comboBox1.DropDownWidth = 320;
  	this.comboBox1.Items.AddRange(new object[] {
                 "Intel? Pentium? 4 Processor (2.80GHz, 533 FSB) [add $30]",
                 "Intel? Pentium? 4 Processor (3GHz, 800 FSB) [add $50]",
                 "Intel? Pentium? D 820 (2.8GHz, 800MHz FSB) [add $150]",
                 "Intel? Pentium? D 840 (3.2GHz, 800MHz FSB) [add $200]"});
  	this.comboBox1.Location = new System.Drawing.Point(24, 136);
  	this.comboBox1.Name = "comboBox1";
  	this.comboBox1.Size = new System.Drawing.Size(320, 21);
  	this.comboBox1.TabIndex = 0;
  	this.comboBox1.Text = "Select Processor Desired";
  	this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.Form1_Load);
  	// 
  	// comboBox2
  	// 
  	this.comboBox2.DropDownWidth = 300;
  	this.comboBox2.Items.AddRange(new object[] {
                 "512MB Dual Channel DDR SDRAM at 400MHz [add $39]",
                 "1GB Dual Channel DDR SDRAM at 533MHz [add $60]",
                 "2GB Dual Channel DDR2 SDRAM at 533MHz [add $220]",
                 "4GB Dual Channel DDR2 SDRAM at 533MHz [add $500]"});
  	this.comboBox2.Location = new System.Drawing.Point(24, 184);
  	this.comboBox2.Name = "comboBox2";
  	this.comboBox2.Size = new System.Drawing.Size(320, 21);
  	this.comboBox2.TabIndex = 1;
  	this.comboBox2.Text = "Select Memory Desired";
  	// 
  	// comboBox3
  	// 
  	this.comboBox3.DropDownWidth = 250;
  	this.comboBox3.Items.AddRange(new object[] {
                 "80GB Serial ATA (7200rpm) (80S) [add $39]",
                 "160GB Serial ATA (7200rpm) (160S) [add $49]",
                 "250GB Serial ATA (7200rpm) (250S) [add $100]",
                 "400GB Serial ATA (7200rpm) (400S) [add $310]"});
  	this.comboBox3.Location = new System.Drawing.Point(24, 232);
  	this.comboBox3.Name = "comboBox3";
  	this.comboBox3.Size = new System.Drawing.Size(320, 21);
  	this.comboBox3.TabIndex = 2;
  	this.comboBox3.Text = "Select Hard Drive Desired";
  	// 
  	// comboBox4
  	// 
  	this.comboBox4.DropDownWidth = 325;
  	this.comboBox4.Items.AddRange(new object[] {
                 "16X CD/DVD burner (DVD+/-RW) [add $20]",
                 "16x DVD-ROM Drive + 16x DVD+/-RW  [add $30]",
                 "24X CD-RW / DVD Combo Drive [add $40]\t\t",
                 "8X CD/DVD burner (DVD+/-RW) [add $50]"});
  	this.comboBox4.Location = new System.Drawing.Point(24, 328);
  	this.comboBox4.Name = "comboBox4";
  	this.comboBox4.Size = new System.Drawing.Size(320, 21);
  	this.comboBox4.TabIndex = 3;
  	this.comboBox4.Text = "Select CD-Rom Desired";
  	// 
  	// comboBox5
  	// 
  	this.comboBox5.DropDownWidth = 200;
  	this.comboBox5.Items.AddRange(new object[] {
                 "3.5 inches Floppy Drive 1.44MB [add $30]",
                 "None [add $0]"});
  	this.comboBox5.Location = new System.Drawing.Point(24, 280);
  	this.comboBox5.MaxDropDownItems = 5;
  	this.comboBox5.Name = "comboBox5";
  	this.comboBox5.Size = new System.Drawing.Size(320, 21);
  	this.comboBox5.TabIndex = 4;
  	this.comboBox5.Text = "Select Floppy Drive Desired";
  	// 
  	// comboBox6
  	// 
  	this.comboBox6.Items.AddRange(new object[] {
                 "USB Keyboard  [add $20] ",
                 "Wireless Keyboard [add $50]"});
  	this.comboBox6.Location = new System.Drawing.Point(24, 424);
  	this.comboBox6.Name = "comboBox6";
  	this.comboBox6.Size = new System.Drawing.Size(320, 21);
  	this.comboBox6.TabIndex = 5;
  	this.comboBox6.Text = "Select Keyboard Desired";
  	// 
  	// comboBox7
  	// 
  	this.comboBox7.DropDownWidth = 245;
  	this.comboBox7.Items.AddRange(new object[] {
                 "15 inch E153FP Analog Flat Panel [add $100] ",
                 "17 inch E173FP Analog Flat Panel [add $160]",
                 "20 inch UltraSharp? Widescreen Digital Flat Panel [add $270]",
                 "No Monitor [add $0]"});
  	this.comboBox7.Location = new System.Drawing.Point(24, 376);
  	this.comboBox7.Name = "comboBox7";
  	this.comboBox7.Size = new System.Drawing.Size(320, 21);
  	this.comboBox7.TabIndex = 6;
  	this.comboBox7.Text = "Select Monitor Desired";
  	// 
  	// comboBox8
  	// 
  	this.comboBox8.DropDownWidth = 250;
  	this.comboBox8.Items.AddRange(new object[] {
                 "Dell? 2-button USB mouse [add $19] ",
                 "Dell Optical USB Mouse [add $29]",
                 "Logitech? MX? 518 Optical Mouse [add $50]",
                 "No Mouse [add $0]"});
  	this.comboBox8.Location = new System.Drawing.Point(24, 472);
  	this.comboBox8.Name = "comboBox8";
  	this.comboBox8.Size = new System.Drawing.Size(320, 21);
  	this.comboBox8.TabIndex = 7;
  	this.comboBox8.Text = "Select Mouse Desired";
  	// 
  	// label1
  	// 
  	this.label1.Font = new System.Drawing.Font("Edwardianpt ITC", 25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  	this.label1.Location = new System.Drawing.Point(184, 8);
  	this.label1.Name = "label1";
  	this.label1.Size = new System.Drawing.Size(288, 48);
  	this.label1.TabIndex = 8;
  	this.label1.Text = "Customize Your Computer";
  	// 
  	// label2
  	// 
  	this.label2.Font = new System.Drawing.Font("Microsoft Serif", 8.6F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  	this.label2.Location = new System.Drawing.Point(88, 88);
  	this.label2.Name = "label2";
  	this.label2.Size = new System.Drawing.Size(72, 16);
  	this.label2.TabIndex = 9;
  	this.label2.Text = "First Name";
  	// 
  	// textBox1
  	// 
  	this.textBox1.AcceptsTab = true;
  	this.textBox1.Location = new System.Drawing.Point(168, 88);
  	this.textBox1.Name = "textBox1";
  	this.textBox1.Size = new System.Drawing.Size(120, 20);
  	this.textBox1.TabIndex = 10;
  	this.textBox1.Text = "";
  	// 
  	// label3
  	// 
  	this.label3.Font = new System.Drawing.Font("Microsoft Serif", 8.6F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  	this.label3.Location = new System.Drawing.Point(376, 88);
  	this.label3.Name = "label3";
  	this.label3.Size = new System.Drawing.Size(72, 16);
  	this.label3.TabIndex = 11;
  	this.label3.Text = "Last Name";
  	// 
  	// textBox2
  	// 
  	this.textBox2.AcceptsTab = true;
  	this.textBox2.Location = new System.Drawing.Point(448, 88);
  	this.textBox2.Name = "textBox2";
  	this.textBox2.Size = new System.Drawing.Size(128, 20);
  	this.textBox2.TabIndex = 12;
  	this.textBox2.Text = "";
  	// 
  	// pictureBox1
  	// 
  	this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image
  	this.pictureBox1.Location = new System.Drawing.Point(512, 8);
  	this.pictureBox1.Name = "pictureBox1";
  	this.pictureBox1.Size = new System.Drawing.Size(64, 64);
  	this.pictureBox1.TabIndex = 14;
  	this.pictureBox1.TabStop = false;
  	// 
  	// panel1
  	// 
  	this.panel1.AutoScroll = true;
  	this.panel1.Controls.Add(this.groupBox1);
  	this.panel1.Location = new System.Drawing.Point(384, 136);
  	this.panel1.Name = "panel1";
  	this.panel1.Size = new System.Drawing.Size(264, 368);
  	this.panel1.TabIndex = 15;
  	// 
  	// groupBox1
  	// 
  	this.groupBox1.Location = new System.Drawing.Point(0, 0);
  	this.groupBox1.Name = "groupBox1";
  	this.groupBox1.Size = new System.Drawing.Size(264, 368);
  	this.groupBox1.TabIndex = 0;
  	this.groupBox1.TabStop = false;
  	this.groupBox1.Text = "Items on your Cart";
  	// 
  	// Form1
  	// 
  	this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  	this.ClientSize = new System.Drawing.Size(680, 526);
  	this.Controls.Add(this.panel1);
  	this.Controls.Add(this.pictureBox1);
  	this.Controls.Add(this.textBox2);
  	this.Controls.Add(this.label3);
  	this.Controls.Add(this.textBox1);
  	this.Controls.Add(this.label2);
  	this.Controls.Add(this.label1);
  	this.Controls.Add(this.comboBox8);
  	this.Controls.Add(this.comboBox7);
  	this.Controls.Add(this.comboBox6);
  	this.Controls.Add(this.comboBox5);
  	this.Controls.Add(this.comboBox4);
  	this.Controls.Add(this.comboBox3);
  	this.Controls.Add(this.comboBox2);
  	this.Controls.Add(this.comboBox1);
  	this.Name = "Form1";
  	this.Text = "Form1";
  	this.Load += new System.EventHandler(this.Form1_Load);
  	this.panel1.ResumeLayout(false);
  	this.ResumeLayout(false);

  }
  #endregion

  /// <summary>
  /// The main entry point for the application.
  /// </summary>
  [STAThread]
  static void Main() 
  {
  	Application.Run(new Form1());
  }

  private void Form1_Load(object sender, System.EventArgs e)
  {
  	
  }

  

  

	}
}

  • 0

You may be new to Neowin (welcome) but you also appear to have very little knowledge of C#, as this is a basic task.

What you want to do is double click on any of the 8 combo boxes and write a single line of code to copy the current text of that control to the groupbox ( something like... Destination.Add((sender as ComboBox).Text); ). It doesn't matter whatsoever that the groupbox is hosted within another control. Then simply hookup the Click event of the other 7 combo boxes to the same function.

Done.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.