Hi dear all !

I am programming a windows form application using C++.net(CLR).
In my program I am to draw a flow chart or such shapes with undetermined length, so I must scroll the form to enable user to see all parts of the shape.
I enabled AutoScroll method of my main form like this :

this->AutoScroll::set(true)

It actually shows me two scroll bars, one horizontal and the other vertical but they don't scroll to the point I wanted them. Simply put, If a draw a rectangle outside the size of the form, it becomes invisible to me.

Which path am I going wrong ?

Thanks in advance
:)

Hello

I assume that you are drawing the shapes you want directly on the forms graphics surface during the form's paint event.
This will not work because the form has no knowlege of what's been drawn there and therefore can not scroll over it.
One way to over come this is to put a panel on your form, draw on the panel and resize the panel manually, depending on the extreme of the shapes you draw.
As the panel is resized the form's autoscroll will take effect.

this should help you get started:

private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) 
			 {
				 // These can be better set on the form's properties
				 this->AutoScroll = true;
				 this->AutoScrollMargin = System::Drawing::Size(10, 10);
				 this->panel1->Location = System::Drawing::Point(0, 0);
			 }
	private: System::Void Form1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) 
			 {
				 //e->Graphics->DrawRectangle(gcnew Pen(Color::Red, 2), System::Drawing::Rectangle(90,90,400,400));
			 }
	
	private: System::Void panel1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) 
			 {
				e->Graphics->DrawRectangle(gcnew Pen(Color::Red, 2), 
					System::Drawing::Rectangle(90, 90, 400, 400));
				// Resize the panel.
				this->panel1->Width = 90 + 405;
				this->panel1->Height = 90 + 405;
			 }

Cheers
Milton

Thank you so much for the good advice :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.