Home All Groups Group Topic Archive Search About
Author
8 Jun 2009 12:37 AM
Derek Hart
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?

Author
8 Jun 2009 3:24 AM
Jack Jackson
On Sun, 7 Jun 2009 17:37:59 -0700, "Derek Hart" <derekmh***@yahoo.com>
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?
Are all your drivers up to date? click for free checkup

Author
8 Jun 2009 4:04 PM
Derek Hart
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


Show quoteHide quote
"Jack Jackson" <jjackson-***@cinnovations.net> wrote in message
news:qv0p25tm7q3nvbg9t6q1kqqlak6a5f22bk@4ax.com...
> On Sun, 7 Jun 2009 17:37:59 -0700, "Derek Hart" <derekmh***@yahoo.com>
> 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?
Author
8 Jun 2009 5:13 PM
Derek Hart
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?







Show quoteHide quote
"Derek Hart" <derekmh***@yahoo.com> wrote in message
news:eccWXLF6JHA.1432@TK2MSFTNGP02.phx.gbl...
> 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-***@cinnovations.net> wrote in message
> news:qv0p25tm7q3nvbg9t6q1kqqlak6a5f22bk@4ax.com...
>> On Sun, 7 Jun 2009 17:37:59 -0700, "Derek Hart" <derekmh***@yahoo.com>
>> 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?
>
>
Author
9 Jun 2009 5:50 AM
Jack Jackson
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.

Show quoteHide quote
On Mon, 8 Jun 2009 10:13:27 -0700, "Derek Hart" <derekmh***@yahoo.com>
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" <derekmh***@yahoo.com> wrote in message
>news:eccWXLF6JHA.1432@TK2MSFTNGP02.phx.gbl...
>> 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-***@cinnovations.net> wrote in message
>> news:qv0p25tm7q3nvbg9t6q1kqqlak6a5f22bk@4ax.com...
>>> On Sun, 7 Jun 2009 17:37:59 -0700, "Derek Hart" <derekmh***@yahoo.com>
>>> 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?
>>
>>
>
Author
10 Jun 2009 1:52 AM
Derek Hart
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


Show quoteHide quote
"Jack Jackson" <jjackson-***@cinnovations.net> wrote in message
news:vntr259vc443nl99fbpqrhp8755tkcr1af@4ax.com...
> 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" <derekmh***@yahoo.com>
> 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" <derekmh***@yahoo.com> wrote in message
>>news:eccWXLF6JHA.1432@TK2MSFTNGP02.phx.gbl...
>>> 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-***@cinnovations.net> wrote in message
>>> news:qv0p25tm7q3nvbg9t6q1kqqlak6a5f22bk@4ax.com...
>>>> On Sun, 7 Jun 2009 17:37:59 -0700, "Derek Hart" <derekmh***@yahoo.com>
>>>> 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?
>>>
>>>
>>
Author
10 Jun 2009 7:59 PM
Jack Jackson
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


Show quoteHide quote
On Tue, 9 Jun 2009 18:52:05 -0700, "Derek Hart" <derekmh***@yahoo.com>
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-***@cinnovations.net> wrote in message
>news:vntr259vc443nl99fbpqrhp8755tkcr1af@4ax.com...
>> 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" <derekmh***@yahoo.com>
>> 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" <derekmh***@yahoo.com> wrote in message
>>>news:eccWXLF6JHA.1432@TK2MSFTNGP02.phx.gbl...
>>>> 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-***@cinnovations.net> wrote in message
>>>> news:qv0p25tm7q3nvbg9t6q1kqqlak6a5f22bk@4ax.com...
>>>>> On Sun, 7 Jun 2009 17:37:59 -0700, "Derek Hart" <derekmh***@yahoo.com>
>>>>> 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?
>>>>
>>>>
>>>
>
Author
10 Jun 2009 10:22 PM
Derek Hart
Me.FindForm() just has an error "FindForm is not a member of
myControls.TextBox".

Do you have specific code for this?

Show quoteHide quote
"Jack Jackson" <jjackson-***@cinnovations.net> wrote in message
news:ep303519rlhf9cavsec9s8l9rgiuoaqfvk@4ax.com...
> 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" <derekmh***@yahoo.com>
> 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-***@cinnovations.net> wrote in message
>>news:vntr259vc443nl99fbpqrhp8755tkcr1af@4ax.com...
>>> 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" <derekmh***@yahoo.com>
>>> 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" <derekmh***@yahoo.com> wrote in message
>>>>news:eccWXLF6JHA.1432@TK2MSFTNGP02.phx.gbl...
>>>>> 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-***@cinnovations.net> wrote in message
>>>>> news:qv0p25tm7q3nvbg9t6q1kqqlak6a5f22bk@4ax.com...
>>>>>> On Sun, 7 Jun 2009 17:37:59 -0700, "Derek Hart"
>>>>>> <derekmh***@yahoo.com>
>>>>>> 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?
>>>>>
>>>>>
>>>>
>>
Author
10 Jun 2009 10:40 PM
Armin Zingler
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

Bookmark and Share