|
-
Oct 20th, 2014, 04:42 AM
#1
Thread Starter
Lively Member
[RESOLVED] Inherit Centralize
Hi all,
I have forms and i added a Modules to Initialize all my Forms (change color, font and more).
Now i want to add code Inherits all my form to System.Windows.Forms in my Modules
Example:
Form 1
Code:
Public Class Form1
InitializeForms(Me)
End Class
Code:
Public Class Form2
InitializeForms(Me)
End Class
Code:
Public Sub InitializeForms(ByRef Sender as Object)
'Code to add Inherits Command [Inherits System.Windows.Form]
End Sub
How can i do this ?
-
Oct 20th, 2014, 05:07 AM
#2
Re: Inherit Centralize
Well you would put all your module code into a separate project. (giving your project a clear namespace name)
You can then import that project by adding it as a reference to your main project and by adding a Imports statement to the top of your form code make it available to each form e.g. 'Imports NamespaceName'
Please Mark your Thread "Resolved",  if the query is solved & Rate those who have helped you
-
Oct 20th, 2014, 05:09 AM
#3
Thread Starter
Lively Member
Re: Inherit Centralize
 Originally Posted by NeedSomeAnswers
Well you would put all your module code into a separate project. (giving your project a clear namespace name)
How to do this? I don't understand. I'm Sorry because i'm still newbie.
-
Oct 20th, 2014, 06:18 AM
#4
Re: Inherit Centralize
To be honest, I'm completely confused as to what you want. your forms already do inherit from Windows.Forms... so I'm lost as to what it is exactly you want.
Personally I wouldn't use Modules, but that's more a personal choice. If you're passing all your forms into the same function like that and making them with all the same settings, why not simply add a form with those settings already. Then when you add a form to your project, inherit from that form. Then you don't need a separate method or anything. And if you make a change to the "template", it will ripple out to all of the inherited forms.
-tg
-
Oct 20th, 2014, 07:09 AM
#5
Thread Starter
Lively Member
Re: Inherit Centralize
 Originally Posted by techgnome
To be honest, I'm completely confused as to what you want. your forms already do inherit from Windows.Forms... so I'm lost as to what it is exactly you want.
Personally I wouldn't use Modules, but that's more a personal choice. If you're passing all your forms into the same function like that and making them with all the same settings, why not simply add a form with those settings already. Then when you add a form to your project, inherit from that form. Then you don't need a separate method or anything. And if you make a change to the "template", it will ripple out to all of the inherited forms.
-tg
Inherits system.windows.forms is just example. Actually i want inherit to 3rd party component (if u know devExpress). I want inherit to xtraForm.
-
Oct 20th, 2014, 07:22 AM
#6
Re: Inherit Centralize
 Originally Posted by jimzarthur
Inherits system.windows.forms is just example. Actually i want inherit to 3rd party component (if u know devExpress). I want inherit to xtraForm.
So do it then. You don't do that in a method. You can't make a class inherit something at run time. It has to be part of the class declaration.
Open the Solution Explorer and click the Show All Files button at the top. Expand the node for any of your forms and then double-click the item ending with "designer.vb". That is the auto-generated designer code file. You'll see the Inherits keyword at the top of the class. If you want to inherit other than System.Windows.Forms.Form then change it there.
-
Oct 20th, 2014, 07:27 AM
#7
Re: Inherit Centralize
Then simply make your own form inherit from xtra form rather than System.Windows.Form.
1. Make sure you've got a reference to a dll that defines the DevExpress.ExtraEditors namespace and the XxtraForm form (I'm assuming they'll noth be in the same dll)
2. Open up the designer code of your form
3. It will probably say "Inherits System.Windows.Form" at the top of it. Change that to "Inherits DevExpress.XtraEditors.XtraForm" and you should be good to go.
edit> Crossed over with JM.
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
-
Oct 20th, 2014, 07:44 AM
#8
Thread Starter
Lively Member
Re: Inherit Centralize
 Originally Posted by jmcilhinney
So do it then. You don't do that in a method. You can't make a class inherit something at run time. It has to be part of the class declaration.
Open the Solution Explorer and click the Show All Files button at the top. Expand the node for any of your forms and then double-click the item ending with "designer.vb". That is the auto-generated designer code file. You'll see the Inherits keyword at the top of the class. If you want to inherit other than System.Windows.Forms.Form then change it there.
Thanks anyway for your guidance. But all my forms has been created with System.Windows.Forms.Form and i want to Inherit to XtraForm Automatically in 1 place. In all my Forms have a InitializeObject(param) to centralize Initialize Form. That's i want to placed in InitializeObject Method. If u say i can't change class inherit something at Design Time, so i must change this manually like ur guidance. Thanks in advance JM.
-
Oct 20th, 2014, 08:21 AM
#9
Re: Inherit Centralize
I'm pretty sure you can't do that (at least, not without some major hack). Inheritance isn't something an object does, it's something an object is. So when you say "Inherits System.Windows.Form" you are saying to the compiler, this thing I'm building is a type of Windows form and that's what the compiler builds for you. You can't change it later at run time.
Edit> As an after thought, you could look at composing the functionality of the XtraForm rather than inheriting it. That's where you keep a reference to the parent class in the child object and you write code in the child object to "pass through" calls to the parent from the child. It means some more coding in your child objects but it does have the advantage that you can change the parent at run time. I think inheritance is still probably a better choice for you but if you're hell bent on handling this stuff at run time them composition is the beter alternative.
Last edited by FunkyDexter; Oct 20th, 2014 at 08:26 AM.
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
-
Oct 20th, 2014, 09:13 AM
#10
Thread Starter
Lively Member
Re: Inherit Centralize
 Originally Posted by FunkyDexter
I'm pretty sure you can't do that (at least, not without some major hack). Inheritance isn't something an object does, it's something an object is. So when you say "Inherits System.Windows.Form" you are saying to the compiler, this thing I'm building is a type of Windows form and that's what the compiler builds for you. You can't change it later at run time.
Edit> As an after thought, you could look at composing the functionality of the XtraForm rather than inheriting it. That's where you keep a reference to the parent class in the child object and you write code in the child object to "pass through" calls to the parent from the child. It means some more coding in your child objects but it does have the advantage that you can change the parent at run time. I think inheritance is still probably a better choice for you but if you're hell bent on handling this stuff at run time them composition is the beter alternative.
Ok i will try ur step. Thanks for all ur help. I will mark this thread RESOLVED
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|