Class inherits form?

T

Tull Clancey

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.
 
J

Joseph Bittman MCAD

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
 
T

Tull Clancey

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.
 
J

Joseph Bittman MCAD

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
 
M

Matt

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)
 

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