Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Note: Question is improved.

Hey everyone.

I've 2 buttons, 1 PictureBox and 1 Panel.
PictureBox's inside of the Panel and Panel's AutoScroll property is set to "true". Also PictureBox Dock property is set to "Fill".

1. Button draws a Rectangle into the pictureBox, 2. one makes it bigger whose size is bigger than the pictureBox itself. So, I need pictureBox to be scrollable.

How can I make it? Any example for this thread?

My Best Regards...

Important: Please don't give advise using existing files! I'm not using them.

Improved Version:

Considering the same situation:

Let's say when we click the second button and the rectangle and scroll bars appeared and it becomes bigger than the picturebox, but it doesn't show all the parts of the rectangle. I mean the scroolbars doesn't change dynamically so the dynamically scaled image(bigger rectangle) can't be seem properly.

How can I control set the scrollbars to control if image is bigger or not, so I can see the bigger rectangle?
Posted
Updated 24-May-11 1:09am
v3

Set the PictureBox's Dock property to none. If the PictureBox is set to resize with the Panel, then scroll bars have no need to become visible. So the PB must be static size and the Panel can be Docked to the form.
 
Share this answer
 
Comments
Un_NaMeD 24-May-11 6:25am    
I don't get this sentence.
"if the PictureBox is set to resize with the Panel, then scroll bars have no need to become visible".
I did Dock to none, but scroll bars didn't appear.
Can you make it clear?
kornakar 24-May-11 6:47am    
I'm sorry if I was unclear. First you must make the PB and the Panel as big as you wish. Then when you make the panel smaller than the PB, the scroll bars will appear.
Un_NaMeD 24-May-11 6:57am    
I see it now.
But there's another thing I editted in the question.
Please have a look if you have time.
kornakar 24-May-11 7:21am    
Maybe you should set PictureBox's SizeMode to AutoSize (or resize it manually)?
Un_NaMeD 24-May-11 7:28am    
I did, but it didn't changed.
But Thanks for sharing your time..
Maybe you change some properties such as the Picture box size and do not update it. Make sure you're calling System.Windows.Forms.ScrollableControl.AdjustFormScrollbars on your panel. Also, check up all other AutoScroll... properties.

[EDIT]
For example, you have Panel picturePanel, and it is a parent of you PictureBox myPicture.

C#
Panel picturePanel; 
PictureBox myPicture; //child of picturePanel

//...

myPicture.ClientSize = new Size(xSize, ySize); //changed
myPicture.Image = (Image)MyImage; //changes
//any change which potentially breaks the scroll position

//needs immediate fix:
picturePanel.AdjustFormScrollbars();


—SA
 
Share this answer
 
v2
Comments
Un_NaMeD 24-May-11 16:09pm    
Hi SA.
Do you mean a changing like this?
<pre>
bmp = new Bitmap(pictureBox.Width, pictureBox.Height);
</pre>
Where do I have to call System.Windows.Forms.ScrollableControl.AdjustFormScrollbars?
Couldn't get it clearly :/
Sergey Alexandrovich Kryukov 24-May-11 23:16pm    
Exactly, this is what I mean. You do something like that -- do AdjustFormScrollbars on a panel which is a parent to the bitmap. Please try it.
--SA
Un_NaMeD 25-May-11 3:14am    
SA, maybe I'm getting on your nerves but, as saying "do AdjustFormScrollbars on a panel which is a parent to the bitmap"; a parent to Bitmap? and where will I put the code? Can you show a little pseudo code?
Sergey Alexandrovich Kryukov 25-May-11 4:09am    
It's OK, sorry if I was not clear. I thought you've shown a pseudo-code yourself...
--SA
Sergey Alexandrovich Kryukov 25-May-11 4:15am    
Added a sample. Can you try it?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900