Click here to Skip to main content
15,918,808 members
Home / Discussions / C#
   

C#

 
QuestionRestrict multiple instance of my application Pin
Nadia Monalisa5-Oct-06 6:21
Nadia Monalisa5-Oct-06 6:21 
AnswerRe: Restrict multiple instance of my application Pin
ntrn05-Oct-06 6:38
ntrn05-Oct-06 6:38 
AnswerRe: Restrict multiple instance of my application Pin
asator5-Oct-06 6:54
asator5-Oct-06 6:54 
QuestionSkype Chat SendMessage Textbox ? Pin
ntrn05-Oct-06 5:49
ntrn05-Oct-06 5:49 
AnswerRe: Skype Chat SendMessage Textbox ? Pin
aamironline5-Oct-06 6:14
aamironline5-Oct-06 6:14 
GeneralRe: Skype Chat SendMessage Textbox ? Pin
ntrn05-Oct-06 6:30
ntrn05-Oct-06 6:30 
QuestionHow to print Datagrid in C# ? Pin
hdv2125-Oct-06 5:38
hdv2125-Oct-06 5:38 
QuestionObject Oriented Graphics issue Pin
vineas5-Oct-06 5:27
vineas5-Oct-06 5:27 
Sorry for the long post, but please bear with me.

I have a graphics user control that can display several graphics primitives, plus bitmaps and text in 2D. Users can easily scroll/pan/zoom, select objects and scale or move them, and is used all over my organization (for a visual, one of the uses is to overlay CAD information on top of a bitmap). The graphics objects are also used outside of the context of drawing - some applications only use the objects themselves to do calculations for other purposes.

Each object implements an interface and most manipulation of the object is through that interface. Each object draws itself using a supplied System.Drawing.Graphics object like a ton of articles on code project and elsewhere suggest. The current design works great for collections of graphics objects up to about 3,000 or so, but now the control is being used in situations where there may be 30k+ objects in the drawing and performance is very poor.

I've been going over the code and looking for optimizations, and there are several things I'm going to work on, but one of the things I also want to try is using different graphics for drawing, perhaps Managed DirectX, but here lies a problem. The interface that each object implements includes 3 methods that need a System.Drawing.Graphics object as a parameter. One of the methods is Draw(), the other two are for determining the size of a shape (which is really only needed for text objects - ie. MeasureString - but had to be in the interface to keep things generic). So basically, I need a way to decouple the actual drawing method used from the object itself.

One idea I had was to create a separate GraphicsContext object that would be passed into the objects in place of System.Drawing.Graphics and would have methods similar to System.Drawing.Graphics, but could be implemented behind the scenes in whatever way I wanted. The problem with that is I'm simply coupling to something else - and the users who don't even use the objects as "graphics" have yet another thing to use for determining size (unless I can figure out a way to measure a string without some type of graphics). Maybe I'm just over-thinking this one.

Another idea I had is to completely remove the graphics requirement for all methods and remove the Draw method entirely, then only the drawing code itself would be coupled to a specific method. This has worse problems though - users can currently add their own graphics objects, but this method would not know how to draw those. Plus the performance probably wouldn't be there anyway - the collections only expose the objects as the interface, so it would require checking and casting to specific types before the drawing. The Con's pretty much make this a no-go.

Are there other ways I can do this? I know there has to be, I know of many games that work with DirectX or OpenGL and some even software render if those aren't available, so there must be some good way of doing this. I once saw an article about this when Googling for something else, but I'll be damned if I can find it now.

-----
In the land of the blind, the one eyed man is king.

AnswerRe: Object Oriented Graphics issue Pin
User 66585-Oct-06 5:41
User 66585-Oct-06 5:41 
AnswerRe: Object Oriented Graphics issue Pin
aamironline5-Oct-06 6:06
aamironline5-Oct-06 6:06 
GeneralRe: Object Oriented Graphics issue Pin
vineas5-Oct-06 7:36
vineas5-Oct-06 7:36 
QuestionDll to XML Pin
gmellado5-Oct-06 5:17
gmellado5-Oct-06 5:17 
QuestionDatabase Copy and Paste Pin
Spudwars5-Oct-06 4:30
Spudwars5-Oct-06 4:30 
AnswerRe: Database Copy and Paste Pin
Chris Buckett5-Oct-06 9:05
Chris Buckett5-Oct-06 9:05 
QuestionNewbie: How to use a variable from a different form? Pin
hristo19775-Oct-06 4:15
hristo19775-Oct-06 4:15 
AnswerRe: Newbie: How to use a variable from a different form? Pin
Andrei Ungureanu5-Oct-06 4:22
Andrei Ungureanu5-Oct-06 4:22 
GeneralRe: Newbie: How to use a variable from a different form? Pin
hristo19775-Oct-06 4:35
hristo19775-Oct-06 4:35 
GeneralRe: Newbie: How to use a variable from a different form? Pin
Nadia Monalisa5-Oct-06 6:28
Nadia Monalisa5-Oct-06 6:28 
GeneralRe: Newbie: How to use a variable from a different form? Pin
hristo19775-Oct-06 10:20
hristo19775-Oct-06 10:20 
GeneralRe: Newbie: How to use a variable from a different form? Pin
Nadia Monalisa5-Oct-06 10:31
Nadia Monalisa5-Oct-06 10:31 
QuestionPdf export file does not complete page 2 if the "mode" summary option is selected Pin
Mishalin5-Oct-06 4:09
Mishalin5-Oct-06 4:09 
QuestionCrystal Reports automatically sorts my columns and rows in a cross tab Pin
Mishalin5-Oct-06 3:53
Mishalin5-Oct-06 3:53 
QuestionDrawing bitmap? Pin
Dominik Reichl5-Oct-06 2:36
Dominik Reichl5-Oct-06 2:36 
AnswerRe: Drawing bitmap? Pin
aamironline5-Oct-06 4:53
aamironline5-Oct-06 4:53 
GeneralRe: Drawing bitmap? Pin
Dominik Reichl5-Oct-06 6:43
Dominik Reichl5-Oct-06 6:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.