Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 12th, 2003, 12:16 PM
Registered User
 
Join Date: Oct 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to override an event with an event?

Hi i'm new to programming so i'm sorry if this sounds dumb. I've created a class that paints my form then i want to override the paint event within the class that inherits it eg.

Class A
Public Overridable Sub blah_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
...code that paints the form
End Sub

Class B
inherits class A
overrides sub blah_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
End Sub

this works but... what if i only want it overridden if the user clicks on a button?

Blah.


 
Old November 12th, 2003, 12:24 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Always override the paint.

Put an IF - THEN - ELSE in Class B that, based on the button click, will either run the local version or just call the inherited one.

Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee
 
Old November 12th, 2003, 12:48 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

To expand on Hal suggestion... in case you aren't sure how to call the first one:

Class B
inherits class A
overrides sub blah_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
If bButtonWasClicked Then
    'Do what you want here
Else
    MyBase.blah_Paint(...)
End Sub

You'll need to figure out how to determine whether the button was clicked or now. Maybe set a var to true on the button click event then use that as your check inside the new blah_Paint().

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 12th, 2003, 05:35 PM
Registered User
 
Join Date: Oct 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm sorry but i'm really confused...
I made a form. By default it's grey and plain looking. I used the paint event to change it. When the program loads, it is painted like i want it look. I want the user to have the option to set it back to default as if i had never used the paint event (plain gray form ) without me having to repaint or set new colors for everything. I got it working by putting in the overrides sub but it is gray when the program loads and not when triggered by any event like a button click because i don't know how to use the button.click event to override the paint event.

This is how i was thinking although obviously it's not going to work...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
overrides blah_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
End Sub
End Sub

so i'm like trying to do this,

If bButtonWasClicked Then
    override the paint (override my paint job) so like override my overrides and make it plain grey default form no paint.
Else
    do nothing, don't override my paint, leave form alone.
End Sub

planoie your right i don't know how to call anything i'm new at this i don't know what i'm doing sorry.

Blah.
 
Old November 12th, 2003, 07:16 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Don't apollogize for inexperience. We all started as a single cell! ;)

Although I don't work with VB.Net Windows forms much, it would seem to me that you are overcomplicating this problem. It sounds like you want to modify the visual styles of the form. Can't you just change the form properties that you are interested in? It seems accessive to try to deal with this paint method you are trying to conditionally override.

As far as .Net goes, if you override a method, that's it. It's overridden. You can't "un-override" it or override conditionally. As Hal suggested, all you can do is override it, then do something conditionally within the method. It happens that you can call the original method by calling MyBase.OriginalMethod() so you could sort of have a conditional override. But you'll have to base that condition on something like a boolean value set from your button's click event.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 13th, 2003, 03:06 PM
Registered User
 
Join Date: Oct 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

your right... thanks for your help :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Event - Sender & Event args dash dev C# 2005 9 December 9th, 2007 07:24 AM
Event handlers jwebb Visual Basic 2005 Basics 1 June 25th, 2007 08:44 PM
first event bostek Excel VBA 2 September 7th, 2006 02:13 AM
What Event Exactly? Macsood ASP.NET 1.0 and 1.1 Basics 6 October 26th, 2005 09:24 AM
About Button event and Keydown event zhangxujun1981 XSLT 1 March 6th, 2004 04:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.