|
Use seperate handlers if you wish to know which event fired.
Rugby League: The Greatest Game Of All.
|
|
|
|
|
Dear PaleyX,
Yes, You are absolutely right, initially I did have two separate routines to handle the two events,
but I feel that if VB.net can allow one routine to handle different events then it is not unreasonable
to be able to find which event has been fired and act appropriately.
Dim B as Button = sender
B.Name (will be "Button1","Button2" or whatever)
Where is the
B.Eventname = "MouseEnter" or "MouseLeave"
e.GetType. seems to return every thing except what you really need.
I can not believe this would be difficult to implement as it is so obvious.
Thank you for your reply.
|
|
|
|
|
gaxxx wrote:
but I feel that if VB.net can allow one routine to handle different events then it is not unreasonable
to be able to find which event has been fired and act appropriately.
Nope, not really.
All your handler is is a registered callback address. When the button gets clickedit has been told to just callback to the function that you gave it by the address you registered.
Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
|
|
|
|
|
Thank you for your reply.
It seems I will just have to wait for VB.net developers to upgrade how callbacks are handled to keep pace with the language its self.
|
|
|
|
|
Actually, the language is capable of doing what you want. The problem is that your code isn't not following better practices. Having a single sub handle two different events is not good practice, or design. On top of that, since you have to determine which event fired you waste time by checking for the event type every time your sub is called. If you keep the code seperated into two different event handlers, your handlers automatically get executed faster because the system already called the appropriate handler instead of you trying to determine which handler to call, then branching to the appropriate code yourself.
RageInTheMachine9532
|
|
|
|
|
The time difference between MouseEnter & MouseLeave events tells you exactly how long a user dwelt over a control. If you have 20 buttons on a form and wish to maintain a log file for example to see if it is possible to distinguish one user from another by statistics alone, are you seriously saying that it is better programming practice to write 40 handlers? one for each possible event?
All I am saying is that, if from inside the event handler, you were given the 'nature of the event' the simple code for the above would be something like.
Dim B as button = Sender
Open log file
write time,B.Name,B.EventType
Close log file
But unfortunately B.EventType does not exist and nobody seems to think that it is a good idea that it should. Execution efficiency is not an issue here.
I can see the reasoning behind your reply and I do thank you for your time.
|
|
|
|
|
I would do 3 things.
1) Create a LIFO stack to hold the actual event data and write it to as file as needed. The stack class would also take care of adding the time stamp to each entry
2) Create an event handler for all the MouseEnter events for each button and have this handler write to your stack class when the mouse enters buttons
Private Sub MouseEnter(ByVal sender as Object, ByVal e as EventArgs) Handles Button1.MouseEnter, ... Buttonx.MouseEnter
Dim B as Button = sender
Stack.Push(B.name,"MouseEnter")
End Sub
3) Create an ecvent handler for all the MouseLeave events for each button and have this handler write to your stack class when the mouse leaves buttons
Private Sub MouseLeave(ByVal sender as Object, ByVal e as EventArgs) Handles Button1.MouseLeave, ... Buttonx.MouseLeave
Dim B as Button = sender
Stack.Push(B.name,"MouseLeave")
End Sub
This will take you down to needing only two event handlers to cover all your 'Buttons'.
Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
|
|
|
|
|
Ray
It is news to me that you could use the stack like that!
Part of my problem is the 'culture shock' coming from VB6 to VB.net, I was just about to repost to Dave to say that I have quickly come round to his view.
Put MouseEnter & MouseLeave events in there own two handlers and then determine the sender, which is readily available.
So you would never need the 40 handlers that I implied, to solve my particular programming example.
I thank you both once more.
|
|
|
|
|
gaxxx wrote:
It is news to me that you could use the stack like that!
My bad... I meant to correct myself and say Queue (Last in First out)
I always try to think a bit loosly coupled in things like this. Rather than opening, closeing and writing to the file in each event handler just abstract that part out to antoher class and have you event handlers 'give' thier data to that class.
Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
|
|
|
|
|
There are simpler ways of doing things is all I was saying...
Just grouping all the *Enter events in one function and all the *Leave events in another is much simpler than what you were trying to do before.
RageInTheMachine9532
|
|
|
|
|
Hi All!!
From your experience:
What is the best book that can teach me all i need in VB.NET as a beginner?
I already bought SAMS Teach Urself VB.NET in 21 Days (by: simon cox), but i can't find everything in it.
And what book in VB.NET is the best in dealing with graphics?
Thanx alot
Toola
"If you can't beat your computer at chess, do what I did — try kick-boxing." — Matt Larson.
|
|
|
|
|
Toola wrote:
SAMS Teach Urself VB.NET in 21 Days
U can use VB.NET for 21 days only
Any book from WROX would do.... I am not sure about graphics part in it. Check the 'index' page for the book before you pay for it
There is nothing new under the sun, But there are lots of old things we don't know. - Ambrose Bierce
|
|
|
|
|
S P S wrote:
U can use VB.NET for 21 days only
|
|
|
|
|
|
Hi everyone..
I just have a few small Q's about using picture boxes, and need your help
1-How can i make the picture inside the box strechable,i.e. takes the size of the box?
2-How can i create a new picture box from inside the program (code)?and add a pic to it?
I bet you already guessed..well ya, i'm a beginner
Plz help me anyone ...i,m in a hurry
Toola
"If you can't beat your computer at chess, do what I did — try kick-boxing." — Matt Larson.
|
|
|
|
|
1-
there is a property for the PictureBox object called SizeMode . set this to StretchImage in order for the image to take the size of the pictureboxes' dimensions (itll stretch/shrink the image to the boxes' dimensions).
ex: PictureBox1.SizeMode = StrechImage in code, or simply set the objects property at design time (in properties window, of course)
2-
to set the picture to be displayed in the picturebox, use its Image property.
ex: PictureBox1.Image = Image.FromFile("C:\my Pictures\pic1.bmp") . note: you can only use certain formats or u will get an error. i dont remember the full list but its most of the main ones (.bmp, either .jpg or .jpeg [i thought only 1 of the 2 worked], .gif, etc).
i dont know how to programmatically create another picturebox at run time. hopefully sum1 can post info on it.
------------------------
Jordan.
III
|
|
|
|
|
Thaaaaanx alooot Nadroj, you made my day
just one answer left i hope someone can answer it!!
Btw, i saw a function called CreateControl , but i really don't know what it does or what parameters it takes? i tried using it, but i failed , i keep giving it the wrong parameters!
do you know how to use it?
Toola
"If you can't beat your computer at chess, do what I did — try kick-boxing." — Matt Larson.
|
|
|
|
|
no sorry i have never looked into creating objects at runtime, so i wouldnt know where to start. hopefully sum1 can post a how-to, and inform the both of us!
------------------------
Jordan.
III
|
|
|
|
|
Toola wrote:
Btw, i saw a function called CreateControl , but i really don't know what it does or what parameters it takes? i tried using it, but i failed , i keep giving it the wrong parameters!
do you know how to use it?
MSDN[^] is a great source of information. You will find that the PictureBox class that you are using inherits from System.Windows.Forms.Control , which contains a method called CreateControl() . Read more here[^] if you are interested.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Thanx alot Nick. I checked out MSDN's site & found it very useful, sure bet i'll be entering that site again!!
I already found a way to create a PictureBox at run time without using the CreateControl() method,
Simply as this:
Dim pb As New PictureBox<br />
System.Windows.Forms.Form1.Controls.Add(pb)<br />
(or Me.Controls.Add(pb))<br />
---------------------------
Toola
"The SMALL details are what make the difference in the BIG picture"
|
|
|
|
|
I want to set a launch condition so that if Office 2000 or newer is nt installed on the target machine, the installation will abort. What Registry value should I use for this?
Thanks!
|
|
|
|
|
You could try looking for the existence of the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\9.0, 10.0 or 11.0.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hi Friends,
I’m creating a database application for keeping password… I got an example of the Password Keeper project that is attached to this site, however in this project the programmer is using arrays to store data and I’m using a database. My database contains two tables; one for login information and the other for the password accounts information. There is a relationship between the two tables, so the user can inter more than one record. I’m facing problem two main problems, which are:
1- Connect the Date and Time Picker control to the database…
2- I want to combine the data in the login form with information in the account details form. For example when I login with my username and password to the system, it shows only the information that I have entered to the database and I can search only the data are related to my username (ID Account)… I don’t know if that can be possible or at least I can get examples of that…
By the way I’m beginner and I’m really doesn’t know when we have to use modules and for what!!!!!???
Regards,
Albadyaih
Albadyiah
|
|
|
|
|
Hello,
I know this forum, I am using vb.net and i want to create a report using Crystal Reports. The question i have is how do change the orientaion of the report from portriat to landscape? The default is landscape but I need to create a report in landscape because it is going to have alot of info on it.
Thank you,
Santana
|
|
|
|
|
Hi,
suppose you have set
<br />
Dim ObjCrystalR as NameofYourReport<br />
Then you just have to do the following :
<br />
objCrystalR.PrintOptions.PrinterName = strNomPrinter<br />
objCrystalR.PrintOptions.PaperOrientation = CrystalDecisions.[Shared].PaperOrientation.Portrait<br />
objCrystalR.PrintToPrinter(1, False, 0, 0)<br />
This code will set the Printer to strnomPrinter.
Change the orientation
And finally, printer 1 time the page.
Sybux
|
|
|
|