|
I have a form in a VB2008 Express project and I would like to imlement a special designer for it that will let me order the controls in the tab order (TabIndex properties). I have a class that inherits from ParentControlDesigner and I applied the DesignerAttribute to the form with "Gettype(custdesigner),Gettype(IDesigner)". As far as I can tell, I have followed all the instructions for making a custom designer but when I double-click on the form in solution explorer the custom designer won't instantiate. I proved this by putting debugging code in the constructor and it never ran. I tried also inheriting from ControlDesigner and ComponentDesigner, and also tried "Gettype(IRootDesigner)" in the second parameter of the attribute. What have I done wrong? Or am I approaching the whole problem the wrong way anyway? | | Cholent Monday, May 11, 2009 1:30 PM | Hi Cholent, Assume Form1 is the class you apply DesginerAttribute, the DesignerAttribute will take effect after you add a new form class which inherits from Form1. Based on my test, the designer actually creates a base type of the Form, so what you change in Form1 doesn't influence the instance of the base type form. In addition, I want to point out Form use System.Windows.Forms.Design.FormDocumentDesigner which is internal, so you can't inherit from it. If you want to customize the designer of the form, there's a lot of things you need to achieve. you can take a look at the source code of FormDocumentDesginer via reflector. If you have any question, please feel free to let me know. Best regards, Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer byCholent Tuesday, May 19, 2009 1:41 PM
-
| | Bruce.Zhou Wednesday, May 13, 2009 10:28 AM | Speaking of apologies, I should apologise for not posting an update myself. I originally had this:
Dim ctrlslist As New List(Of Control)
Dim tmp As Integer = ctrlslist(lstControls.SelectedIndex).TabIndex
ctrlslist(lstControls.SelectedIndex).TabIndex = ctrlslist(lstControls.SelectedIndex + 1).TabIndex
ctrlslist(lstControls.SelectedIndex + 1).TabIndex = tmp
I think I managed to work out what to do, but I'd be glad if you could tell me if it's right or not:
Dim ctrlslist As New List(Of Control)
Dim tmp As Integer = ctrlslist(lstControls.SelectedIndex).TabIndex
SetTabIndex(ctrlslist(lstControls.SelectedIndex), ctrlslist(lstControls.SelectedIndex + 1).TabIndex)
SetTabIndex(ctrlslist(lstControls.SelectedIndex + 1), tmp)
Private Sub SetTabIndex(ByVal ctrl As Control, ByVal index As Integer)
Dim propdesc As PropertyDescriptor = TypeDescriptor.GetProperties(ctrl)("TabIndex")
changeservice.OnComponentChanging(ctrl, propdesc)
ctrl.TabIndex = index
changeservice.OnComponentChanged(ctrl, propdesc, Nothing, index)
End Sub
Many thanks - Marked As Answer byCholent Tuesday, May 19, 2009 1:42 PM
-
| | Cholent Monday, May 18, 2009 10:37 PM | Hi Cholent, Assume Form1 is the class you apply DesginerAttribute, the DesignerAttribute will take effect after you add a new form class which inherits from Form1. Based on my test, the designer actually creates a base type of the Form, so what you change in Form1 doesn't influence the instance of the base type form. In addition, I want to point out Form use System.Windows.Forms.Design.FormDocumentDesigner which is internal, so you can't inherit from it. If you want to customize the designer of the form, there's a lot of things you need to achieve. you can take a look at the source code of FormDocumentDesginer via reflector. If you have any question, please feel free to let me know. Best regards, Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't.- Marked As Answer byCholent Tuesday, May 19, 2009 1:41 PM
-
| | Bruce.Zhou Wednesday, May 13, 2009 10:28 AM | I can't seem to make it out. I did what you said (inherit from another form), and I added debug code to the New, Initialize, Dispose and Vebs subs but I see that it doesn't always run. It also creates errors in the main VS designer code. Perhaps you could write me an example of how I should do this. I just want to add a verb to the verb list. Below is the code I have at the moment:
Public Class TabOrderer
Inherits ControlDesigner
Dim verbscoll As New DesignerVerbCollection(New DesignerVerb() {New DesignerVerb("Order Tabs", AddressOf ShowForm)})
Public Sub New()
MyBase.New()
File.AppendAllText("C:\test.txt", "new ")
End Sub
Public Overrides Sub Initialize(ByVal component As IComponent)
MyBase.Initialize(component)
File.AppendAllText("C:\test.txt", "init ")
End Sub
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
File.AppendAllText("C:\test.txt", "disp ")
End Sub
Public Overrides ReadOnly Property Verbs() As DesignerVerbCollection
Get
File.AppendAllText("C:\test.txt", "getverb ")
Return verbscoll
End Get
End Property
Private Sub ShowForm(ByVal sender As Object, ByVal e As EventArgs)
MsgBox("hello")
End Sub
End Class
| | Cholent Wednesday, May 13, 2009 2:43 PM | Hi cholent, You can try the following steps:
- Use DesignerAttribute to apply TabOrder designer on Form1 class.
- Build the project.
- Add New Form by right click the project named Form2.
- change the code in Form2 class, and make it inherit from Form1.
- Save and rebuild the project.
- Double click Form2.
Please make sure the user run Visual Studio has the permission to write the specified file, otherwise, the designer will throw "access * file is denied", thus crashed the designer. Keep on letting me know if the problem can't be solved. Best regards, Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't. - Unmarked As Answer byCholent Sunday, May 17, 2009 2:48 PM
- Marked As Answer byCholent Thursday, May 14, 2009 8:05 PM
-
| | Bruce.Zhou Thursday, May 14, 2009 2:03 AM | Thanks for the info but you told me the inheritance trick already. I've now worked out how to do it. I inherited the designer from DocumentDesigner (not ControlDesigner or ParentDesigner) and I made sure not to put IRootDesigner as the second param for DesignerAttribute. Now I've got a new problem. If I set the new TabIndex directly it shows up in the main designer, but when I close it and reopen it 'forgets' the changes. I seems that I have to set the property another way but I'm not sure how. Is it something to do with TypeDescriptor? | | Cholent Thursday, May 14, 2009 8:05 PM | Hi Cholentï¼?br/> Sorry for the delay. I haven't received email notification for this thread. Would you please post some of the code here? Best regards, Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't. | | Bruce.Zhou Monday, May 18, 2009 6:44 AM | Speaking of apologies, I should apologise for not posting an update myself. I originally had this:
Dim ctrlslist As New List(Of Control)
Dim tmp As Integer = ctrlslist(lstControls.SelectedIndex).TabIndex
ctrlslist(lstControls.SelectedIndex).TabIndex = ctrlslist(lstControls.SelectedIndex + 1).TabIndex
ctrlslist(lstControls.SelectedIndex + 1).TabIndex = tmp
I think I managed to work out what to do, but I'd be glad if you could tell me if it's right or not:
Dim ctrlslist As New List(Of Control)
Dim tmp As Integer = ctrlslist(lstControls.SelectedIndex).TabIndex
SetTabIndex(ctrlslist(lstControls.SelectedIndex), ctrlslist(lstControls.SelectedIndex + 1).TabIndex)
SetTabIndex(ctrlslist(lstControls.SelectedIndex + 1), tmp)
Private Sub SetTabIndex(ByVal ctrl As Control, ByVal index As Integer)
Dim propdesc As PropertyDescriptor = TypeDescriptor.GetProperties(ctrl)("TabIndex")
changeservice.OnComponentChanging(ctrl, propdesc)
ctrl.TabIndex = index
changeservice.OnComponentChanged(ctrl, propdesc, Nothing, index)
End Sub
Many thanks - Marked As Answer byCholent Tuesday, May 19, 2009 1:42 PM
-
| | Cholent Monday, May 18, 2009 10:37 PM | Hi Cholent, Thanks for your new update. However, I don't know where you place this segment of code. So test the difference of the above two pieces of code. What's your testing result? Does that solve your problem? Best regards, Bruce Zhou Please mark the replies as answers if they help and unmark if they don't. | | Bruce.Zhou Tuesday, May 19, 2009 10:50 AM | I had placed that code in the 'Move Down' button handler of my designer. It's supposed to move the selected control further down the tabbing order. Everything's now working fine. It seems that if you want VB to save the changes you have to inform the IChangeService of the changes. | | Cholent Tuesday, May 19, 2009 1:41 PM | Hi Cholent, Thanks for sharing your experience. It is helpful. Best regards, Bruce Zhou Please mark the replies as answers if they help and unmark if they don't. | | Bruce.Zhou Wednesday, May 20, 2009 9:26 AM |
|