473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

standard or generic forms

Hi,

I want to write code to manage standard (or generic) forms in Windows
Forms (i don't know the correct word) like that :
- a base form in a class : frmBase with some controls inside it :
labels, textbox, buttons ..
- many forms, each in a class : frmCustomer, frmSupplier, frmProduct ...
Each form inherits from frmBase and have specific controls (labels,
textbox, buttons ..) more inherited controls of frmBase.
Each class (frmBase, frmCustomer ..) is in a file (frmBase.vb,
frmCustomer.vb ..).

I want to access each controls (specific and inherited) as control array
(i know there are not now control arrays in .net).
So i want use the code that Cor Ligthert suggests :

Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doset(Me)
End Sub

Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
AddHandler ctr.LostFocus, AddressOf meLostFocus
AddHandler ctr.GotFocus, AddressOf meGotFocus
' and many other AddHandler
doSet(ctr)
Next
End Sub

Private Sub meLostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
' here code to manage LostFocus
End Sub
Private Sub meGotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
' here code to manage GotFocus
End Sub
...

I don't want to put all the code in each form but to have only once this
code.

Now my questions :
1) is it possible to put this code only in frmBase ?
For that, is it possible to access in frmBase at the specific controls
of derived forms ? by reflection ?
by polymorphism ?

2) can the address following the keyword Addressof to be in another
class ? in the same project ?
in an another project of the solution ?

Many thanks for your help, ideas, links to articles ..

Best Regards,

Dominique
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
5 1813
Dominique,

We did a long time not see you.

However answering while not going to deep in your question and hoping I
understand you well. When you see that routine I made is it only using a
reference to a control.

So in my opinion that control can be anywhere. (When I would do what you
want was first making a shared class for it doing those routines). Seeing
your problem the only thing I can think about is why not.

You have to keep in mind that using those routines that you should always
start with the parent control.

I hope this helps?

Cor
Nov 21 '05 #2
Cor,

Thanks for your answer.

You said "We did a long time not see you."
.. but it is not me you know, it is the first time i post in this
newsgroup.

"dominique" is a french firstname and several people have this
firstname. Next time i 'll put also my lastname.

Yes i understood that your code is about controls but what i want, it is
to manage controls of derived and base form, with the same code and use
the same events with AddHandler.

I am re-writing many code i wrote in Basic PDS 7.1 and i got used my
users to specific user interface (for example : key arrow down == tab,
arrow up = shift tab ..). I need to keep the same in vb.net then i must
manage events in all the forms and more i want used base form.

If you (or others) can help me more, it will be very well.

Cheers,

dominique gratpain


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3
Hi Dominique,

There was a Belgian Guy a time in this newsgroup who was helping a lot. I
first made the mistake that I thought he was a woman, so maybe can you make
this clear as well, because in my country Dominique is a name mostly used by
woman. I know that it is in the French language for man and a woman as I
thought can be seen in Asterix.

Beneath I made a sample as I thought you where asking for?

I hope that helps?

Cor

\\\
Public Class Form1
Inherits Form2
#Region " Windows Form Designer generated code "
'.................
End Class
///
\\\\a form2 with by instance 3 textboxes
Public Class Form2
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
Dim myFormhandlers As New FormHandlers(Me)
End Sub
'...............
End Class
///
\\\
Public Class FormHandlers
Sub New(ByVal TopMyform As Control)
doSet(TopMyform)
End Sub
Dim last As String
Private Sub doSet(ByVal parentCtr As Control)
Dim ctr As Control
For Each ctr In parentCtr.Controls
AddHandler ctr.LostFocus, AddressOf meLostFocus
AddHandler ctr.GotFocus, AddressOf meGotFocus
doSet(ctr)
Next
End Sub
Private Sub meLostFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
last = DirectCast(sender, Control).Name
End Sub
Private Sub meGotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Control).Text = last
End Sub
End Class
////
Nov 21 '05 #4
Hi Cor,

Thanks, you solved my problem :

it missed me the instruction :
Dim myFormhandlers As New FormHandlers(Me)
in the constructor of the form.

Three comments :

1) we can put also this instruction in the constructor of the derived
form (form1 in your instance with some textbox in form1). It is ok for
the textbox of form1 (derived class) and the textbox of form2 (base
class)

2) in your code, there is a small problem with the first textbox when it
got the focus (because last = "").
i add that and it is ok :

Dim i as Integer=0

Private Sub meGotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
if i=1 then DirectCast(sender, Control).Text = last
i=1
End Sub

3) i tried your code in debug mode with breakpoints on
last = DirectCast(sender, Control).Name

and

if i=1 then DirectCast(sender, Control).Text = last

i thought it'll go once on lostfocus and once on gotfocus but it is not
the case, it goes many times on lostfocus and got focus, strange !!, i
don't understand (even with one form without derived form).
Now about my fistname, yes it is true, in France, Dominique is used both
for men and women.
Normally it is for men because Saint Dominique was a man (around year
1200). Often in France, a firstname which finished by "e", is used by
women. Sometimes also we add a "e" at a name for men to have a name for
women :
Michel, Michèle or Daniel, Danièle or Jean, Jeanne ..

Me, i am a man and i live near Paris.
And you, what country are you from ?

a big thank you for your help

Dominique


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #5
Dominique,

Glad it is solved, this is a sample, so it has to be as small as possible
and you can use it as you want. (Questions 1 and 2).

For the focus I thought that that was that it lost it focus as well to the
debugger, however I did never thought any further than that (Question 3).

I was often in Paris, I had/have family living there.
(Now only still at Glenvilliers)

Cor (from Holland)
Hi Cor,

Thanks, you solved my problem :

it missed me the instruction :
Dim myFormhandlers As New FormHandlers(Me)
in the constructor of the form.

Three comments :

1) we can put also this instruction in the constructor of the derived
form (form1 in your instance with some textbox in form1). It is ok for
the textbox of form1 (derived class) and the textbox of form2 (base
class)

2) in your code, there is a small problem with the first textbox when it
got the focus (because last = "").
i add that and it is ok :

Dim i as Integer=0

Private Sub meGotFocus(ByVal sender As Object, _
ByVal e As System.EventArgs)
if i=1 then DirectCast(sender, Control).Text = last
i=1
End Sub

3) i tried your code in debug mode with breakpoints on
last = DirectCast(sender, Control).Name

and

if i=1 then DirectCast(sender, Control).Text = last

i thought it'll go once on lostfocus and once on gotfocus but it is not
the case, it goes many times on lostfocus and got focus, strange !!, i
don't understand (even with one form without derived form).
Now about my fistname, yes it is true, in France, Dominique is used both
for men and women.
Normally it is for men because Saint Dominique was a man (around year
1200). Often in France, a firstname which finished by "e", is used by
women. Sometimes also we add a "e" at a name for men to have a name for
women :
Michel, Michèle or Daniel, Danièle or Jean, Jeanne ..

Me, i am a man and i live near Paris.
And you, what country are you from ?

a big thank you for your help

Dominique


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: Steven T. Hatton | last post by:
Now that I have a better grasp of the scope and capabilities of the C++ Standard Library, I understand that products such as Qt actually provide much of the same functionality through their own...
17
by: Andreas Huber | last post by:
What follows is a discussion of my experience with .NET generics & the ..NET framework (as implemented in the Visual Studio 2005 Beta 1), which leads to questions as to why certain things are the...
12
by: wxs | last post by:
Many times we have a bunch of enums we have from either different enums or the same enum that will have various numeric values assigned. Rarely will there be collisions in numbering between the...
5
by: Selden McCabe | last post by:
I have an application where they want to create numerous forms (for example, an expense reimbursement form, a book availability form, etc.). The idea is someone would create a form for a user to...
4
by: MohanDasGandhi | last post by:
Hi all, How the class name for windows standard controls(Ex:Button) are generated in VS2005? InVS 2005, I have created one button conrol and compiled. I got a class name as given below: ...
0
by: manini | last post by:
Hello Everyone I m getting the generic GDI + error,Please help me to resolve this error ************** Exception Text ************** System.Runtime.InteropServices.ExternalException: A generic...
3
by: BombDrop | last post by:
Can any one help I have a method that will return a List to be bound as a datasource to a combobox see code for population below. I get the following error when i try to compile Error 29 ...
7
by: j4richard | last post by:
Help please, I am getting this "Unhandled Exception has occurred in your application" " A Generic error occurred in GDI+" See the end of this message for details on...
2
by: Andrus | last post by:
Winforms UI assembly has static FormManager.FormCreator method which creates forms taking entity as parameter. I need to pass this method to business objects in business assembly so that business...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.