Hi


I am developing windows application using C#.There is combo box in the windows application ,once user select value it automatically generate pop window.I want to appear the new window at the right side lower corner in combo box.I tused below coding ,but it never works,please let me know how to do implement this.

Form F = new Form();
F.StartPosition = FormStartPosition.Manual;
F.Location = new Point(comboBox1.Location.X+comboBox1.Width, comboBox1.Location.X+comboBox1.Width+comboBox1.Height+comboBox1.Width);
F.Size = new Size(272, 100);
F.Show();

Thanks
Tank

Recommended Answers

All 3 Replies

Hi,

The given code is working fine. for testing, I have replaced the Point values with (100,100) and the window popped up. So please check these line of code

F.Location = new Point(comboBox1.Location.X+comboBox1.Width, comboBox1.Location.X+comboBox1.Width+comboBox1.Height+comboBox1.Width);

and verify the values of comboBox.

Update us the results.

Thank you.

.I want to appear the new window at the right side lower corner in combo box.

You have a mainForm. And then you have a comboBox on it. And when you select an item from it, a new form has to appear in the button-right corner, with some info in it. Am I correct?

I did a semple code how to position forms. This code bellow shows how to position a new form to all four corners of the mainForm:

namespace Feb13Exercise
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
            string[] array = { "top-left", "top-right", "bottom-left", "bottom-right" };
            this.comboBox1.Items.AddRange(array);
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.comboBox1.SelectedIndex > -1)
            {
                string value = this.comboBox1.GetItemText(this.comboBox1.SelectedItem);
                if (value != String.Empty)
                {
                    Form2 f2 = new Form2();
                    f2.Size = new Size(250, 150);
                    int[]xy = CalculateFormPosition(value, f2.Size.Width, f2.Size.Height);
                    f2.StartPosition = FormStartPosition.Manual;
                    f2.Location = new Point(xy[0], xy[1]);
                    f2.Show(this);
                }
            }
        }

        private int[] CalculateFormPosition(string value, int f2Width, int f2Height)
        {
            int dev = 20;
            int x = this.Location.X;
            int y = this.Location.Y;
            switch (value)
            {
                case "top-left":
                    {
                        x = x + dev;
                        y = y + dev + dev;
                        break;
                    }
                case "top-right":
                    {
                        x = (x + this.Width - dev) - f2Width;
                        y = y + dev + dev;
                        break;
                    }
                case "bottom-left":
                    {
                        x = x + dev;
                        y = (y + this.Height - dev) - f2Height;
                        break;
                    }
                case "bottom-right":
                    {
                        x = (x + this.Width - dev) - f2Width;
                        y = (y + this.Height - dev) - f2Height;
                        break;
                    }
            }
            return new int[] { x, y };
        }
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.