Как сделать элемент (ресурс) в панели - PullRequest
0 голосов
/ 22 апреля 2019

Этот код моей кнопки:

        int offsetY = 5;
        int x = 0;
        int y = 0;
        int index = 1;            

        //Start adds new panel and new label
        Panel b = new Panel();
        Label la = new Label();

        //Adds panel properties
        b.Controls.Add(la);
        b.Location = new Point(x, y + offsetY);
        b.Size = new Size(633, 119);
        newhaven.Class1 cl = new newhaven.Class1();
        b.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
        flowLayoutPanel1.Controls.Add(b);
        b.ResumeLayout(false);


        //Adds label properties
        x = 0;
        y = -20;
        la.Location = new Point(x,y);
       // la.Size = new Size(60, 30);
        la.Text = "Hello";
        flowLayoutPanel1.Controls.Add(la);

Я хочу привет, чтобы быть в панели)

enter image description here

Вы можете мне помочь?

1 Ответ

0 голосов
/ 22 апреля 2019

Вы почти все поняли правильно, но вам нужно позаботиться о координатах положения этикетки, пожалуйста, убедитесь, что они лежат внутри координат панели.

Следующие работы:

            int offsetY = 5;
            int x = 0;
            int y = 0;
            int index = 1;

            //Start adds new panel and new label
            Panel b = new Panel();
            Label la = new Label();

            //Adds panel properties
            b.Controls.Add(la);
            b.Location = new Point(x, y + offsetY);
            b.Size = new Size(633, 119);
            //newhaven.Class1 cl = new newhaven.Class1();
            b.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            flowLayoutPanel1.Controls.Add(b);
            b.ResumeLayout(false);


            // Adds label properties -
            // commented the co-ordinates and using the same as that of panel
            //x = 0;
            //y = -20;
            la.Location = new Point(x, y + offsetY);
            // la.Size = new Size(60, 30);
            la.Text = "Hello";

            // no need to add the label separately, its inside the panel
            //flowLayoutPanel1.Controls.Add(la); 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...