Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Pass parameters from designer to autogenerated controls
 

Pass parameters from designer to autogenerated controls

hi,
the situation is:
i made a UserControl and the UserControl is listed in the toolbox,

Code Snippet

public partial class MyControl : UserControl

{

public MyControl()

{
InitializeComponent();
}



public MyControl(Boolean x)

{
InitializeComponent();
}

}


now i want is, if i drag in the designer from the toolbox MyControl on a Form, that the second constructor should be called with pre defined parameter.
For example that i can define some where how to retrive the value to pass and the design generator create the right code.
Coke-22  Friday, August 24, 2007 3:40 PM

Hi, Coke-22,

Based on my understanding, you want to call the second constructor while dragging the user control to designer, don't you?

However, I think it is not possible to choose that constructor while dragging from toolbox to designer, because it is not possible to build and pass the parameters at that time.

But if you want to change some properties during design time, you can try to use property window(F4), or use the smart tag technology.

Here is a good sample for how to make a Smart Tag http://msdn.microsoft.com/msdnmag/issues/05/07/DesignerActions/

Hope this helps,

Regards

Yu Guo â€?MSFT  Wednesday, August 29, 2007 3:18 AM
No, but found a work arround.
You can define a property that takes a boolen for example and in the set (setter) part u can check if value is true then make all those things u want to make in the contructor with additional paramters. and if this should have behavour like an constructor make sure to run code only once.

smart tags was to complicated :-).
Coke-22  Thursday, September 06, 2007 1:44 PM

Hi, Coke-22,

Based on my understanding, you want to call the second constructor while dragging the user control to designer, don't you?

However, I think it is not possible to choose that constructor while dragging from toolbox to designer, because it is not possible to build and pass the parameters at that time.

But if you want to change some properties during design time, you can try to use property window(F4), or use the smart tag technology.

Here is a good sample for how to make a Smart Tag http://msdn.microsoft.com/msdnmag/issues/05/07/DesignerActions/

Hope this helps,

Regards

Yu Guo â€?MSFT  Wednesday, August 29, 2007 3:18 AM
hi,
i was looking for

By Yu Guo - MSFT

call the second constructor while dragging the user control to designer



Coke-22  Friday, August 31, 2007 8:10 AM

Hi, Coke-22,

As I answered in my last post,

" I think it is not possible to choose that constructor while dragging from toolbox to designer"

Orcould youtell me how can you define the parameter while you are dragging?

Regards

Yu Guo â€?MSFT  Friday, August 31, 2007 8:22 AM
No, but found a work arround.
You can define a property that takes a boolen for example and in the set (setter) part u can check if value is true then make all those things u want to make in the contructor with additional paramters. and if this should have behavour like an constructor make sure to run code only once.

smart tags was to complicated :-).
Coke-22  Thursday, September 06, 2007 1:44 PM

You can use google to search for other answers

Custom Search

More Threads

• Remove default ToolStripItems from ToolStrip Designer
• How to design a form on Blend and use it in a VB 2005 project?
• Error Message When Trying to Create a Data Source for a Compact Data Base in VS 2008
• currencyformat in textbox winforms
• listBox or listView: 1 item=Multiple rows with formatting
• Image issue
• Cannot publish because a project failed to build.
• How to quick tab to a textbox with ALT?
• Can't design a User control if not inherited directly from UserControl
• Enabling Design Time Events