• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

Building a composite custom control...

I have built a custom control that has a Button on it.
I have added a property in my control so that I can change the button in design mode. The problem is that any changes I make are not reflected once I run the program.
Imports System.ComponentModel
Public Class UserControl1
    <Description("Config Button"), Category("CONFIG")> _
    Public Property ConfigButton() As Button
        Get
            Return m_btnConfig
        End Get
        Set(ByVal value As Button)
            m_btnConfig = value
        End Set
    End Property
End Class

Open in new window

0
aferia
Asked:
aferia
  • 4
  • 3
1 Solution
 
VBRocksCommented:
It's not persisted.  I think you'll need to set it at runtime (like when the form loads).
0
 
aferiaAuthor Commented:
That is what I wa afraid of. I really needed to be able to change the button in design mode. I was thinking of having a several properties connected directly to the buttons members (ie: button.Text, button.Visible, etc). That seems to work fine, but it is just not ideal. Is there really no way to make the information persist from design to run-time?
0
 
PaulHewsCommented:
You want to create a designer for your control:

ASP.NET Control Designers Overview
http://msdn.microsoft.com/en-us/library/wxh45wzs.aspx
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
aferiaAuthor Commented:
There is a lot of information in the link you have given. I have been looking over it, but I have not found anything that applies for what I need. Is there a place with code samples or a tutorial on how to do the specific thing that I am trying to?
0
 
PaulHewsCommented:
I may be off base.  Is this an ASP.NET custom control or for WinForms?
0
 
aferiaAuthor Commented:
I'm actually trying to create a custom control to be used with Forms in a Visual Basic .NET aplication... so WinForms. I have been researching for hours now and I cant find anything that explains what I am trying to do.
0
 
PaulHewsCommented:
Okay, sorry, I thought it was about an ASP.NET server control for some reason (My misreading the question zones.)

Here is code that persists changes made to the button in design time.  The key is the DesignerSerializationVisibility metadata attribute:  http://msdn.microsoft.com/en-us/library/system.componentmodel.designerserializationvisibilityattribute.aspx
Imports System.ComponentModel
 
 
Public Class UserControl1
    <Description("Config Button"), Category("CONFIG"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
        Public Property ConfigButton() As Button
        Get
            Return Button1
        End Get
        Set(ByVal value As Button)
            Button1 = value
        End Set
    End Property
 
End Class

Open in new window

0
 
aferiaAuthor Commented:
That was exactly what I was looking for. Thanks so much! But I have another issue with a DataGridView though, when I try setting the "Columns" it gives me the null reference error. Do you know why?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now