Click here to Skip to main content
12,767,637 members (51,985 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#

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)

Line class:-
public void Draw(Graphics object);

Form1 class:- Its independent form. contains one button

On button Click()
	Line object = new Line();
		  //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
Updated 29-Dec-09 22:06pm
lw@zi 88.1K
Rate this: bad
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170217.1 | Last Updated 31 Dec 2009
Copyright © CodeProject, 1999-2017
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