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

Dani AI

Generated

The problem is almost always coordinate space and a small typo. used the comboBox location values directly (which are control‑relative) and accidentally reused Location.X for the Y coordinate, so the popup went off where you did not expect. ’s (100,100) test proved the form will appear when given valid screen coordinates. ’s sample demonstrates anchoring to the main form; that works too, but a simpler and more robust approach is to compute the combo box corner in screen coordinates and place the popup relative to that point.

Example (compute bottom‑right anchor, keep popup on screen):

var popupForm = new Form();
popupForm.FormBorderStyle = FormBorderStyle.FixedToolWindow;
popupForm.SetBounds(0, 0, 272, 100, BoundsSpecified.Size);

// get bottom-right of the combo box in screen coordinates
Point comboTopLeft = comboBox1.PointToScreen(Point.Empty);
int anchorX = comboTopLeft.X + comboBox1.Width;
int anchorY = comboTopLeft.Y + comboBox1.Height;

// place popup to the right and aligned to the combo's bottom
int posX = anchorX;
int posY = anchorY - popupForm.Height;

// make sure popup stays inside the working area for the monitor it's on
Rectangle work = Screen.FromControl(comboBox1).WorkingArea;
if (posX + popupForm.Width > work.Right) posX = work.Right - popupForm.Width;
if (posY < work.Top) posY = anchorY; // fallback below combo

popupForm.DesktopLocation = new Point(posX, posY);
popupForm.Show();

Troubleshooting tips: always convert control coordinates to screen coordinates with PointToScreen; prefer Screen.FromControl/WorkingArea to clamp to the visible monitor; test with multiple monitors and different DPI/scaling settings. If the popup should not steal focus or should behave like a drop‑down, consider a borderless tool window, ToolStripDropDown, or creating a non-activating window. For reference on converting control coordinates, see the Control.PointToScreen documentation: Control.PointToScreen.

This approach avoids using parent form coordinates directly and prevents the common off-screen placement you saw in the original attempt.

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.