Results 1 to 3 of 3

Thread: help with setting the width

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    help with setting the width

    hi guys! i have a simple problem that i can't figure out..how can i set the width value of my form i've tried the code below but i think that is not the proper way. by the way, i only want to set the width value. Thanks in advance!
    Code:
    this.Size.Width = 5;

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: help with setting the width

    You set the Width property of the form itself.

    The reason that the code you posted won't work is that Size is a structure, not a class, so the Size property of your form is a value type. That means that when you get the Size property of the form it returns a copy containing the same value as the Size object contained in your form. If you try to set the Width as you're doing above then you're setting the Width property of the copy, which won't affect the original and therefore won't affect the form. You cannot set a property of a property directly if the parent property is a value type. If you wanted to use the Size property you'd have to do this:
    C# Code:
    1. Size sz = this.Size;
    2.  
    3. sz.Width = 5;
    4. this.Size = sz;
    The form class provides its own Width property so you don't have to do that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: help with setting the width

    Ok thanks for that JM. The code below also works to me
    Code:
    this.Width = 5;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width