Inheriting Forms - And Implementing Click on Controls

G

Guest

Problem 1:
I'd like to have a base form, from which a number of other forms derive. A
simple inheritance model using a base form so that the construct can handle
the base one, but offer me the ability to build on top of it without changing
the whole application. Unfortunately, when I create a form, and inherit from
it, the inherited form is a raw .Net form, exposing all the traditional .Net
properties throwing regX errors, and behaving very strangly, causing my
program to die a horrible death.

What's the deal with this? If I can't do this, i'm going to have to build
about 30 different forms and implement a hideously complicated interface set.
:/

Second Problem:
My labels are not exposing their click method in the designer. And if I wire
them up manualy (as they are exposed), it still compiles fine, but the click
event for the Label is never fired. (I'm using the label to save space as I
don't want to use a button, the screen is small enough as it is.)
Is it possible to inherit from label and implement my own version of Label
that does fire the Click event? Without it throwing errors about overriding
methods that I shouldn't be?

Any help would be truly appreciated, before i go mad and throw my monitor
out the window.

Cheers

Tris
 
G

Guest

[1] It is well known and publicized that visual inheritance doesn't work.
Form inheritance itself works fine, just the designer cannot show it. For
proposed workarounds use Google to search the archives.

[2] It's well known and publicized that the Label doesn't support the Click
event. There are examples in article and control form that show how to
achieve it. For examples use Google to search for "Compact Framework
Clickable Label" or look at the LabelEx control in the SDF
(www.opennetcf.org/sdf)

-Chris
 
G

Guest

HI Tris,

I haven't checked you first problem. I'll try to help in your second
problem. If you like its possible for you to create a custom class of type
control and insert these codes

Protected Overrides Sub OnMouseDown(e As MouseEventArgs) - or in OnMouseUp()
Me.Capture = Me.ClientRectangle.Contains(e.X, e.Y)
If Me.Capture Then
Method_Click()
End If
End Sub

Another option, you can try it in your own Parent form by overriding the
mousedown or mouseup event.

Protected Overrides Sub OnMouseUp(ByVal e As
System.Windows.Forms.MouseEventArgs)
Dim rec As Rectangle
rec = New Rectangle(Label1.Left, Label1.Top, Label1.Right,
Label1.Bottom)
If rec.Contains(e.Y, e.Y) Then
Method_Click()
End If
End Sub
 

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