DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: aligning a windows forms control *basic question*

  1. #1
    Soc877 Guest

    aligning a windows forms control *basic question*


    Ok, if there's a traffic slow down on the 101 or 126 freeway it is because
    I will have committed suicide by jumping off a bridge. Right now I hate
    my existence. Here's my **** question I haven't been able to answer for
    two hours:

    HOW DO I FREAKING ALIGN A PANEL IN A WINDOWS FORM? I'm talking about left
    | center | right alignment. I mean, if this was HTML I would type:

    <div align="center">
    I'm going to kill myself
    </div>

    All I want to do, for love of Christ, is center a few labels on the form.
    I figured I'd stick them in a panel so I could just align the panel. So
    that's the question. Now I'm going to vent my frustration.

    Until the last two hours, I thought I was reasonably smart and worthy of
    life. I've been using ASP.NET for about 6 months. I've rolled a few dll
    files of my own.

    Then about a week ago I decided to try my hand at windows forms. I figured
    what the ****, it's all the .net framework, right? right? So I started programming
    a game that I made up a while back on paper. I went through some tutorials
    on System.Net.Sockets and got started. Multiplayer would be the hard part,
    I thought. The UI would be a breeze. I took one look at System.Windows.Forms.Control
    and saw familiar things to a web control. I figured if I kept a browser
    window on msdn everything would be OK.

    Then I tried to align something. I went to msdn to look for the alignment
    property. It wasn't there. I found textalign for a few controls. I want
    to align a panel containing labels, I thought to myself, not each label.
    the closest thing I found was stuff about dock and anchor. Really, I don't
    care what the **** happens when I resize the window. I just want, when the
    window originally loads up, for some text to be horizontally centered. I
    thought maybe basic alignment was handled with docking and anchoring. Maybe
    it is. After wandering around msdn and the Internet, looking at about 7,000
    enumerations of odd alignment settings, many associated with voodoo, I have
    been reduced to my knees. It is 4:19am. I can develop entire web sites
    but I can't align text in a windows form. I'm going to go find some cyanide.

    ..........................................
    Ye olden suicide note:
    The box said "requires 639 K of conventional memory." I just couldn't take
    it anymore.

    Modern suicide note:
    <person id="me">
    <status="false" cause="suicide" reason="text-align" />
    </person>

  2. #2
    ralph Guest

    Re: aligning a windows forms control *basic question*


    "Soc877" <wessel@zealonline.com> wrote:
    >
    >Ok, if there's a traffic slow down on the 101 or 126 freeway it is because
    >I will have committed suicide by jumping off a bridge. Right now I hate
    >my existence. Here's my **** question I haven't been able to answer for
    >two hours:
    >
    >HOW DO I FREAKING ALIGN A PANEL IN A WINDOWS FORM? I'm talking about left
    >| center | right alignment. I mean, if this was HTML I would type:
    >
    ><div align="center">
    >I'm going to kill myself
    ></div>
    >
    >All I want to do, for love of Christ, is center a few labels on the form.
    > I figured I'd stick them in a panel so I could just align the panel. So
    >that's the question. Now I'm going to vent my frustration.
    >
    >Until the last two hours, I thought I was reasonably smart and worthy of
    >life. I've been using ASP.NET for about 6 months. I've rolled a few dll
    >files of my own.
    >
    >Then about a week ago I decided to try my hand at windows forms. I figured
    >what the ****, it's all the .net framework, right? right? So I started

    programming
    >a game that I made up a while back on paper. I went through some tutorials
    >on System.Net.Sockets and got started. Multiplayer would be the hard part,
    >I thought. The UI would be a breeze. I took one look at System.Windows.Forms.Control
    >and saw familiar things to a web control. I figured if I kept a browser
    >window on msdn everything would be OK.
    >
    >Then I tried to align something. I went to msdn to look for the alignment
    >property. It wasn't there. I found textalign for a few controls. I want
    >to align a panel containing labels, I thought to myself, not each label.
    > the closest thing I found was stuff about dock and anchor. Really, I don't
    >care what the **** happens when I resize the window. I just want, when

    the
    >window originally loads up, for some text to be horizontally centered.

    I
    >thought maybe basic alignment was handled with docking and anchoring. Maybe
    >it is. After wandering around msdn and the Internet, looking at about 7,000
    >enumerations of odd alignment settings, many associated with voodoo, I have
    >been reduced to my knees. It is 4:19am. I can develop entire web sites
    >but I can't align text in a windows form. I'm going to go find some cyanide.
    >
    >..........................................
    >Ye olden suicide note:
    >The box said "requires 639 K of conventional memory." I just couldn't take
    >it anymore.
    >
    >Modern suicide note:
    ><person id="me">
    ><status="false" cause="suicide" reason="text-align" />
    ></person>



    I obviously don't understand the problem, because using the designer you
    just select the Main Menu Format::Center in Form:: Horizontally | Vertically.
    (Earlier versions it was 'Layout', 'Horizontal' and 'Vertical')

    In code you can manually put them where you want by...

    controlX.Location = new Point(56,72);
    controlX.Size = new Size(264, 152);
    ' resize
    this.controlX.Anchor = ((System.Windows.Forms.AnchorStyles.Top |
    System.Windows.Forms.AnchorStyles.Left) |
    System.Windows.Forms.AnchorStyles.Right);

    Or am I missing something?

    -ralph



  3. #3
    Soc877 Guest

    Re: aligning a windows forms control *basic question*


    Sorry for the suicidal post. I'm vexed because I'm stumped by something very
    simple.

    My experience is with xhtml/asp.net. When I want to center something, I
    just make a div or a span tag and set the align attribute to center. I can
    do that either in the mark up or in the code.

    Now I'm starting to work with windows forms. I made a panel to hold three
    or four labels. I want to center the labels in the panel. Then I want to
    center the panel on the form. It seems like it should be a really simple
    thing to do. I feel like I should just be able to say something like:

    myPanel.Align = "center";

    Instead I'm doing weird things like:

    myPanel.Left = (myForm.ClientSize.Width - myPanel.Width) / 2;

    I know that that can't be the right way to do things. So, my dumb question
    is "How do I center controls?"

    Also, I don't use Visual Studio.

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center