Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Showing the selected rectangle in the Designer
 

Showing the selected rectangle in the Designer

Hi,

Although I'm developing an Add-In, I'm thinking my question is more appropriate for this forum rather than Visual Studio Extensibility. If not, let me know.

Anyway, when I have a form designer shown and active (let's assume it's blank at this point, with no controls placed on it), and I take my mouse and click down at a certain point and then drag it down and to the right, a temporary rectangle is shown and grows while I'm dragging it. When I stop dragging (lift up on the right mouse button), the temporary rectangle disappears. However, the coordinates for the rectangle (Location and Size)still appear on the right side of the IDE status bar.

Question: Does anyone know how I can programmatically get that rectangle to remain on the design surface?

Here's my reason for wanting to do so if it helps. My Add-In displays a custom tool window that allows me to automatically generate a set of controls for the form. I'd like to be able to use the mouse to draw a rectangle on the form to define the area on the form for which the generated controls will be placed. I'm not particular about the looks of the rectangle as long as I can define where the controls will be placed. I'd need to be able to remove the rectangle programmatically as well.

I have figured out away to grab the Location and Size info displayed in the IDE status bar. Don't know if that is beneficial or not.

So, any ideas?

Thanks,
Greg
GregVance  Saturday, April 11, 2009 7:13 PM

Hi GregVance,

Welcome to MSDN, here is the correct forum for you.

First, base on my experience, that rectangle is not exactly existed, when you click down the left button of the mouse on the form and drag, the rectangle show the area you are going to select controls on that form. All the controls on that form whose border is partly inside the area will be selected. You cannot set it remain visible in VS designer.

Second, the rectangle size shown in status bar of VS designer won't disappear immediately when you release mouse is because that information is not refreshed. When you click something else such as property grid, it will disappear.

Third, as for your purpose, you can use a GroupBox instead. GroupBox is widely used to group control which will give user good experience.

If you have anything unclear, please feel free to tell me.

Sincerely,
Kira Qian


Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Tuesday, April 14, 2009 3:42 AM
Hi,

Thanks for taking the time to respond. I understand that the drawn rectangle defines the area where any controls that exist on the form will be selected. However, I'm specifically looking for a way to simulate the same thing but have the rectangle remain visible afterwards. My Add-In will be adding controls to the form that might or might not be added to a container control. If a container control is selected, then the Add-In will add the control(s) to that container control. If no container control is selected, then the Add-In will add the control(s) to the form. It will be up to the user of the Add-In whether to place the controls inside a GroupBox, or other container control, or directly on the form.

Thanks,
Greg
GregVance  Tuesday, April 14, 2009 9:53 AM

Hi GregVance,

I have searched many information through but without lucky, no document show it can show the rectangle at design time.

I found the Panel control is more suitable than GroupBox. If you put a GroupBox on the form to define the area, GroupBox will be shown at run time. But if you use a Panel, it shown nothing at run time when its BorderStyle property is none.

I hope this can help you.

Sincerely,
Kira Qian


Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Thursday, April 16, 2009 2:25 AM
Hi Kira,

Thanks for taking the time to research it. Since I'm able to access the Location and Size from the IDE status bar, I decided to just use GDI to draw a rectangle on the formbased on thestatus bar info. It's not ideal for what I was looking/hoping for, but it will do.

Thanks again,
Greg
GregVance  Thursday, April 16, 2009 6:29 AM

You can use google to search for other answers

Custom Search

More Threads

• Open Form in VS2005 takes a LONG time
• MDI CHILD QUESTIOn
• type typeEditor
• How can I search the data in a dataset?
• Stored procedure vs Query in VB.Net and backend - SQL Server 2000?
• Change background image of MDI form
• Changing focus after cancelling validation
• Submitting to database
• Extensibility DTE Object Unavailable (error) in WinForms Design
• How do you implement the layout commands for IDesignerHost?