Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WinForm
Hi,
 
Please correct if I am wrong in Design or suggest me to go through right way..
 
I have created one small assignment. and i need your suggestions to work that application.
 
As my previous mfc code was unmanaged and thinking the same way,
so I m getting little confused to work with managed c# code.
 

Contents are
 
Mainform class:- which runs through main application which contains 2 panels.
 
Global class:-
DrawShape(Line object, Graphics gObject)
{
  object.Draw(gObject);
}
 
Line class:-
public void Draw(Graphics object);
 
Form1 class:- Its independent form. contains one button
 
On button Click()
	{
	Line object = new Line();
			
  	          //TODO:
		
		  //I want to draw the line on mainform's panel for
                  //that i need Graphics object of Mainform.panel.
			
		  // Global.DrawShape(object, GraphicsObject);
		}
Posted 29-Dec-09 19:59pm
Edited 29-Dec-09 22:06pm
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You should handle the panel's Paint event and perform your drawing there. PainEventArgs offers graphics object as one of its property. That will have method for drawing lines on it.
 
In the button click event, you can set the values which you need and then create the line.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Thanks,
 
I have used Event handling and it worked. but It throws Cross thread operation invalid error.
I solved it using invoke method but i didn't understand what is Cross thread operation.
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.150129.1 | Last Updated 31 Dec 2009
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100