PC Review


Reply
Thread Tools Rate Thread

Design Time Controls

 
 
Derek Hart
Guest
Posts: n/a
 
      8th Jun 2009
Build a usercontrol that I want developers to use in Visual Studio. I need
to pass some variables into the control at design time, so the property grid
can pop up with specific properties. How could I pass, for example, the name
of the form I am on (at design time), to the property?


 
Reply With Quote
 
 
 
 
Jack Jackson
Guest
Posts: n/a
 
      8th Jun 2009
On Sun, 7 Jun 2009 17:37:59 -0700, "Derek Hart" <(E-Mail Removed)>
wrote:

>Build a usercontrol that I want developers to use in Visual Studio. I need
>to pass some variables into the control at design time, so the property grid
>can pop up with specific properties. How could I pass, for example, the name
>of the form I am on (at design time), to the property?
>


Why don't you just back up through the Parent properties until you get
to the form?
 
Reply With Quote
 
Derek Hart
Guest
Posts: n/a
 
      8th Jun 2009
I'm just not sure where to do this... the user control is self contained...
how can I talk to the live form at design time? For example, here is the
property I am modifying on an inherited TextBox: I need to pass the name of
the form at design time so the custom UITypeEditor has the name to get the
correct data to return to the UITypeEditor in the property.

<CategoryAttribute("Design"), _
DefaultValueAttribute(GetType(String), ""), _
DescriptionAttribute("Name of the data field."), _
Editor(GetType(MergeFieldNameBuilder),
GetType(System.Drawing.Design.UITypeEditor))> _
Public Property DataField() As String
Get
Return _DataField
End Get
Set(ByVal value As String)
_DataField = value
End Set
End Property


"Jack Jackson" <jjackson-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Sun, 7 Jun 2009 17:37:59 -0700, "Derek Hart" <(E-Mail Removed)>
> wrote:
>
>>Build a usercontrol that I want developers to use in Visual Studio. I need
>>to pass some variables into the control at design time, so the property
>>grid
>>can pop up with specific properties. How could I pass, for example, the
>>name
>>of the form I am on (at design time), to the property?
>>

>
> Why don't you just back up through the Parent properties until you get
> to the form?



 
Reply With Quote
 
Derek Hart
Guest
Posts: n/a
 
      8th Jun 2009
I think I have found something that puts me on the right track. This will
give me the name of the form inside the property:

Return Site.Container.Components(0).Site.Name

I can even get to the properties with correct casting.

Return CType(Site.Container.Components(0), System.Windows.Forms.Form).Text

Any comments on if this is the best way to get to properties at design time?







"Derek Hart" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm just not sure where to do this... the user control is self
> contained... how can I talk to the live form at design time? For example,
> here is the property I am modifying on an inherited TextBox: I need to
> pass the name of the form at design time so the custom UITypeEditor has
> the name to get the correct data to return to the UITypeEditor in the
> property.
>
> <CategoryAttribute("Design"), _
> DefaultValueAttribute(GetType(String), ""), _
> DescriptionAttribute("Name of the data field."), _
> Editor(GetType(MergeFieldNameBuilder),
> GetType(System.Drawing.Design.UITypeEditor))> _
> Public Property DataField() As String
> Get
> Return _DataField
> End Get
> Set(ByVal value As String)
> _DataField = value
> End Set
> End Property
>
>
> "Jack Jackson" <jjackson-(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> On Sun, 7 Jun 2009 17:37:59 -0700, "Derek Hart" <(E-Mail Removed)>
>> wrote:
>>
>>>Build a usercontrol that I want developers to use in Visual Studio. I
>>>need
>>>to pass some variables into the control at design time, so the property
>>>grid
>>>can pop up with specific properties. How could I pass, for example, the
>>>name
>>>of the form I am on (at design time), to the property?
>>>

>>
>> Why don't you just back up through the Parent properties until you get
>> to the form?

>
>



 
Reply With Quote
 
Jack Jackson
Guest
Posts: n/a
 
      9th Jun 2009
It looks like that would work.

I still don't see why you don't just use (in some method in your
UserControl) Me.FindForm() or use Me.Parent to back up through the
parents of your UserControl until you get to the form.

Even in the IDE, each control is added to its parent's Controls
collection, so starting with any control you can look through the tree
of all controls.

On Mon, 8 Jun 2009 10:13:27 -0700, "Derek Hart" <(E-Mail Removed)>
wrote:

>I think I have found something that puts me on the right track. This will
>give me the name of the form inside the property:
>
>Return Site.Container.Components(0).Site.Name
>
>I can even get to the properties with correct casting.
>
>Return CType(Site.Container.Components(0), System.Windows.Forms.Form).Text
>
>Any comments on if this is the best way to get to properties at design time?
>
>
>
>
>
>
>
>"Derek Hart" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> I'm just not sure where to do this... the user control is self
>> contained... how can I talk to the live form at design time? For example,
>> here is the property I am modifying on an inherited TextBox: I need to
>> pass the name of the form at design time so the custom UITypeEditor has
>> the name to get the correct data to return to the UITypeEditor in the
>> property.
>>
>> <CategoryAttribute("Design"), _
>> DefaultValueAttribute(GetType(String), ""), _
>> DescriptionAttribute("Name of the data field."), _
>> Editor(GetType(MergeFieldNameBuilder),
>> GetType(System.Drawing.Design.UITypeEditor))> _
>> Public Property DataField() As String
>> Get
>> Return _DataField
>> End Get
>> Set(ByVal value As String)
>> _DataField = value
>> End Set
>> End Property
>>
>>
>> "Jack Jackson" <jjackson-(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> On Sun, 7 Jun 2009 17:37:59 -0700, "Derek Hart" <(E-Mail Removed)>
>>> wrote:
>>>
>>>>Build a usercontrol that I want developers to use in Visual Studio. I
>>>>need
>>>>to pass some variables into the control at design time, so the property
>>>>grid
>>>>can pop up with specific properties. How could I pass, for example, the
>>>>name
>>>>of the form I am on (at design time), to the property?
>>>>
>>>
>>> Why don't you just back up through the Parent properties until you get
>>> to the form?

>>
>>

>

 
Reply With Quote
 
Derek Hart
Guest
Posts: n/a
 
      10th Jun 2009
Jack,

I have a class that just inherits a control. Just for testing, I placed the
CType down below. This class is not part of a usercontrol directly. It is
just a textbox that is used inside the IDE toolbox. In the "Get" part of the
property I tried looking at the parent, but I don't really have access to
this. Do you know how that might look?

<ToolboxBitmapAttribute(GetType(TextBox))> _

Public Class MyTextBox

Inherits TextBox

Private _DataField As String = ""





<CategoryAttribute("Design"), _

DefaultValueAttribute(GetType(String), ""), _

DescriptionAttribute("Name of the data field."), _

Editor(GetType(MergeFieldNameBuilder),
GetType(System.Drawing.Design.UITypeEditor))> _

Public Property DataField() As String

Get

Return CType(Site.Container.Components(0),
System.Windows.Forms.Form).Text
End Get

Set(ByVal value As String)

_DataField = value

End Set

End Property

End Class



Derek


"Jack Jackson" <jjackson-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> It looks like that would work.
>
> I still don't see why you don't just use (in some method in your
> UserControl) Me.FindForm() or use Me.Parent to back up through the
> parents of your UserControl until you get to the form.
>
> Even in the IDE, each control is added to its parent's Controls
> collection, so starting with any control you can look through the tree
> of all controls.
>
> On Mon, 8 Jun 2009 10:13:27 -0700, "Derek Hart" <(E-Mail Removed)>
> wrote:
>
>>I think I have found something that puts me on the right track. This will
>>give me the name of the form inside the property:
>>
>>Return Site.Container.Components(0).Site.Name
>>
>>I can even get to the properties with correct casting.
>>
>>Return CType(Site.Container.Components(0), System.Windows.Forms.Form).Text
>>
>>Any comments on if this is the best way to get to properties at design
>>time?
>>
>>
>>
>>
>>
>>
>>
>>"Derek Hart" <(E-Mail Removed)> wrote in message
>>news:(E-Mail Removed)...
>>> I'm just not sure where to do this... the user control is self
>>> contained... how can I talk to the live form at design time? For
>>> example,
>>> here is the property I am modifying on an inherited TextBox: I need to
>>> pass the name of the form at design time so the custom UITypeEditor has
>>> the name to get the correct data to return to the UITypeEditor in the
>>> property.
>>>
>>> <CategoryAttribute("Design"), _
>>> DefaultValueAttribute(GetType(String), ""), _
>>> DescriptionAttribute("Name of the data field."), _
>>> Editor(GetType(MergeFieldNameBuilder),
>>> GetType(System.Drawing.Design.UITypeEditor))> _
>>> Public Property DataField() As String
>>> Get
>>> Return _DataField
>>> End Get
>>> Set(ByVal value As String)
>>> _DataField = value
>>> End Set
>>> End Property
>>>
>>>
>>> "Jack Jackson" <jjackson-(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> On Sun, 7 Jun 2009 17:37:59 -0700, "Derek Hart" <(E-Mail Removed)>
>>>> wrote:
>>>>
>>>>>Build a usercontrol that I want developers to use in Visual Studio. I
>>>>>need
>>>>>to pass some variables into the control at design time, so the property
>>>>>grid
>>>>>can pop up with specific properties. How could I pass, for example, the
>>>>>name
>>>>>of the form I am on (at design time), to the property?
>>>>>
>>>>
>>>> Why don't you just back up through the Parent properties until you get
>>>> to the form?
>>>
>>>

>>



 
Reply With Quote
 
Jack Jackson
Guest
Posts: n/a
 
      10th Jun 2009
What does "I don't really have access to this" mean?

If you want the Get of the DataField property to return the form's
Text property, I would try:

Get
Dim frm As System.Windows.Forms.Form = Me.FindForm()

Return If(frm Is Nothing, '', frm.Text)
End Get


On Tue, 9 Jun 2009 18:52:05 -0700, "Derek Hart" <(E-Mail Removed)>
wrote:

>Jack,
>
>I have a class that just inherits a control. Just for testing, I placed the
>CType down below. This class is not part of a usercontrol directly. It is
>just a textbox that is used inside the IDE toolbox. In the "Get" part of the
>property I tried looking at the parent, but I don't really have access to
>this. Do you know how that might look?
>
><ToolboxBitmapAttribute(GetType(TextBox))> _
>
>Public Class MyTextBox
>
> Inherits TextBox
>
> Private _DataField As String = ""
>
>
>
>
>
> <CategoryAttribute("Design"), _
>
> DefaultValueAttribute(GetType(String), ""), _
>
> DescriptionAttribute("Name of the data field."), _
>
> Editor(GetType(MergeFieldNameBuilder),
>GetType(System.Drawing.Design.UITypeEditor))> _
>
> Public Property DataField() As String
>
> Get
>
> Return CType(Site.Container.Components(0),
>System.Windows.Forms.Form).Text
> End Get
>
> Set(ByVal value As String)
>
> _DataField = value
>
> End Set
>
> End Property
>
>End Class
>
>
>
>Derek
>
>
>"Jack Jackson" <jjackson-(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>> It looks like that would work.
>>
>> I still don't see why you don't just use (in some method in your
>> UserControl) Me.FindForm() or use Me.Parent to back up through the
>> parents of your UserControl until you get to the form.
>>
>> Even in the IDE, each control is added to its parent's Controls
>> collection, so starting with any control you can look through the tree
>> of all controls.
>>
>> On Mon, 8 Jun 2009 10:13:27 -0700, "Derek Hart" <(E-Mail Removed)>
>> wrote:
>>
>>>I think I have found something that puts me on the right track. This will
>>>give me the name of the form inside the property:
>>>
>>>Return Site.Container.Components(0).Site.Name
>>>
>>>I can even get to the properties with correct casting.
>>>
>>>Return CType(Site.Container.Components(0), System.Windows.Forms.Form).Text
>>>
>>>Any comments on if this is the best way to get to properties at design
>>>time?
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>"Derek Hart" <(E-Mail Removed)> wrote in message
>>>news:(E-Mail Removed)...
>>>> I'm just not sure where to do this... the user control is self
>>>> contained... how can I talk to the live form at design time? For
>>>> example,
>>>> here is the property I am modifying on an inherited TextBox: I need to
>>>> pass the name of the form at design time so the custom UITypeEditor has
>>>> the name to get the correct data to return to the UITypeEditor in the
>>>> property.
>>>>
>>>> <CategoryAttribute("Design"), _
>>>> DefaultValueAttribute(GetType(String), ""), _
>>>> DescriptionAttribute("Name of the data field."), _
>>>> Editor(GetType(MergeFieldNameBuilder),
>>>> GetType(System.Drawing.Design.UITypeEditor))> _
>>>> Public Property DataField() As String
>>>> Get
>>>> Return _DataField
>>>> End Get
>>>> Set(ByVal value As String)
>>>> _DataField = value
>>>> End Set
>>>> End Property
>>>>
>>>>
>>>> "Jack Jackson" <jjackson-(E-Mail Removed)> wrote in message
>>>> news:(E-Mail Removed)...
>>>>> On Sun, 7 Jun 2009 17:37:59 -0700, "Derek Hart" <(E-Mail Removed)>
>>>>> wrote:
>>>>>
>>>>>>Build a usercontrol that I want developers to use in Visual Studio. I
>>>>>>need
>>>>>>to pass some variables into the control at design time, so the property
>>>>>>grid
>>>>>>can pop up with specific properties. How could I pass, for example, the
>>>>>>name
>>>>>>of the form I am on (at design time), to the property?
>>>>>>
>>>>>
>>>>> Why don't you just back up through the Parent properties until you get
>>>>> to the form?
>>>>
>>>>
>>>

>

 
Reply With Quote
 
Derek Hart
Guest
Posts: n/a
 
      10th Jun 2009
Me.FindForm() just has an error "FindForm is not a member of
myControls.TextBox".

Do you have specific code for this?

"Jack Jackson" <jjackson-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> What does "I don't really have access to this" mean?
>
> If you want the Get of the DataField property to return the form's
> Text property, I would try:
>
> Get
> Dim frm As System.Windows.Forms.Form = Me.FindForm()
>
> Return If(frm Is Nothing, '', frm.Text)
> End Get
>
>
> On Tue, 9 Jun 2009 18:52:05 -0700, "Derek Hart" <(E-Mail Removed)>
> wrote:
>
>>Jack,
>>
>>I have a class that just inherits a control. Just for testing, I placed
>>the
>>CType down below. This class is not part of a usercontrol directly. It is
>>just a textbox that is used inside the IDE toolbox. In the "Get" part of
>>the
>>property I tried looking at the parent, but I don't really have access to
>>this. Do you know how that might look?
>>
>><ToolboxBitmapAttribute(GetType(TextBox))> _
>>
>>Public Class MyTextBox
>>
>> Inherits TextBox
>>
>> Private _DataField As String = ""
>>
>>
>>
>>
>>
>> <CategoryAttribute("Design"), _
>>
>> DefaultValueAttribute(GetType(String), ""), _
>>
>> DescriptionAttribute("Name of the data field."), _
>>
>> Editor(GetType(MergeFieldNameBuilder),
>>GetType(System.Drawing.Design.UITypeEditor))> _
>>
>> Public Property DataField() As String
>>
>> Get
>>
>> Return CType(Site.Container.Components(0),
>>System.Windows.Forms.Form).Text
>> End Get
>>
>> Set(ByVal value As String)
>>
>> _DataField = value
>>
>> End Set
>>
>> End Property
>>
>>End Class
>>
>>
>>
>>Derek
>>
>>
>>"Jack Jackson" <jjackson-(E-Mail Removed)> wrote in message
>>news:(E-Mail Removed)...
>>> It looks like that would work.
>>>
>>> I still don't see why you don't just use (in some method in your
>>> UserControl) Me.FindForm() or use Me.Parent to back up through the
>>> parents of your UserControl until you get to the form.
>>>
>>> Even in the IDE, each control is added to its parent's Controls
>>> collection, so starting with any control you can look through the tree
>>> of all controls.
>>>
>>> On Mon, 8 Jun 2009 10:13:27 -0700, "Derek Hart" <(E-Mail Removed)>
>>> wrote:
>>>
>>>>I think I have found something that puts me on the right track. This
>>>>will
>>>>give me the name of the form inside the property:
>>>>
>>>>Return Site.Container.Components(0).Site.Name
>>>>
>>>>I can even get to the properties with correct casting.
>>>>
>>>>Return CType(Site.Container.Components(0),
>>>>System.Windows.Forms.Form).Text
>>>>
>>>>Any comments on if this is the best way to get to properties at design
>>>>time?
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>"Derek Hart" <(E-Mail Removed)> wrote in message
>>>>news:(E-Mail Removed)...
>>>>> I'm just not sure where to do this... the user control is self
>>>>> contained... how can I talk to the live form at design time? For
>>>>> example,
>>>>> here is the property I am modifying on an inherited TextBox: I need to
>>>>> pass the name of the form at design time so the custom UITypeEditor
>>>>> has
>>>>> the name to get the correct data to return to the UITypeEditor in the
>>>>> property.
>>>>>
>>>>> <CategoryAttribute("Design"), _
>>>>> DefaultValueAttribute(GetType(String), ""), _
>>>>> DescriptionAttribute("Name of the data field."), _
>>>>> Editor(GetType(MergeFieldNameBuilder),
>>>>> GetType(System.Drawing.Design.UITypeEditor))> _
>>>>> Public Property DataField() As String
>>>>> Get
>>>>> Return _DataField
>>>>> End Get
>>>>> Set(ByVal value As String)
>>>>> _DataField = value
>>>>> End Set
>>>>> End Property
>>>>>
>>>>>
>>>>> "Jack Jackson" <jjackson-(E-Mail Removed)> wrote in message
>>>>> news:(E-Mail Removed)...
>>>>>> On Sun, 7 Jun 2009 17:37:59 -0700, "Derek Hart"
>>>>>> <(E-Mail Removed)>
>>>>>> wrote:
>>>>>>
>>>>>>>Build a usercontrol that I want developers to use in Visual Studio. I
>>>>>>>need
>>>>>>>to pass some variables into the control at design time, so the
>>>>>>>property
>>>>>>>grid
>>>>>>>can pop up with specific properties. How could I pass, for example,
>>>>>>>the
>>>>>>>name
>>>>>>>of the form I am on (at design time), to the property?
>>>>>>>
>>>>>>
>>>>>> Why don't you just back up through the Parent properties until you
>>>>>> get
>>>>>> to the form?
>>>>>
>>>>>
>>>>

>>



 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      10th Jun 2009
Derek Hart wrote:
> Me.FindForm() just has an error "FindForm is not a member of
> myControls.TextBox".
>
> Do you have specific code for this?


Are you sure it's a Winforms application? ;-) Every control has a FindForm
method because it's a member of System.Windows.Forms.Control. What's your
class' base class?


Armin

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot move controls at design-time Alper Özgür Microsoft ASP .NET 3 23rd Jun 2006 05:27 PM
Design time writing in Controls =?Utf-8?B?cmV2Y29t?= Microsoft Dot NET Framework Forms 0 11th Oct 2005 12:09 PM
Re: Controls Design time Cor Microsoft Dot NET 0 25th Mar 2004 09:19 AM
Help! Refresh controls at design time. nobody Microsoft ASP .NET 2 17th Mar 2004 06:04 AM
Design time controls news.microsoft.com Microsoft Dot NET Framework Forms 0 1st Nov 2003 02:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:45 PM.