By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,835 Members | 1,119 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,835 IT Pros & Developers. It's quick & easy.

Class inherits form?

P: n/a
I have a class that inherits a form. How can I handle clicks and changes to
controls on the inherited form within my class?

Cheers,
Tull.
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies

P: n/a
July 25, 2005

LOL It has been a long time since I inherited anything (and it was
nice!), but I believe you must go to the form that you are inheriting from
and mark the controls that you want to handle with the Protected modifier.
This way inherited forms can control them, compared to the Private modifier
which only allows the same class. Hope this helps! :-)

--
Joseph Bittman
Microsoft Certified Application Developer

Web Site: http://71.39.42.23
Static IP


"Tull Clancey" <tu**********@btopenworld.com> wrote in message
news:dc**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
I have a class that inherits a form. How can I handle clicks and changes
to controls on the inherited form within my class?

Cheers,
Tull.

Nov 21 '05 #2

P: n/a
Thanks for the feedback. I'm not sure I have explained things correctly.

I'm trying to setup a simple input box. I know this would be far better off
as a control, but it seems a simple way to learn the inheritance thingy to
start with. When complete it wouldn't take much to convert it anyway.

I want a class, clsInput. This class will have several properties,
UpperCase, NumericOnly, TextOnly, Password, Prompt, etc. And probably a
single function GetInput to return the text entered.

I want the class to load a form and set the input parameters, then accept an
input and return the text entered, ie.

Dim str As String
Dim inp As New clsInput
inp.TextOnly = True
inp.Prompt = "Give me some text!"
str = inp.GetInput

I've managed to half the code between a class and a form, but this seems a
little daft, why have a class and a form if you can do exactly the same with
a form and a couple of public variables.

I would like the class to be able to create the form and the form controls,
(which I can do easily) and have the class control the form while displayed.
The only other problem is, as the form has to be 'ShowDialog' how do I
control clicks and key presses from the class when the form has Modal
control?

Cheers,
Tull.
"Joseph Bittman MCAD" <Ry*********@msn.com> wrote in message
news:e$**************@TK2MSFTNGP12.phx.gbl...
July 25, 2005

LOL It has been a long time since I inherited anything (and it was
nice!), but I believe you must go to the form that you are inheriting from
and mark the controls that you want to handle with the Protected modifier.
This way inherited forms can control them, compared to the Private
modifier which only allows the same class. Hope this helps! :-)

--
Joseph Bittman
Microsoft Certified Application Developer

Web Site: http://71.39.42.23
Static IP


"Tull Clancey" <tu**********@btopenworld.com> wrote in message
news:dc**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
I have a class that inherits a form. How can I handle clicks and changes
to controls on the inherited form within my class?

Cheers,
Tull.


Nov 21 '05 #3

P: n/a
July 25, 2005

Why does the form have to be displayed with showdialog? Why can't it be
..Show? Anyway, if it is Show and not showdialog, then you could always
create an event and handler in the form that wants to control the other
events. Then from the class that opened the form, when the user clicks a
control, raise the event that you created in the .Show form so then it can
handle them. I wouldn't be sure how to do this if it must be called by
Showdialog. I hope this helps! :-)

--
Joseph Bittman
Microsoft Certified Application Developer

Web Site: http://71.39.42.23
Static IP


"Tull Clancey" <tu**********@btopenworld.com> wrote in message
news:dc**********@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com...
Thanks for the feedback. I'm not sure I have explained things correctly.

I'm trying to setup a simple input box. I know this would be far better
off as a control, but it seems a simple way to learn the inheritance
thingy to start with. When complete it wouldn't take much to convert it
anyway.

I want a class, clsInput. This class will have several properties,
UpperCase, NumericOnly, TextOnly, Password, Prompt, etc. And probably a
single function GetInput to return the text entered.

I want the class to load a form and set the input parameters, then accept
an input and return the text entered, ie.

Dim str As String
Dim inp As New clsInput
inp.TextOnly = True
inp.Prompt = "Give me some text!"
str = inp.GetInput

I've managed to half the code between a class and a form, but this seems a
little daft, why have a class and a form if you can do exactly the same
with a form and a couple of public variables.

I would like the class to be able to create the form and the form
controls, (which I can do easily) and have the class control the form
while displayed. The only other problem is, as the form has to be
'ShowDialog' how do I control clicks and key presses from the class when
the form has Modal control?

Cheers,
Tull.
"Joseph Bittman MCAD" <Ry*********@msn.com> wrote in message
news:e$**************@TK2MSFTNGP12.phx.gbl...
July 25, 2005

LOL It has been a long time since I inherited anything (and it was
nice!), but I believe you must go to the form that you are inheriting
from and mark the controls that you want to handle with the Protected
modifier. This way inherited forms can control them, compared to the
Private modifier which only allows the same class. Hope this helps! :-)

--
Joseph Bittman
Microsoft Certified Application Developer

Web Site: http://71.39.42.23
Static IP


"Tull Clancey" <tu**********@btopenworld.com> wrote in message
news:dc**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
I have a class that inherits a form. How can I handle clicks and changes
to controls on the inherited form within my class?

Cheers,
Tull.



Nov 21 '05 #4

P: n/a
When you declare public objects (the controls), you're going to want to
declare them with WithEvents. Then it should work just like on a normal
form.

Public WithEvents yourcontrol As New Button (for example)

Tull Clancey wrote:
I have a class that inherits a form. How can I handle clicks and changes to
controls on the inherited form within my class?

Cheers,
Tull.

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.