Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Simple method using Enum.Parse to change the dockstyle to control on form with combobox

, 9 May 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
ComboBox items do not have to be strings.The combobox calls ToString on each object in Items so simply add the enum values to the combobox.using System;using System.Drawing;using System.Windows.Forms;namespace Anchor_Form{ public class Form1 : Form { public...
ComboBox items do not have to be strings.
The combobox calls ToString on each object in Items so simply add the enum values to the combobox.

using System;
using System.Drawing;
using System.Windows.Forms;

namespace Anchor_Form
    public class Form1 : Form
		public Form1()
			foreach (DockStyle style in Enum.GetValues(typeof(DockStyle)))
			comboBox1.SelectedIndex = 0;
		private void InitializeComponent()
			panel1		= new Panel();
			comboBox1	= new ComboBox();
			// panel1
			panel1.BackColor = SystemColors.ControlDarkDark;
			panel1.Location = new Point(43, 60);
			panel1.Name = "panel1";
			panel1.Size = new Size(200, 100);
			panel1.TabIndex = 0;
			// comboBox1
			comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
			comboBox1.Location = new Point(61, 178);
			comboBox1.Name = "comboBox1";
			comboBox1.Size = new Size(121, 21);
			comboBox1.TabIndex = 1;
			comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
			// Form1
			AutoScaleDimensions = new SizeF(6F, 13F);
			AutoScaleMode = AutoScaleMode.Font;
			ClientSize = new Size(284, 264);
			Name = "Form1";
			Text = "Form1";
		private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
			panel1.Dock = (DockStyle)comboBox1.SelectedItem;
		Panel		panel1;
		ComboBox	comboBox1;


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior) Shaw Inspection Systems Ltd
United Kingdom United Kingdom
No Biography provided

Comments and Discussions

GeneralReason for my vote of 4 Good solution when localization is n... PinmemberPhilippe Mori14-May-11 11:14 
GeneralAs Enum.Parse is not the best solution for this problem, the... PinmemberPhilippe Mori14-May-11 11:13 
GeneralReason for my vote of 1 The point was a way using Enum.Parse... Pinmembercharles henington14-May-11 6:50 
Reason for my vote of 1
The point was a way using Enum.Parse not a simple DockStyle thanks for the effort though this might be a good solution if not using Enum.Parse thanks for the post

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150327.1 | Last Updated 10 May 2011
Article Copyright 2011 by jarvisa
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid