Custom Designer

G

Guest

Hi, I'm writing a control called a validating submit button. Basically, you
can tell it to validate a number of controls when the user hits this button.
When they hit the button, it'll say, "You must enter yada yada..." and
highlight the bad field.

Ok, now that I've got that out of the way, I think this problem should be
relatively easy. Basically, I created a special designer that was a form that
had two lists, one of available controls, and one of controls it will
validate, in order. It would then add these items an arraylist of the
inherited button class. This seems to work fine! I can run my custom verb,
have it open up and show all the items that are currently selected to be
validated and all of that jazz, but it doesn't change the actual .vb file in
the InitializeComponent sub of the test form. So basically, it can change all
these values on the design-time copy of the actual control, but I can't
figure out how to add code to the initialize component of the form that'll be
using this control.

I figure that this question ought to be rather easy, as being able to create
a custom designer without being able to "save your changes," so to speak, is
pretty useless, and probably a commonly asked question.

Thanks for your time!
Bryce Covert.
 
D

Dan

Hi Bryce

I may be way off but the with the last control I wrote I had a similar issue
and it was because I hadn't set the designerserializattionvisibility
attribute on the property.

here is the link in msdn for it
mshelp://MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfsystemcomponentmodeldesignerserializationvisibilityattributeclasstopic.htm

Hope that helps.
Dan
 
G

Guest

Dan,

This didn't work. I also found a little bit of code on transactions, and
tried using something to this extent (ChooseControls is a form for modifying
the arraylist in the actual button):

Dim h As IDesignerHost =
DirectCast(GetService(GetType(IDesignerHost)), IDesignerHost)
Dim dt As DesignerTransaction

'Add a new button to the collection
dt = h.CreateTransaction("Edit Controls")

Dim x As New ChooseControls
x.Submit = Me.Control
x.ShowDialog()

dt.Commit()

Should this do it? I just found some snippets, and threw it together. It
still doesn't work, and I'm not quite sure why.

Thanks again everyone,

Bryce
 
D

Dan

Hi Bryce

Would it be possible for you to post any of your control code to get a
better idea?

Dan
 
G

Guest

Here's some code that is relevant.

<System.ComponentModel.Designer(GetType(ButtonDesigner))> _
Public Class SubmitButton
Inherits System.Windows.Forms.Button


'this is the arraylist behind the scenes
Dim _ControlsThatNeedValidation As New System.Collections.ArrayList

'this is the property that exposes the array list.

<DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
Public Property ValidatingControls() As System.Collections.ArrayList
Get
Return _ControlsThatNeedValidation
End Get
Set(ByVal Value As System.Collections.ArrayList)

_ControlsThatNeedValidation = Value
End Set
End Property

.....
End Class

Public Class ButtonDesigner
Inherits System.Windows.Forms.Design.ControlDesigner

Public Sub New()
End Sub 'New


' This method provides designer verbs.
Public Overrides ReadOnly Property Verbs() As
System.ComponentModel.Design.DesignerVerbCollection
Get
Return New DesignerVerbCollection(New DesignerVerb() {New
DesignerVerb("Example Designer Verb Command", New
System.EventHandler(AddressOf Me.onVerb))})
End Get
End Property

' Event handling method for the example designer verb
Private Sub onVerb(ByVal sender As Object, ByVal e As System.EventArgs)

If (TypeOf (Me.Component) Is SubmitButton) Then

Dim h As IDesignerHost =
DirectCast(GetService(GetType(IDesignerHost)), IDesignerHost)
Dim dt As DesignerTransaction
Dim c As IComponentChangeService = DirectCast(getservice(GetType _
(IComponentChangeService)), IComponentChangeService)

'Add a new button to the collection
dt = h.CreateTransaction("Add Button")

Dim x As New ChooseControls
x.Submit = Me.Control
x.ShowDialog()

DirectCast(Me.Control, SubmitButton).ValidatingControls =
x.Submit.ValidatingControls

dt.Commit()

End If
End Sub 'onVerb

Protected Overrides Sub PostFilterProperties(ByVal properties As
System.Collections.IDictionary)

properties.Remove("ValidatingControls")

End Sub

End Class

Let me know if this helps. THanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top