tags:

views:

49

answers:

1

Hello All i have a problem i want So many Control on my Window Form (LAbel,textbox) how can i disable all Control When My form Load TO Caught One By one And do Visibilty False is Very irretating for me and After That i want to Pass The Control Inside the Function and Set Its Width And Height HOw Can i Achive it.

i m using Function Inside below But its Not able to Set the HEight And Weight my All LAbel And Textboxe takes Default Values

thanks in advance

shashank tyagi

 public void Setlabel(Control ctl2)
    {
        Control lbl = (Control)ctl2;
        lbl.Visible = Visible;
        lbl.Size=new Size(123,123);
        lbl.Height = 40;
        //lbl.PreferredSize = new Size(100, 100);

    }
+1  A: 

If you want to set visibility for the group of controls, you can put them in the same Panel control, and then just change that panel's Visible property.

As for the other part of your question, the code you provided should work but if called at the right time. You have to realize that your control cannot have the width or height bigger than the container in which that control is. If you called this function in constructor for example, it wouldn't work because your form hasn't resized itself yet and it is to small for your control to be big enough. Instead, you should call this function either on your form's Load event (provided that all the containers of your control have been loaded by that time) or on your form's Resize event (but be carefull about this one because it will also execute after user resizes the window).
Of course, you can also make sure that all of control's are big enough for your control to resize before resizing it.

Ivan Ferić
For my First past Its Not Possible Like A Asp.net page USing ONe Loop We can Disable All control.
Chunmun Tyagi
It is posible to create loop through all controls and change both enabled and/or visible property. Just do: foreach (var control in Form.Controls) { control.Enabled = false; control.Visible = false; } But it is more preferable to put those controls in the same container control (like Panel) and just change container's properties.
Ivan Ferić