• Advertisement
Sign in to follow this  

[.net] Form Scrollbar problems

This topic is 4131 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Heya chaps! So I'm making this MDI editor. It's child forms should have scrollbars that are enabled always when needed. For the moment I try to load just an image in the forms and if the image's too big the scrollbars get enabled. The image gets loaded correctly. So to get these scrollbars showing I do:
    private void RegionFile_Load(object sender, EventArgs e)
        {
            this.VerticalScroll.Visible = true;
            this.HorizontalScroll.Visible = true;
            SetupScrollbars();
        }

And SetupScrollbars() looks like:
  {
            int xOffset = (int)(regionImage.Width - ClientSize.Width;
            int yOffset = (int)(regionImage.Height - ClientSize.Height;

            if (xOffset > 0)
            {
                this.HorizontalScroll.Enabled = true;
                this.HorizontalScroll.Maximum = xOffset;
                this.HorizontalScroll.Minimum = 0;
                this.HorizontalScroll.SmallChange = 1;
                this.HorizontalScroll.LargeChange = xOffset / 4;
            }
            else
                this.HorizontalScroll.Enabled = false;

            if (yOffset > 0)
            {
                this.VerticalScroll.Enabled = true;
                this.VerticalScroll.Maximum = yOffset;
                this.VerticalScroll.Minimum = 0;
                this.VerticalScroll.SmallChange = 1;
                this.VerticalScroll.LargeChange = yOffset / 4;
            }
            else
                this.VerticalScroll.Enabled = false;
        }

The scrollbars show correct, but the problem is I can't get their values to change. The Scroll event gets called and the scrollbars' values seem to increase at that point, but then get resetted back to zero :S What's going on? And what should I do? Thanks, MindWipe

Share this post


Link to post
Share on other sites
Advertisement
What do you mean they "seem to increase"? How do you know they get reset back to 0? Do you have code in the Scroll event?

Share this post


Link to post
Share on other sites
Quote:
Original post by Machaira
What do you mean they "seem to increase"? How do you know they get reset back to 0? Do you have code in the Scroll event?


In the Scroll event the scrollbar get the value set to 1 (the ScrollArgument.newValue == 1) but directly afterwards the scrollbar is set to 0 again. For the moment I got no code in the function but I checked the values a while back.

I tried to set the value to something in SetupScrollbars() the value got changed, but no matter what I pressed on the scrollbar it always got set back to 0.

/MindWipe

Share this post


Link to post
Share on other sites
Ok, so try this:

Create a new application. Add following code:

Quote:

private void Form1_Load(object sender, EventArgs e)
{
this.VerticalScroll.Enabled = true;
this.VerticalScroll.Maximum = 20;
this.VerticalScroll.Minimum = 0;
this.VerticalScroll.SmallChange = 1;
this.VerticalScroll.LargeChange = 5;

this.HorizontalScroll.Enabled = true;
this.HorizontalScroll.Maximum = 20;
this.HorizontalScroll.Minimum = 0;
this.HorizontalScroll.SmallChange = 1;
this.HorizontalScroll.LargeChange = 5;

this.VerticalScroll.Visible = true;
this.HorizontalScroll.Visible = true;
}


And try it. See how you can't change the scrollbars.

/MindWipe

Share this post


Link to post
Share on other sites
Quote:
Original post by Machaira
Works fine for me.


Yes, that works, adding your own scrollbars. But I'm talking about the Form's preset scrollbars (Form.HorizonalScroll and VerticalScroll). Try adding the code in my previous post. Thanks for making that program though.

Here's the project

/MindWipe

Share this post


Link to post
Share on other sites
You must have grabbed the wrong version I uploaded just before I fixed it. Try it again.

The reason yours doesn't work is that there's no controls outside the client area. There's nothing to scroll to. You also need to set the AutoScroll to true. Making the scrollbars visible when there's nothing to scroll to is not necessary.

Share this post


Link to post
Share on other sites
Quote:
Original post by Machaira
You must have grabbed the wrong version I uploaded just before I fixed it. Try it again.

The reason yours doesn't work is that there's no controls outside the client area. There's nothing to scroll to. You also need to set the AutoScroll to true. Making the scrollbars visible when there's nothing to scroll to is not necessary.


I still get the same version when I download it. Ok, noticed how to use the AutoScroll, and if it only works when there's a control outside the client area that makes sense it didn't work.

Cheers!

/MindWipe

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement