[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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