473,388 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Throw an Event when a Variable changes (VB .NET)

bergy
89
I have a user control class, when a user selects the control (or it's children) the background of the control turns blue. When the user exits, it returns to its "unselected" state. I have accomplished this with simple ENTER/LEAVE events.

I then put multiple controls into a FlowLayoutPanel and everything works just great, I can add as many controls (with a button attached to the form) as I need.

Now... I'm trying to delete controls and I need some way to flag which control was selected last -- since the user leaves the control and the LEAVE event is fired when the click the delete button -- the bg color changes and there is no way for me to tell which control was selected last so I can't tell the delete function which control it should delete.

My solution to this is to add another property to the control, a boolean, named isSelected. I set that in the control on ENTER. What I'd like to do is monitor the isSelected boolean value and when it has changed throw an event so I can handle it in my form.

I'm asking, how can I monitor a variable in a class, and when the value is changed, throw an event.
Jun 18 '07 #1
1 9234
TRScheel
638 Expert 512MB
I have a user control class, when a user selects the control (or it's children) the background of the control turns blue. When the user exits, it returns to its "unselected" state. I have accomplished this with simple ENTER/LEAVE events.

I then put multiple controls into a FlowLayoutPanel and everything works just great, I can add as many controls (with a button attached to the form) as I need.

Now... I'm trying to delete controls and I need some way to flag which control was selected last -- since the user leaves the control and the LEAVE event is fired when the click the delete button -- the bg color changes and there is no way for me to tell which control was selected last so I can't tell the delete function which control it should delete.

My solution to this is to add another property to the control, a boolean, named isSelected. I set that in the control on ENTER. What I'd like to do is monitor the isSelected boolean value and when it has changed throw an event so I can handle it in my form.

I'm asking, how can I monitor a variable in a class, and when the value is changed, throw an event.
Expand|Select|Wrap|Line Numbers
  1. public class MyControl
  2. {
  3.      private bool _IsSelected = false; 
  4.  
  5.      public delegate void PrivateVariableChanged(object sender, EventArgs e)
  6.      public event PrivateVariableChanged SelectedChanged = new PrivateVariableChanged(EmptyHandler);
  7.  
  8.      private static void EmptyHandler(object sender, EventArgs e)
  9.      { }
  10.  
  11.      public bool IsSelected
  12.      {
  13.           get { return _IsSelected; }
  14.           set 
  15.           {
  16.                if(IsSelected != value)
  17.                      SelectedChanged.Invoke();
  18.  
  19.                _IsSelected = value;
  20.           }
  21.      }
  22. }
  23.  

That will make it so whenever you change IsSelected (mind you, the public property, NOT the private variable. Use the property whenever possible) it will invoke the SelectedChanged event. With that event you can tie your functions to it.
Jun 18 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Varghjärta | last post by:
Hey! I'm a hobby programmer since many years now and I've done most of my latest 'real application' coding in C#. I've played with python of and on yet not catching on until a few months ago...
2
by: Luis Esteban Valencia | last post by:
Hello I have a datagrid with a dropdownlist that has the products, another column has the price of the product and when the user changes the product it also must change the price how can I achieve...
7
by: Mrkrich | last post by:
I have one procedure that will take very long time before it finishs. During its running, I provide users a button to cancel this process if they don't want it to run anymore. I have one varible...
7
by: ljlevend | last post by:
Is there any way (either .NET or API) to detect when Windows.Forms.Form.ActiveForm changes? Thanks, Lance
6
by: Peter | last post by:
VB6 has a wonderful debug tool: You can create a breakpoint which will break when a varible changes. This tool help me greatly. I wonder when does vb.net have Data Breakpoint? Anyone can tell me?...
6
by: nickybon | last post by:
Hi fellas, Im setting up a form in my Access project and I need to implement this rather special fucntion. This function is basically simple to understand but I really dont know how to create...
7
by: Jerry Spence1 | last post by:
I want to fire an event when the user changes text, but I don't want to fire it when the program changes the text. This must be a very common thing to do, and I was wondering if there was a better...
2
by: William Cole | last post by:
Here is my issue I have two text fields (Field A, Field B). I want Field B to be updated when Field A is changed. The problem is Field A is being changed through JavaScript so an onChange event...
0
by: Rick | last post by:
VS 2005 I have some custom business objects (BindingList(of T)) connected through BindingSources to a BindingNavigator. When the user moves focus the BindingSource of the navigator can be...
3
by: Tarscher | last post by:
Hi all, I'm a c# sharp beginner and need to fire an event when a list changes in size (element added or removed). Can i make my own event that fires when this happenes? Thanks in advance...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.