Connecting Tech Pros Worldwide Help | Site Map

Updating the state of a control

RL Stevenson
Guest
 
Posts: n/a
#1: Nov 17 '05
Often I want to change the Enable or Visibility on a control when some other
control on the form changes. Or maybe I need to make a change to the
DataSource on a combo box when the user makes a selection elsewhere on the
form.

In Visual FoxPro, you would call Refresh on the form causing Refresh to be
called on all the controls on the form, causing the Refresh event code to be
called and allowing the controls to update themselves to the new state. Or
sometime you might just call Refresh on a single control if two controls are
tightly coupled.

Basically, I would like to have a method to call on a form or control that
will execute some event code that I have provided.

I can't find anything in Windows Forms so far that even reminds me of this
capability, yet I expect that this kind of functionality is widely used.
Can someone help me find the right tree in this forest?



Jianwei Sun
Guest
 
Posts: n/a
#2: Nov 17 '05

re: Updating the state of a control


System.Windows.Forms.Control has an event called "Refresh", is this the
tree you look for.

WinFroms expose a lot of even handler you can hook your code in,are you
looking for how to hook an event handler to call your own code?
Generally, you can override some event handler methods to do the stuff
you are interested.

JW



RL Stevenson wrote:[color=blue]
> Often I want to change the Enable or Visibility on a control when some other
> control on the form changes. Or maybe I need to make a change to the
> DataSource on a combo box when the user makes a selection elsewhere on the
> form.
>
> In Visual FoxPro, you would call Refresh on the form causing Refresh to be
> called on all the controls on the form, causing the Refresh event code to be
> called and allowing the controls to update themselves to the new state. Or
> sometime you might just call Refresh on a single control if two controls are
> tightly coupled.
>
> Basically, I would like to have a method to call on a form or control that
> will execute some event code that I have provided.
>
> I can't find anything in Windows Forms so far that even reminds me of this
> capability, yet I expect that this kind of functionality is widely used.
> Can someone help me find the right tree in this forest?
>
>
>[/color]
RL Stevenson
Guest
 
Posts: n/a
#3: Nov 17 '05

re: Updating the state of a control


Thank you for pointing out the refresh method. I was not looking in the
right place.

Now, how to find out what events, if any, are caused by calling Refresh.

I did a simple experiment with a textbox to see if I could invoke my event
code by calling Refresh. The help file says Refresh causes the control to
redraw itself, but doesn't mention any events that occur.

Hoped to find a Refresh event for a textbox, but no.

Paint event? No such thing for a text box.

Maybe the Layout event?

That one doesn't seem to be triggered by invoking Refresh on the textbox.

Seems like there should be some event that is triggered, but I haven't
discovered it yet.

Any hints?


"Jianwei Sun" <jsunnewsgroup@gmail.com> wrote in message
news:O$bek44mFHA.3568@TK2MSFTNGP10.phx.gbl...[color=blue]
> System.Windows.Forms.Control has an event called "Refresh", is this the
> tree you look for.
>
> WinFroms expose a lot of even handler you can hook your code in,are you
> looking for how to hook an event handler to call your own code? Generally,
> you can override some event handler methods to do the stuff you are
> interested.
>
> JW
>
>
>
> RL Stevenson wrote:[color=green]
>> Often I want to change the Enable or Visibility on a control when some
>> other control on the form changes. Or maybe I need to make a change to
>> the DataSource on a combo box when the user makes a selection elsewhere
>> on the form.
>>
>> In Visual FoxPro, you would call Refresh on the form causing Refresh to
>> be called on all the controls on the form, causing the Refresh event code
>> to be called and allowing the controls to update themselves to the new
>> state. Or sometime you might just call Refresh on a single control if
>> two controls are tightly coupled.
>>
>> Basically, I would like to have a method to call on a form or control
>> that will execute some event code that I have provided.
>>
>> I can't find anything in Windows Forms so far that even reminds me of
>> this capability, yet I expect that this kind of functionality is widely
>> used. Can someone help me find the right tree in this forest?
>>
>>[/color][/color]

Javaman59
Guest
 
Posts: n/a
#4: Nov 17 '05

re: Updating the state of a control


Hi,

In c# you don't "Refresh" a control, because in c# their is no distinction
between the control, and it's value. It looks to me as if Foxpro is a bit
like C++/MFC, which kept the controls and values seperate, and the programmer
had to keep them in synch. The way it works in C# is that you just assign a
value to control's property, and that's it, you are done.

eg.
TextBox name = new TextBox();
name.Text = "Jerry Jones";

if (name.Text == "Jerry Jones)...

That's it...no other data to maintain or synchronise.

There is also the problem of changing several controls when one control
changes. I don't know if there is a neat c# solution to that problem. I write
a method called "UpdateControls" which changes the states of the controls
which are dependant on other controls. I invoke "UpdateControls" whenever one
of the controls which is depended on changes value.

Regards,

Stephen


"RL Stevenson" wrote:
[color=blue]
> Often I want to change the Enable or Visibility on a control when some other
> control on the form changes. Or maybe I need to make a change to the
> DataSource on a combo box when the user makes a selection elsewhere on the
> form.
>
> In Visual FoxPro, you would call Refresh on the form causing Refresh to be
> called on all the controls on the form, causing the Refresh event code to be
> called and allowing the controls to update themselves to the new state. Or
> sometime you might just call Refresh on a single control if two controls are
> tightly coupled.
>
> Basically, I would like to have a method to call on a form or control that
> will execute some event code that I have provided.
>
> I can't find anything in Windows Forms so far that even reminds me of this
> capability, yet I expect that this kind of functionality is widely used.
> Can someone help me find the right tree in this forest?
>
>
>
>[/color]
RL Stevenson
Guest
 
Posts: n/a
#5: Nov 17 '05

re: Updating the state of a control


Thanks.

Your approach is very similar to the one I used.

I liked the FoxPro approach because it seemed more object-oriented to me.
The code to update the state of the control is part of the control. You can
consider the control to be an abstract state machine in some sense because
when you tell it to update itself, the control finds the state variables in
its environment that affect it, and then the control changes its state to
conform to the current environment.



"Javaman59" <Javaman59@discussions.microsoft.com> wrote in message
news:5943D7C9-A2AD-425D-83E4-CB5582C06E84@microsoft.com...[color=blue]
> Hi,
>
> In c# you don't "Refresh" a control, because in c# their is no distinction
> between the control, and it's value. It looks to me as if Foxpro is a bit
> like C++/MFC, which kept the controls and values seperate, and the
> programmer
> had to keep them in synch. The way it works in C# is that you just assign
> a
> value to control's property, and that's it, you are done.
>
> eg.
> TextBox name = new TextBox();
> name.Text = "Jerry Jones";
>
> if (name.Text == "Jerry Jones)...
>
> That's it...no other data to maintain or synchronise.
>
> There is also the problem of changing several controls when one control
> changes. I don't know if there is a neat c# solution to that problem. I
> write
> a method called "UpdateControls" which changes the states of the controls
> which are dependant on other controls. I invoke "UpdateControls" whenever
> one
> of the controls which is depended on changes value.
>
> Regards,
>
> Stephen
>
>
> "RL Stevenson" wrote:
>[color=green]
>> Often I want to change the Enable or Visibility on a control when some
>> other
>> control on the form changes. Or maybe I need to make a change to the
>> DataSource on a combo box when the user makes a selection elsewhere on
>> the
>> form.
>>
>> In Visual FoxPro, you would call Refresh on the form causing Refresh to
>> be
>> called on all the controls on the form, causing the Refresh event code to
>> be
>> called and allowing the controls to update themselves to the new state.
>> Or
>> sometime you might just call Refresh on a single control if two controls
>> are
>> tightly coupled.
>>
>> Basically, I would like to have a method to call on a form or control
>> that
>> will execute some event code that I have provided.
>>
>> I can't find anything in Windows Forms so far that even reminds me of
>> this
>> capability, yet I expect that this kind of functionality is widely used.
>> Can someone help me find the right tree in this forest?
>>
>>
>>
>>[/color][/color]


Closed Thread