how to get previous control in c#

2019-04-09 15:47发布

问题:

how to get previous control in c#

there is a method to GetNextControl but there is no method to get previous control can any body tell me how could i get this

thanx in advance

回答1:

GetNextControl(Control control, bool forward) you can specify if you want to get the control forward or backward. For instance to get the backward control of button1, you can do:

Control previous = GetNextControl(button1, false);//false indicates backward


回答2:

GetNextControl() will return the previous control if you pass false in its second argument:

Control prev = yourControl.GetNextControl(origin, false);

I agree the method name is somewhat confusing, but you're arguably indeed looking for the next control, only in the other direction.



回答3:

Yes, you can use it like:

var control = GetNextControl(origControl, false);