Click here to Skip to main content
11,580,580 members (66,998 online)
Click here to Skip to main content

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

, 7 May 2011 CPOL 3K 1
Rate this:
Please Sign up or sign in to vote.
using System;using System.Windows.Forms;namespace WindowsFormsApplication1{ public partial class Form1 : Form { private Panel panel1; private ComboBox comboBox1; public Form1() { InitializeComponent(); } ...
using System;
using System.Windows.Forms;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private Panel panel1;
        private ComboBox comboBox1;
 
        public Form1()
        {
            InitializeComponent();
        }
 
        private void InitializeComponent()
        {
            this.panel1 = new System.Windows.Forms.Panel();
            this.comboBox1 = new System.Windows.Forms.ComboBox();
            this.SuspendLayout();
            // 
            // panel1
            // 
            this.panel1.BackColor = System.Drawing.SystemColors.ControlDarkDark;
            this.panel1.Location = new System.Drawing.Point(47, 65);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(200, 100);
            this.panel1.TabIndex = 0;
            // 
            // comboBox1
            // 
            this.comboBox1.FormattingEnabled = true;
            this.comboBox1.Location = new System.Drawing.Point(126, 187);
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new System.Drawing.Size(121, 21);
            this.comboBox1.TabIndex = 1;
            this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
            // 
            // Form1
            // 
            this.ClientSize = new System.Drawing.Size(298, 264);
            this.Controls.Add(this.comboBox1);
            this.Controls.Add(this.panel1);
            this.Name = "Form1";
            this.ResumeLayout(false);
 
        }
 
        protected override void OnLoad(EventArgs e)
        {
            string[] DockStyles = Enum.GetNames(typeof(MyDock));
            comboBox1.Items.AddRange(DockStyles);
            base.OnLoad(e);
        }
 
        private enum MyDock
        {
            None,
            Top,
            Bottom,
            Left,
            Right,
            Fill
        }
 
        private DockStyle Style(string style)
        {
            return (DockStyle)Enum.Parse(typeof(MyDock), style);
        }
 
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            panel1.Dock = Style(comboBox1.SelectedItem.ToString());
            comboBox1.BringToFront();
        }
    }
}

License

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

Share

About the Author

charles henington
United States United States
I do not claim to be wrong! I just rarely ever write.

You may also be interested in...

Comments and Discussions

 
GeneralYour not very bright are you? Pin
charles henington15-May-11 4:07
membercharles henington15-May-11 4:07 
Your not very bright are you?
GeneralReason for my vote of 2 It does not make much sense to uses ... Pin
Philippe Mori14-May-11 10:15
memberPhilippe Mori14-May-11 10:15 
GeneralReason for my vote of 5 Very elegant and practical solution!... Pin
DrABELL10-May-11 10:33
memberDrABELL10-May-11 10:33 

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
Web04 | 2.8.150603.1 | Last Updated 7 May 2011
Article Copyright 2011 by charles henington
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid