Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VisualStudio2012
dear professionals,
i have more than 500 controls i want to save their setting, what is the best way..
i was thinking of save with textchanged event because i am afraid from not responding due to saving while closing...
in my application i am dealing with these controls with direct cast and i want to write a code and point to my.setting."string"....as i am doing with controls ....so i am beginner and it is not easy for me..
 
Private Sub MotorInputTag1_MouseTextChanged(sender As Object, e As EventArgs) Handles MotorInputTag1.TextChanged, MotorInputTag2.TextChanged, MotorInputTag3.TextChanged, MotorInputTag4.TextChanged, MotorInputTag5.TextChanged, MotorInputTag6.TextChanged, MotorInputTag7.TextChanged, MotorInputTag8.TextChanged, MotorInputTag9.TextChanged, MotorInputTag10.TextChanged, MotorInputTag11.TextChanged, MotorInputTag12.TextChanged, MotorInputTag13.TextChanged, MotorInputTag14.TextChanged, MotorInputTag15.TextChanged, MotorInputTag16.TextChanged, MotorInputTag17.TextChanged, MotorInputTag18.TextChanged, MotorInputTag19.TextChanged, MotorInputTag20.TextChanged, MotorInputTag21.TextChanged, MotorInputTag22.TextChanged, MotorInputTag23.TextChanged, MotorInputTag24.TextChanged, MotorInputTag25.TextChanged, MotorInputTag26.TextChanged, MotorInputTag27.TextChanged, MotorInputTag28.TextChanged, MotorInputTag29.TextChanged, MotorInputTag30.TextChanged, MotorInputTag31.TextChanged, MotorInputTag32.TextChanged, MotorOutputTag1.TextChanged, MotorOutputTag2.TextChanged, MotorOutputTag3.TextChanged, MotorOutputTag4.TextChanged, MotorOutputTag5.TextChanged, MotorOutputTag6.TextChanged, MotorOutputTag7.TextChanged, MotorOutputTag8.TextChanged, MotorOutputTag9.TextChanged, MotorOutputTag10.TextChanged, MotorOutputTag11.TextChanged, MotorOutputTag12.TextChanged, MotorOutputTag13.TextChanged, MotorOutputTag14.TextChanged, MotorOutputTag15.TextChanged, MotorOutputTag16.TextChanged, MotorOutputTag17.TextChanged, MotorOutputTag18.TextChanged, MotorOutputTag19.TextChanged, MotorOutputTag20.TextChanged, MotorOutputTag21.TextChanged, MotorOutputTag22.TextChanged, MotorOutputTag23.TextChanged, MotorOutputTag24.TextChanged, MotorOutputTag25.TextChanged, MotorOutputTag26.TextChanged, MotorOutputTag27.TextChanged, MotorOutputTag28.TextChanged, MotorOutputTag29.TextChanged, MotorOutputTag30.TextChanged, MotorOutputTag31.TextChanged, MotorOutputTag32.TextChanged, _
    MotorInputPin1.TextChanged, MotorInputPin2.TextChanged, MotorInputPin3.TextChanged, MotorInputPin4.TextChanged, MotorInputPin5.TextChanged, MotorInputPin6.TextChanged, MotorInputPin7.TextChanged, MotorInputPin8.TextChanged, MotorInputPin9.TextChanged, MotorInputPin10.TextChanged, MotorInputPin11.TextChanged, MotorInputPin12.TextChanged, MotorInputPin13.TextChanged, MotorInputPin14.TextChanged, MotorInputPin15.TextChanged, MotorInputPin16.TextChanged, MotorInputPin17.TextChanged, MotorInputPin18.TextChanged, MotorInputPin19.TextChanged, MotorInputPin20.TextChanged, MotorInputPin21.TextChanged, MotorInputPin22.TextChanged, MotorInputPin23.TextChanged, MotorInputPin24.TextChanged, MotorInputPin25.TextChanged, MotorInputPin26.TextChanged, MotorInputPin27.TextChanged, MotorInputPin28.TextChanged, MotorInputPin29.TextChanged, MotorInputPin30.TextChanged, MotorInputPin31.TextChanged, MotorInputPin32.TextChanged, MotorOutputPin1.TextChanged, MotorOutputPin2.TextChanged, MotorOutputPin3.TextChanged, MotorOutputPin4.TextChanged, MotorOutputPin5.TextChanged, MotorOutputPin6.TextChanged, MotorOutputPin7.TextChanged, MotorOutputPin8.TextChanged, MotorOutputPin9.TextChanged, MotorOutputPin10.TextChanged, MotorOutputPin11.TextChanged, MotorOutputPin12.TextChanged, MotorOutputPin13.TextChanged, MotorOutputPin14.TextChanged, MotorOutputPin15.TextChanged, MotorOutputPin16.TextChanged, MotorOutputPin17.TextChanged, MotorOutputPin18.TextChanged, MotorOutputPin19.TextChanged, MotorOutputPin20.TextChanged, MotorOutputPin21.TextChanged, MotorOutputPin22.TextChanged, MotorOutputPin23.TextChanged, MotorOutputPin24.TextChanged, MotorOutputPin25.TextChanged, MotorOutputPin26.TextChanged, MotorOutputPin27.TextChanged, MotorOutputPin28.TextChanged, MotorOutputPin29.TextChanged, MotorOutputPin30.TextChanged, MotorOutputPin31.TextChanged, MotorOutputPin32.TextChanged, _
    DvInputTag1.TextChanged, DvInputTag2.TextChanged, DvInputTag3.TextChanged, DvInputTag4.TextChanged, DvInputTag5.TextChanged, DvInputTag6.TextChanged, DvInputTag7.TextChanged, DvInputTag8.TextChanged, DvInputTag9.TextChanged, DvInputTag10.TextChanged, DvInputTag11.TextChanged, DvInputTag12.TextChanged, DvInputTag13.TextChanged, DvInputTag14.TextChanged, DvInputTag15.TextChanged, DvInputTag16.TextChanged, DvInputTag17.TextChanged, DvInputTag18.TextChanged, DvInputTag19.TextChanged, DvInputTag20.TextChanged, DvInputTag21.TextChanged, DvInputTag22.TextChanged, DvInputTag23.TextChanged, DvInputTag24.TextChanged, DvInputTag25.TextChanged, DvInputTag26.TextChanged, DvInputTag27.TextChanged, DvInputTag28.TextChanged, DvInputTag29.TextChanged, DvInputTag30.TextChanged, DvInputTag31.TextChanged, DvInputTag32.TextChanged, DvOutputTag1.TextChanged, DvOutputTag2.TextChanged, DvOutputTag3.TextChanged, DvOutputTag4.TextChanged, DvOutputTag5.TextChanged, DvOutputTag6.TextChanged, DvOutputTag7.TextChanged, DvOutputTag8.TextChanged, DvOutputTag9.TextChanged, DvOutputTag10.TextChanged, DvOutputTag11.TextChanged, DvOutputTag12.TextChanged, DvOutputTag13.TextChanged, DvOutputTag14.TextChanged, DvOutputTag15.TextChanged, DvOutputTag16.TextChanged, DvOutputTag17.TextChanged, DvOutputTag18.TextChanged, DvOutputTag19.TextChanged, DvOutputTag20.TextChanged, DvOutputTag21.TextChanged, DvOutputTag22.TextChanged, DvOutputTag23.TextChanged, DvOutputTag24.TextChanged, DvOutputTag25.TextChanged, DvOutputTag26.TextChanged, DvOutputTag27.TextChanged, DvOutputTag28.TextChanged, DvOutputTag29.TextChanged, DvOutputTag30.TextChanged, DvOutputTag31.TextChanged, DvOutputTag32.TextChanged, _
    DvInputPin1.TextChanged, DvInputPin2.TextChanged, DvInputPin3.TextChanged, DvInputPin4.TextChanged, DvInputPin5.TextChanged, DvInputPin6.TextChanged, DvInputPin7.TextChanged, DvInputPin8.TextChanged, DvInputPin9.TextChanged, DvInputPin10.TextChanged, DvInputPin11.TextChanged, DvInputPin12.TextChanged, DvInputPin13.TextChanged, DvInputPin14.TextChanged, DvInputPin15.TextChanged, DvInputPin16.TextChanged, DvInputPin17.TextChanged, DvInputPin18.TextChanged, DvInputPin19.TextChanged, DvInputPin20.TextChanged, DvInputPin21.TextChanged, DvInputPin22.TextChanged, DvInputPin23.TextChanged, DvInputPin24.TextChanged, DvInputPin25.TextChanged, DvInputPin26.TextChanged, DvInputPin27.TextChanged, DvInputPin28.TextChanged, DvInputPin29.TextChanged, DvInputPin30.TextChanged, DvInputPin31.TextChanged, DvInputPin32.TextChanged, DvOutputPin1.TextChanged, DvOutputPin2.TextChanged, DvOutputPin3.TextChanged, DvOutputPin4.TextChanged, DvOutputPin5.TextChanged, DvOutputPin6.TextChanged, DvOutputPin7.TextChanged, DvOutputPin8.TextChanged, DvOutputPin9.TextChanged, DvOutputPin10.TextChanged, DvOutputPin11.TextChanged, DvOutputPin12.TextChanged, DvOutputPin13.TextChanged, DvOutputPin14.TextChanged, DvOutputPin15.TextChanged, DvOutputPin16.TextChanged, DvOutputPin17.TextChanged, DvOutputPin18.TextChanged, DvOutputPin19.TextChanged, DvOutputPin20.TextChanged, DvOutputPin21.TextChanged, DvOutputPin22.TextChanged, DvOutputPin23.TextChanged, DvOutputPin24.TextChanged, DvOutputPin25.TextChanged, DvOutputPin26.TextChanged, DvOutputPin27.TextChanged, DvOutputPin28.TextChanged, DvOutputPin29.TextChanged, DvOutputPin30.TextChanged, DvOutputPin31.TextChanged, DvOutputPin32.TextChanged, _
    MvInputTag1.TextChanged, MvInputTag2.TextChanged, MvInputTag3.TextChanged, MvInputTag4.TextChanged, MvInputTag5.TextChanged, MvInputTag6.TextChanged, MvInputTag7.TextChanged, MvInputTag8.TextChanged, MvInputTag9.TextChanged, MvInputTag10.TextChanged, MvInputTag11.TextChanged, MvInputTag12.TextChanged, MvInputTag13.TextChanged, MvInputTag14.TextChanged, MvInputTag15.TextChanged, MvInputTag16.TextChanged, MvInputTag17.TextChanged, MvInputTag18.TextChanged, MvInputTag19.TextChanged, MvInputTag20.TextChanged, MvInputTag21.TextChanged, MvInputTag22.TextChanged, MvInputTag23.TextChanged, MvInputTag24.TextChanged, MvInputTag25.TextChanged, MvInputTag26.TextChanged, MvInputTag27.TextChanged, MvInputTag28.TextChanged, MvInputTag29.TextChanged, MvInputTag30.TextChanged, MvInputTag31.TextChanged, MvInputTag32.TextChanged, MvOutputTag1.TextChanged, MvOutputTag2.TextChanged, MvOutputTag3.TextChanged, MvOutputTag4.TextChanged, MvOutputTag5.TextChanged, MvOutputTag6.TextChanged, MvOutputTag7.TextChanged, MvOutputTag8.TextChanged, MvOutputTag9.TextChanged, MvOutputTag10.TextChanged, MvOutputTag11.TextChanged, MvOutputTag12.TextChanged, MvOutputTag13.TextChanged, MvOutputTag14.TextChanged, MvOutputTag15.TextChanged, MvOutputTag16.TextChanged, MvOutputTag17.TextChanged, MvOutputTag18.TextChanged, MvOutputTag19.TextChanged, MvOutputTag20.TextChanged, MvOutputTag21.TextChanged, MvOutputTag22.TextChanged, MvOutputTag23.TextChanged, MvOutputTag24.TextChanged, MvOutputTag25.TextChanged, MvOutputTag26.TextChanged, MvOutputTag27.TextChanged, MvOutputTag28.TextChanged, MvOutputTag29.TextChanged, MvOutputTag30.TextChanged, MvOutputTag31.TextChanged, MvOutputTag32.TextChanged, _
  MvInputPin1.TextChanged, MvInputPin2.TextChanged, MvInputPin3.TextChanged, MvInputPin4.TextChanged, MvInputPin5.TextChanged, MvInputPin6.TextChanged, MvInputPin7.TextChanged, MvInputPin8.TextChanged, MvInputPin9.TextChanged, MvInputPin10.TextChanged, MvInputPin11.TextChanged, MvInputPin12.TextChanged, MvInputPin13.TextChanged, MvInputPin14.TextChanged, MvInputPin15.TextChanged, MvInputPin16.TextChanged, MvInputPin17.TextChanged, MvInputPin18.TextChanged, MvInputPin19.TextChanged, MvInputPin20.TextChanged, MvInputPin21.TextChanged, MvInputPin22.TextChanged, MvInputPin23.TextChanged, MvInputPin24.TextChanged, MvInputPin25.TextChanged, MvInputPin26.TextChanged, MvInputPin27.TextChanged, MvInputPin28.TextChanged, MvInputPin29.TextChanged, MvInputPin30.TextChanged, MvInputPin31.TextChanged, MvInputPin32.TextChanged, MvOutputPin1.TextChanged, MvOutputPin2.TextChanged, MvOutputPin3.TextChanged, MvOutputPin4.TextChanged, MvOutputPin5.TextChanged, MvOutputPin6.TextChanged, MvOutputPin7.TextChanged, MvOutputPin8.TextChanged, MvOutputPin9.TextChanged, MvOutputPin10.TextChanged, MvOutputPin11.TextChanged, MvOutputPin12.TextChanged, MvOutputPin13.TextChanged, MvOutputPin14.TextChanged, MvOutputPin15.TextChanged, MvOutputPin16.TextChanged, MvOutputPin17.TextChanged, MvOutputPin18.TextChanged, MvOutputPin19.TextChanged, MvOutputPin20.TextChanged, MvOutputPin21.TextChanged, MvOutputPin22.TextChanged, MvOutputPin23.TextChanged, MvOutputPin24.TextChanged, MvOutputPin25.TextChanged, MvOutputPin26.TextChanged, MvOutputPin27.TextChanged, MvOutputPin28.TextChanged, MvOutputPin29.TextChanged, MvOutputPin30.TextChanged, MvOutputPin31.TextChanged, MvOutputPin32.TextChanged, _
    ScInInputTag1.TextChanged, ScInInputTag2.TextChanged, ScInInputTag3.TextChanged, ScInInputTag4.TextChanged, ScInInputTag5.TextChanged, ScInInputTag6.TextChanged, ScInInputTag7.TextChanged, ScInInputTag8.TextChanged, ScInInputTag9.TextChanged, ScInInputTag10.TextChanged, ScInInputTag11.TextChanged, _
  ScInInputPin1.TextChanged, ScInInputPin2.TextChanged, ScInInputPin3.TextChanged, ScInInputPin4.TextChanged, ScInInputPin5.TextChanged, ScInInputPin6.TextChanged, ScInInputPin7.TextChanged, ScInInputPin8.TextChanged, ScInInputPin9.TextChanged, ScInInputPin10.TextChanged, ScInInputPin11.TextChanged, _
      ScInOutputTag1.TextChanged, ScInOutputTag2.TextChanged, ScInOutputTag3.TextChanged, ScInOutputTag4.TextChanged, ScInOutputTag5.TextChanged, ScInOutputTag6.TextChanged, ScInOutputTag7.TextChanged, ScInOutputTag8.TextChanged, ScInOutputTag9.TextChanged, ScInOutputTag10.TextChanged, ScInOutputTag11.TextChanged, _
  ScInOutputPin1.TextChanged, ScInOutputPin2.TextChanged, ScInOutputPin3.TextChanged, ScInOutputPin4.TextChanged, ScInOutputPin5.TextChanged, ScInOutputPin6.TextChanged, ScInOutputPin7.TextChanged, ScInOutputPin8.TextChanged, ScInOutputPin9.TextChanged, ScInOutputPin10.TextChanged, ScInOutputPin11.TextChanged, _
   ScOutInputTag1.TextChanged, ScOutInputTag2.TextChanged, ScOutInputTag3.TextChanged, ScOutInputTag4.TextChanged, ScOutInputTag5.TextChanged, ScOutInputTag6.TextChanged, ScOutInputTag7.TextChanged, ScOutInputTag8.TextChanged, ScOutInputTag9.TextChanged, ScOutInputTag10.TextChanged, ScOutInputTag11.TextChanged, _
  ScOutInputPin1.TextChanged, ScOutInputPin2.TextChanged, ScOutInputPin3.TextChanged, ScOutInputPin4.TextChanged, ScOutInputPin5.TextChanged, ScOutInputPin6.TextChanged, ScOutInputPin7.TextChanged, ScOutInputPin8.TextChanged, ScOutInputPin9.TextChanged, ScOutInputPin10.TextChanged, ScOutInputPin11.TextChanged, _
    ScOutOutputTag1.TextChanged, ScOutOutputTag2.TextChanged, ScOutOutputTag3.TextChanged, ScOutOutputTag4.TextChanged, ScOutOutputTag5.TextChanged, ScOutOutputTag6.TextChanged, ScOutOutputTag7.TextChanged, ScOutOutputTag8.TextChanged, ScOutOutputTag9.TextChanged, ScOutOutputTag10.TextChanged, ScOutOutputTag11.TextChanged, _
          ScOutOutputPin1.TextChanged, ScOutOutputPin2.TextChanged, ScOutOutputPin3.TextChanged, ScOutOutputPin4.TextChanged, ScOutOutputPin5.TextChanged, ScOutOutputPin6.TextChanged, ScOutOutputPin7.TextChanged, ScOutOutputPin8.TextChanged, ScOutOutputPin9.TextChanged, ScOutOutputPin10.TextChanged, ScOutOutputPin11.TextChanged
 

        'using directcast to check the sender...
            texttag = DirectCast(Panel.Controls(sender.name), TextBox)
 
how can i assign texttag to its setting variable.....i meant how can i point to the "my.settings variable" with string.
Posted 30-Jan-13 8:50am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This approach could help you: Saving the state (serializing) a Windows Form[^]
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 30-Jan-13 14:29pm
   
This is useful to know, my 5, but the main problem is not here.
Please see my answer.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

First of all, having 500 controls looks questionable. Chances are, you need to radically review the design. I hope that you show only a small part of those controls at a time, others are hidden.
 
It's 100% clear what is your problem: the designer. This is a big evil, if you overuse it. If forces you into doing a lot of manual repetitive work.
 
If you have many controls (let's say, more then some five), you should never ever add them with the designer. You should add then in code. Create all the main container controls with the designer, such a set of panels, main menu, status bar. Basically, that's all.
 
Add the control in your code. Create an array of controls, and then, in the loop, instantiate each, set its property. To insert a control, use the property System.Windows.Forms.Control.Parent. It should be some parent control (such as Panel). Alternatively, on a parent control use the property System.Windows.Forms.Control.Controls to add a child:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.parent.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.controls.aspx[^].
 
That's all you need to solve your problem. This way, you will have arrays of controls (you can also use any collections the way you want), so you will be able to do most of operations in loops.
 
Forget about VB6, otherwise you are going to have problems. It was never good, was obsolete even before it was introduced to the market. In contrast to it, .NET is a decent thing. If you well understand what is it, you will never have problems similar to VB6 disaster.
 
—SA
  Permalink  
Comments
CPallini at 30-Jan-13 15:33pm
   
5.
Ironically, VB6 'designer' supports arrays of controls.
Sergey Alexandrovich Kryukov at 30-Jan-13 16:35pm
   
Thank you, Carlo.
Everything supports arrays of controls. If supported by a brain. :-)
—SA
Ahmed.ganainy at 8-Feb-13 11:10am
   
Ok i follow your instruction and i created each and every thing with control array now how can i directcast an element in control array.
directcast(controls("control name"), control type
i want the user when he uncheck checkbox it will disable the the two text box beside it
fyi i used control arrays for checkboxes and text boxes but i can't point to them dynamically by code as i was doing before with direct cast. below is my setting window of interest
http://uploadpic.org/v.php?img=5TWwXfDZoX
Sergey Alexandrovich Kryukov at 8-Feb-13 12:23pm
   
You can do DirectCast, but it will fail of the target and run-time type are not assignment compatible, apparently.
You cannot cast TextBox to RadioButton. :-)'-
In many cases, casts is a sign of wrong design.
You create variables/members of the type which you want to work with.
You can put all your controls in Control[] array, to arrange them all, for example. But it you have an array of TextBox, you should create it as TextBox[], to be able to set/read texts, without casts. Remember that the same reference can in in different arrays/collection of different compile-time types. You TextBox can be a reference in TextBox[] and in TextBox[] at the same time; same thing about collections.
—SA

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

  Print Answers RSS
0 OriginalGriff 315
1 Jochen Arndt 190
2 DamithSL 125
3 PIEBALDconsult 110
4 Garth J Lancaster 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100