adding controls programmatically on winfform

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jj

    adding controls programmatically on winfform

    i try to add a group of linklabel to winform as following, but when running
    it, i can only see one linklabel added (the first one). Could anyone help
    me to solve it and tell me why?

    thanks
    jj
    ---------------------------------------------------
    LinkLabel[] lnkCase = new LinkLabel[caseCount];

    for (int i = 0; i < caseCount; i++)
    {
    lnkCase[i] = new LinkLabel();
    lnkCase[i].Text = dirs[i].Name;
    lnkCase[i].Name = dirs[i].Name;
    lnkCase[i].Location = new System.Drawing. Point(100 + i * 2, 80 + i *
    2);
    lnkCase[i].Size = new System.Drawing. Size(272, 23);
    lnkCase[i].LinkClicked += new
    System.Windows. Forms.LinkLabel LinkClickedEven tHandler
    (lnkCase_LinkCl icked);
    this.Controls.A dd(lnkCase[i]);
    }

    -----------------------------------------


  • timtos

    #2
    Re: adding controls programmaticall y on winfform

    Replace the corresponding line with
    lnkCase[i].Location = new System.Drawing. Point(100, i*25);

    Beside:
    Do you really want to change the x-coordinate?
    If the space between the linklabels is too big you also have to reduce the size
    with the Size property...

    Hope this helps,
    timtos.

    "jj" <jjcpa@rocketma il.com> wrote in message news:eOpySLwdDH A.2368@TK2MSFTN GP09.phx.gbl...[color=blue]
    > i try to add a group of linklabel to winform as following, but when running
    > it, i can only see one linklabel added (the first one). Could anyone help
    > me to solve it and tell me why?
    >
    > thanks
    > jj
    > ---------------------------------------------------
    > LinkLabel[] lnkCase = new LinkLabel[caseCount];
    >
    > for (int i = 0; i < caseCount; i++)
    > {
    > lnkCase[i] = new LinkLabel();
    > lnkCase[i].Text = dirs[i].Name;
    > lnkCase[i].Name = dirs[i].Name;
    > lnkCase[i].Location = new System.Drawing. Point(100 + i * 2, 80 + i *
    > 2);
    > lnkCase[i].Size = new System.Drawing. Size(272, 23);
    > lnkCase[i].LinkClicked += new
    > System.Windows. Forms.LinkLabel LinkClickedEven tHandler
    > (lnkCase_LinkCl icked);
    > this.Controls.A dd(lnkCase[i]);
    > }
    >
    > -----------------------------------------
    >
    >[/color]


    Comment

    • jj

      #3
      Re: adding controls programmaticall y on winfform

      it works. thank you very much.

      could you also tell me why? what's the difference between (100, 80 + i*25)
      and (100, 80 + i * 2)? one works while the other does not.


      "timtos" <tirobu@gmx.d e> wrote in news:bjl7n1$jhs $1@news.uni-koblenz.de:
      [color=blue]
      > Replace the corresponding line with
      > lnkCase[i].Location = new System.Drawing. Point(100, i*25);
      >
      > Beside:
      > Do you really want to change the x-coordinate?
      > If the space between the linklabels is too big you also have to reduce
      > the size with the Size property...
      >
      > Hope this helps,
      > timtos.
      >
      > "jj" <jjcpa@rocketma il.com> wrote in message
      > news:eOpySLwdDH A.2368@TK2MSFTN GP09.phx.gbl...[color=green]
      >> i try to add a group of linklabel to winform as following, but when
      >> running it, i can only see one linklabel added (the first one). Could
      >> anyone help me to solve it and tell me why?
      >>
      >> thanks
      >> jj
      >> ---------------------------------------------------
      >> LinkLabel[] lnkCase = new LinkLabel[caseCount];
      >>
      >> for (int i = 0; i < caseCount; i++)
      >> {
      >> lnkCase[i] = new LinkLabel();
      >> lnkCase[i].Text = dirs[i].Name;
      >> lnkCase[i].Name = dirs[i].Name;
      >> lnkCase[i].Location = new System.Drawing. Point(100 + i * 2, 80 + i *
      >> 2);
      >> lnkCase[i].Size = new System.Drawing. Size(272, 23);
      >> lnkCase[i].LinkClicked += new
      >> System.Windows. Forms.LinkLabel LinkClickedEven tHandler
      >> (lnkCase_LinkCl icked);
      >> this.Controls.A dd(lnkCase[i]);
      >> }
      >>
      >> -----------------------------------------
      >>
      >>[/color]
      >
      >
      >[/color]

      Comment

      • timtos

        #4
        Re: adding controls programmaticall y on winfform

        Have you tried smaller values between 2 and 25?
        Take 10 or 15 for example. Your controls are overlapping and due to that only the top-most is visible.

        The control´s height is not only the height of the text! You have to include the margin in your calculations.
        That´s the reason I was talking about resizing your controls! You can reduce the height of the linklabels
        to the height of the text. This way you can put them closer together...

        Greetings,
        timtos.

        "jj" <jjcpa@rocketma il.com> wrote in message news:eIMefVwdDH A.1448@TK2MSFTN GP12.phx.gbl...[color=blue]
        > it works. thank you very much.
        >
        > could you also tell me why? what's the difference between (100, 80 + i*25)
        > and (100, 80 + i * 2)? one works while the other does not.
        >
        >
        > "timtos" <tirobu@gmx.d e> wrote in news:bjl7n1$jhs $1@news.uni-koblenz.de:
        >[color=green]
        > > Replace the corresponding line with
        > > lnkCase[i].Location = new System.Drawing. Point(100, i*25);
        > >
        > > Beside:
        > > Do you really want to change the x-coordinate?
        > > If the space between the linklabels is too big you also have to reduce
        > > the size with the Size property...
        > >
        > > Hope this helps,
        > > timtos.
        > >
        > > "jj" <jjcpa@rocketma il.com> wrote in message
        > > news:eOpySLwdDH A.2368@TK2MSFTN GP09.phx.gbl...[color=darkred]
        > >> i try to add a group of linklabel to winform as following, but when
        > >> running it, i can only see one linklabel added (the first one). Could
        > >> anyone help me to solve it and tell me why?
        > >>
        > >> thanks
        > >> jj
        > >> ---------------------------------------------------
        > >> LinkLabel[] lnkCase = new LinkLabel[caseCount];
        > >>
        > >> for (int i = 0; i < caseCount; i++)
        > >> {
        > >> lnkCase[i] = new LinkLabel();
        > >> lnkCase[i].Text = dirs[i].Name;
        > >> lnkCase[i].Name = dirs[i].Name;
        > >> lnkCase[i].Location = new System.Drawing. Point(100 + i * 2, 80 + i *
        > >> 2);
        > >> lnkCase[i].Size = new System.Drawing. Size(272, 23);
        > >> lnkCase[i].LinkClicked += new
        > >> System.Windows. Forms.LinkLabel LinkClickedEven tHandler
        > >> (lnkCase_LinkCl icked);
        > >> this.Controls.A dd(lnkCase[i]);
        > >> }
        > >>
        > >> -----------------------------------------
        > >>
        > >>[/color]
        > >
        > >
        > >[/color]
        >[/color]


        Comment

        Working...