开发者

how to pass control inside a function

开发者 https://www.devze.com 2023-01-18 17:20 出处:网络
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

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);

    }


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消