How can I get the correct width of my form?












0














When using the following code to get the size of a form and the position another form to the left of it the size of the form returned seems to be larger than it should be.



//form is the name of the second form that I'm trying to
//position to the left of this form
form.Left = this.Left - form.Width;


Back in the vb6 days I would use something like SaleWidth instead. Is there something like that that I need to use in c#? Or is this due to for shadows etc? How can I get my second form to end up right next to the current form?



Current Results



enter image description here



Expected Results



enter image description here










share|improve this question






















  • form.Left = this.Left - form.Width; When are you calling this?
    – LarsTech
    Nov 19 '18 at 17:30










  • In the Form_Move event of the current form.
    – Arvo Bowen
    Nov 19 '18 at 17:31










  • The width property is the "client width" (i.e., the width of the client area of the form) I believe, and not the overall outer width of the form. There's a way to figure this out by looking at all the properties, but I can't remember what that is.
    – Flydog57
    Nov 19 '18 at 17:45










  • The apparent gap between the forms is due to the window's theme. The theme makes the form's non-client area border transparent. If you make a call to the API method SetWindowTheme to remove the theme, you will observe that your calculation is correct. i.e. SetWindowTheme(this.Handle, " ", " ");. A hack is to adjust the width by: (SystemInformation.FrameBorderSize.Width + SystemInformation.SizingBorderWidth).
    – TnTinMn
    Nov 19 '18 at 17:47






  • 1




    @Flydog57 No, you have it the other way around. ClientSize is the interior size, Width would be the overall width of the form, which is a fantasy number, since Windows lies about the overall width of a form due to those fancy border shades.
    – LarsTech
    Nov 19 '18 at 17:47
















0














When using the following code to get the size of a form and the position another form to the left of it the size of the form returned seems to be larger than it should be.



//form is the name of the second form that I'm trying to
//position to the left of this form
form.Left = this.Left - form.Width;


Back in the vb6 days I would use something like SaleWidth instead. Is there something like that that I need to use in c#? Or is this due to for shadows etc? How can I get my second form to end up right next to the current form?



Current Results



enter image description here



Expected Results



enter image description here










share|improve this question






















  • form.Left = this.Left - form.Width; When are you calling this?
    – LarsTech
    Nov 19 '18 at 17:30










  • In the Form_Move event of the current form.
    – Arvo Bowen
    Nov 19 '18 at 17:31










  • The width property is the "client width" (i.e., the width of the client area of the form) I believe, and not the overall outer width of the form. There's a way to figure this out by looking at all the properties, but I can't remember what that is.
    – Flydog57
    Nov 19 '18 at 17:45










  • The apparent gap between the forms is due to the window's theme. The theme makes the form's non-client area border transparent. If you make a call to the API method SetWindowTheme to remove the theme, you will observe that your calculation is correct. i.e. SetWindowTheme(this.Handle, " ", " ");. A hack is to adjust the width by: (SystemInformation.FrameBorderSize.Width + SystemInformation.SizingBorderWidth).
    – TnTinMn
    Nov 19 '18 at 17:47






  • 1




    @Flydog57 No, you have it the other way around. ClientSize is the interior size, Width would be the overall width of the form, which is a fantasy number, since Windows lies about the overall width of a form due to those fancy border shades.
    – LarsTech
    Nov 19 '18 at 17:47














0












0








0







When using the following code to get the size of a form and the position another form to the left of it the size of the form returned seems to be larger than it should be.



//form is the name of the second form that I'm trying to
//position to the left of this form
form.Left = this.Left - form.Width;


Back in the vb6 days I would use something like SaleWidth instead. Is there something like that that I need to use in c#? Or is this due to for shadows etc? How can I get my second form to end up right next to the current form?



Current Results



enter image description here



Expected Results



enter image description here










share|improve this question













When using the following code to get the size of a form and the position another form to the left of it the size of the form returned seems to be larger than it should be.



//form is the name of the second form that I'm trying to
//position to the left of this form
form.Left = this.Left - form.Width;


Back in the vb6 days I would use something like SaleWidth instead. Is there something like that that I need to use in c#? Or is this due to for shadows etc? How can I get my second form to end up right next to the current form?



Current Results



enter image description here



Expected Results



enter image description here







c# winforms






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 17:19









Arvo Bowen

2,04412354




2,04412354












  • form.Left = this.Left - form.Width; When are you calling this?
    – LarsTech
    Nov 19 '18 at 17:30










  • In the Form_Move event of the current form.
    – Arvo Bowen
    Nov 19 '18 at 17:31










  • The width property is the "client width" (i.e., the width of the client area of the form) I believe, and not the overall outer width of the form. There's a way to figure this out by looking at all the properties, but I can't remember what that is.
    – Flydog57
    Nov 19 '18 at 17:45










  • The apparent gap between the forms is due to the window's theme. The theme makes the form's non-client area border transparent. If you make a call to the API method SetWindowTheme to remove the theme, you will observe that your calculation is correct. i.e. SetWindowTheme(this.Handle, " ", " ");. A hack is to adjust the width by: (SystemInformation.FrameBorderSize.Width + SystemInformation.SizingBorderWidth).
    – TnTinMn
    Nov 19 '18 at 17:47






  • 1




    @Flydog57 No, you have it the other way around. ClientSize is the interior size, Width would be the overall width of the form, which is a fantasy number, since Windows lies about the overall width of a form due to those fancy border shades.
    – LarsTech
    Nov 19 '18 at 17:47


















  • form.Left = this.Left - form.Width; When are you calling this?
    – LarsTech
    Nov 19 '18 at 17:30










  • In the Form_Move event of the current form.
    – Arvo Bowen
    Nov 19 '18 at 17:31










  • The width property is the "client width" (i.e., the width of the client area of the form) I believe, and not the overall outer width of the form. There's a way to figure this out by looking at all the properties, but I can't remember what that is.
    – Flydog57
    Nov 19 '18 at 17:45










  • The apparent gap between the forms is due to the window's theme. The theme makes the form's non-client area border transparent. If you make a call to the API method SetWindowTheme to remove the theme, you will observe that your calculation is correct. i.e. SetWindowTheme(this.Handle, " ", " ");. A hack is to adjust the width by: (SystemInformation.FrameBorderSize.Width + SystemInformation.SizingBorderWidth).
    – TnTinMn
    Nov 19 '18 at 17:47






  • 1




    @Flydog57 No, you have it the other way around. ClientSize is the interior size, Width would be the overall width of the form, which is a fantasy number, since Windows lies about the overall width of a form due to those fancy border shades.
    – LarsTech
    Nov 19 '18 at 17:47
















form.Left = this.Left - form.Width; When are you calling this?
– LarsTech
Nov 19 '18 at 17:30




form.Left = this.Left - form.Width; When are you calling this?
– LarsTech
Nov 19 '18 at 17:30












In the Form_Move event of the current form.
– Arvo Bowen
Nov 19 '18 at 17:31




In the Form_Move event of the current form.
– Arvo Bowen
Nov 19 '18 at 17:31












The width property is the "client width" (i.e., the width of the client area of the form) I believe, and not the overall outer width of the form. There's a way to figure this out by looking at all the properties, but I can't remember what that is.
– Flydog57
Nov 19 '18 at 17:45




The width property is the "client width" (i.e., the width of the client area of the form) I believe, and not the overall outer width of the form. There's a way to figure this out by looking at all the properties, but I can't remember what that is.
– Flydog57
Nov 19 '18 at 17:45












The apparent gap between the forms is due to the window's theme. The theme makes the form's non-client area border transparent. If you make a call to the API method SetWindowTheme to remove the theme, you will observe that your calculation is correct. i.e. SetWindowTheme(this.Handle, " ", " ");. A hack is to adjust the width by: (SystemInformation.FrameBorderSize.Width + SystemInformation.SizingBorderWidth).
– TnTinMn
Nov 19 '18 at 17:47




The apparent gap between the forms is due to the window's theme. The theme makes the form's non-client area border transparent. If you make a call to the API method SetWindowTheme to remove the theme, you will observe that your calculation is correct. i.e. SetWindowTheme(this.Handle, " ", " ");. A hack is to adjust the width by: (SystemInformation.FrameBorderSize.Width + SystemInformation.SizingBorderWidth).
– TnTinMn
Nov 19 '18 at 17:47




1




1




@Flydog57 No, you have it the other way around. ClientSize is the interior size, Width would be the overall width of the form, which is a fantasy number, since Windows lies about the overall width of a form due to those fancy border shades.
– LarsTech
Nov 19 '18 at 17:47




@Flydog57 No, you have it the other way around. ClientSize is the interior size, Width would be the overall width of the form, which is a fantasy number, since Windows lies about the overall width of a form due to those fancy border shades.
– LarsTech
Nov 19 '18 at 17:47












1 Answer
1






active

oldest

votes


















0














After a few tries with the comments others have made I found that the following will get me what I'm after.



form.Left = this.Left - (form.ClientRectangle.Width + SystemInformation.SizingBorderWidth);





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379709%2fhow-can-i-get-the-correct-width-of-my-form%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    After a few tries with the comments others have made I found that the following will get me what I'm after.



    form.Left = this.Left - (form.ClientRectangle.Width + SystemInformation.SizingBorderWidth);





    share|improve this answer


























      0














      After a few tries with the comments others have made I found that the following will get me what I'm after.



      form.Left = this.Left - (form.ClientRectangle.Width + SystemInformation.SizingBorderWidth);





      share|improve this answer
























        0












        0








        0






        After a few tries with the comments others have made I found that the following will get me what I'm after.



        form.Left = this.Left - (form.ClientRectangle.Width + SystemInformation.SizingBorderWidth);





        share|improve this answer












        After a few tries with the comments others have made I found that the following will get me what I'm after.



        form.Left = this.Left - (form.ClientRectangle.Width + SystemInformation.SizingBorderWidth);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 18:33









        Arvo Bowen

        2,04412354




        2,04412354






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53379709%2fhow-can-i-get-the-correct-width-of-my-form%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

            ts Property 'filter' does not exist on type '{}'

            mat-slide-toggle shouldn't change it's state when I click cancel in confirmation window