Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a program that I created in Vb.net.
This program is a timer calculator for PIC micro-controllers.

Now,there are trackbar controls, text boxes, radio buttons and other controls on the GUI.
When one control is changed, as per the user's input, a text box showing an output program is updated in real time.

I used the <xxxxx>Changed event for the controls, eg TextChanged, SelectedIndexChanged and CheckedChanged events based on whether the control is a textbox, combobox or radiobutton.

I would hardwire all these events to fire into one function where i would first determine the sender, and then execute the appropriate code.

I assume there is a better, more efficient way to do this, How can i do it?

Thank you
Posted
Comments
[no name] 8-Dec-14 11:51am    
What PicKit version are you using, and can you give more detail on your project, like; will your hardware be reliant on your software. Ie constantly connected?
frankboyd 9-Dec-14 3:07am    
@CodingK, the question I am asking would actually have no bearing on the tools used for the actual programming of the PIC. It's really more of a GUI problem than PICs themselves. I mentioned the PIC for completeness of the question.

As i understand you have multiple controls, whose values changes when a parent or previous control's values changes.

You can create a function with an object parameter

VB
sub (ByVal e as Object)

' all your code here.
' combine all the code here written in TextChanged, SelectedIndexChanged and CheckedChanged events

you can use e to identify the source

end sub.



Now call this function from every TextChanged, SelectedIndexChanged and CheckedChanged events.
 
Share this answer
 
Comments
frankboyd 9-Dec-14 3:31am    
@prathameshpitale , that is exactly what I did. I grouped the handlers of similar controls, e.g. radio buttons selecting clock frequency, and wired them to one function.

I had pre-assigned a value to the ".Tag" property of each of the controls, and in the event handler, I would simply extract the value of the ".Tag" property of the current sender, and use it, so I didn't need to use a switch statement.

This works well. I just wonder if there isn't a better way, maybe something built into the framework?
I would probably not wire them all to the same handler: simply because it takes time to "sort out" which control type generated the event - you can't use a switch, so you have to say "if (trackbar) then ... else if (textbox) then ..." and so forth.
Instead, I'd use a different handler for each control class, and then pass the relevant info to a "generic" updater.
 
Share this answer
 
Comments
frankboyd 9-Dec-14 3:47am    
@OriginalGriff, I had pre-assigned a value to the ".Tag" property of each of the controls, and in the event handler, I would simply extract the value of the ".Tag" property of the current sender, and use it, so I didn't need to use a switch statement.

The idea of a generic updater seems very extensible. As it stands, using teh .Tag property means that I cannot change the current tag data without changing how the event handler handles the sender events.

How would I go about this generic updater, and from which function/event handler would I call it from. This is an event driven app.

Is there a better way, that allows scalability and extensibility of the program?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900