Thread: Anchoring a controll using code

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    731

    Anchoring a controll using code

    How would I anchor all 4 sides of a control using code.

    This is what I got so far...

    Code:
    formControll.Anchor = AnchorStyles.Bottom;
    but that only sets it to bottom, and if I add somthing below that like this:

    Code:
    formControll.Anchor = AnchorStyles.Bottom;
    formControll.Anchor = AnchorStyles.Top;
    It will only anchor to the top then. I need to anchor them all on the same peice of code, how do I do that?

  2. #2
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    You need to do a bitwise OR on them. Theres a tutorial on how it works in the C++ tutorials on this site (it's the same for C#), but this is basically what you do:
    Code:
    formControll.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    731
    omfg, I was so close. I did || instead of |.

    Second time I asked this and was answered on this bored (other time was in C++).

    Thanks once again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  4. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM