Results 1 to 9 of 9

Thread: [RESOLVED] XNA Form Resize iusse

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2015
    Posts
    171

    Resolved [RESOLVED] XNA Form Resize iusse

    Hello,
    I'm using the code from https://www.vbforums.com/showthread....-XNA-in-VB-Net to draw a lines chart( I simply put a for cycle inside the backgroundworker to draw all the lines).
    My problem is that when i resize the form(or I maximize it), the picturebox stretch the chart instad to redraw it correctly; If I correctly understand, I need to change the backbufferHeight and Widht, but all example that I've found are not "winform" ,and the have a different structure; any advice?

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: XNA Form Resize iusse

    Are you really using just XNA, or are you using MonoGame? The latter is an open source extension of XNA, which works more easily with newer versions of VS. If you are still using XNA, that kind of restricts you to FW 4.0 and VS 2010 (though you can get it working in later versions of VS). I moved over to MonoGame...and found it virtually painless. However, there are some slight differences, and more resources for MonoGame, which targets a newer version of DirectX, so it's important to make a distinction between plain vanilla XNA and MonoGame (which still uses the XNA libraries).
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2015
    Posts
    171

    Re: XNA Form Resize iusse

    For now xna 4.0, but I'm thinking about to switch to monogame.

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: XNA Form Resize iusse

    I heard that the guy who wrote that thread is pretty cool

    I personally haven't touched XNA since around the time that thread was written. However, assuming that you're using the Set2dLine method I wrote, then what you'll need to do is apply a little bit of math to adjust for the form resizing. Presumably, you're drawing on a PictureBox, in which case you can get the ClientSize to set the relative size of chart lines.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2015
    Posts
    171

    Re: XNA Form Resize iusse

    Quote Originally Posted by dday9 View Post
    I heard that the guy who wrote that thread is pretty cool

    I personally haven't touched XNA since around the time that thread was written. However, assuming that you're using the Set2dLine method I wrote, then what you'll need to do is apply a little bit of math to adjust for the form resizing. Presumably, you're drawing on a PictureBox, in which case you can get the ClientSize to set the relative size of chart lines.
    yes, I'm using Set2dLine from your tutorial for drawing on a PictureBox, but I tryed also on a panel with same result. I anchored the PictureBox on the form, so when the form is maximized or resized, PictureBox change size according, problem is that it stretch all the chart(lines became so big that came over the border.. So i did some research and seem that what I should do is update the backbuffer size, I am not able to understand how, because all the example that I found use GraphicsDeviceManager(and use game template,not winform) that is missing in the tutorial.

  6. #6
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: XNA Form Resize iusse

    I don't think that is right. I think that you will need to adjust the BasicEffect's Projection (documentation) because right now it is only being set once when the Form loads, so once the Form resizes the projection is off.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2015
    Posts
    171

    Re: XNA Form Resize iusse

    Quote Originally Posted by dday9 View Post
    I don't think that is right. I think that you will need to adjust the BasicEffect's Projection (documentation) because right now it is only being set once when the Form loads, so once the Form resizes the projection is off.
    Can you explain me how please?

  8. #8
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: XNA Form Resize iusse

    I imagine that this (untested) in the Resized event would work:
    Code:
    effect.Projection = Matrix.CreateOrthographicOffCenter(0, PictureBox1.ClientSize.Width, PictureBox1.ClientSize.Height, 0, 0, 1)
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jun 2015
    Posts
    171

    Re: XNA Form Resize iusse

    Tested, and works. Thanks!!
    Last edited by hannibal smith; Jun 16th, 2021 at 02:27 PM.

Tags for this Thread

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