Click here to Skip to main content
15,909,091 members
Home / Discussions / C#
   

C#

 
GeneralRe: Using C++ Code in C# Project/Solution? Pin
Shameel13-Jul-11 2:21
professionalShameel13-Jul-11 2:21 
AnswerRe: Using C++ Code in C# Project/Solution? Pin
jschell13-Jul-11 9:16
jschell13-Jul-11 9:16 
GeneralRe: Using C++ Code in C# Project/Solution? Pin
AmbiguousName14-Jul-11 23:57
AmbiguousName14-Jul-11 23:57 
AnswerRe: Using C++ Code in C# Project/Solution? Pin
Morton song19-Jul-11 17:37
Morton song19-Jul-11 17:37 
QuestionDrawing a grid for plotting a graph Pin
Praveen Raghuvanshi12-Jul-11 19:23
professionalPraveen Raghuvanshi12-Jul-11 19:23 
AnswerRe: Drawing a grid for plotting a graph Pin
lukeer12-Jul-11 21:03
lukeer12-Jul-11 21:03 
QuestionRe: Drawing a grid for plotting a graph Pin
Praveen Raghuvanshi12-Jul-11 22:41
professionalPraveen Raghuvanshi12-Jul-11 22:41 
AnswerRe: Drawing a grid for plotting a graph [modified] Pin
lukeer13-Jul-11 0:38
lukeer13-Jul-11 0:38 
Here is a quick proposal with horrible readablility:
private PointF Transform(PointF logicalPoint)
{
    float logicalXMin = -100;
    float logicalXMax = 100;
    float logicalYMin = -100;
    float logicalYMax = 100;

    float canvasXMin = this.ClientRectangle.Left;
    float canvasXMax = this.ClientRectangle.Right;
    float canvasYMin = this.ClientRectangle.Top;
    float canvasYMax = this.ClientRectangle.Bottom;

    float canvasX = ((((float)(Math.Log(logicalPoint.X, 10))) - logicalXMin) / (logicalXMax - logicalXMin) * (canvasXMax - canvasXMin)) + canvasXMin;
    float canvasY = ((-logicalPoint.Y - logicalYMin ) / (logicalYMax - logicalYMin) * (canvasYMax - canvasYMin)) + canvasYMin;

    return (new PointF(canvasX, canvasY));
}
You use a control as canvas. You have to transform logical co-ordinates into canvas co-ordinates. Therefore you look at your logical value in relation to logical maximum and minimum. Then apply the same relation to canvas minimum and maximum.
Since canvas Y-axis is inverted, you have to use negative logical Y value to compensate.

As mathematics dictates, you can't use negative X values here.
Draw grid lines using logical co-ordinates. They should get processed just as any data point.
for( int power = 0, power < 4, power++)
{
    g.DrawLine( gridPen, Math.Pow(1, power), logicalYMin, Math.Pow(1, power), logicalYMax);
    g.DrawLine( gridPen, Math.Pow(2, power), logicalYMin, Math.Pow(2, power), logicalYMax);
    g.DrawLine( gridPen, Math.Pow(5, power), logicalYMin, Math.Pow(5, power), logicalYMax);
}
Horizontal grid lines should be even easier.
for( int i = logicalYMin; i <= logicalYMax; i += 10)
{
    g.DrawLine( gridPen, logicalXMin, i, logicalXMax, i);
}


Ciao,


luker
modified on Wednesday, July 13, 2011 7:17 AM

GeneralRe: Drawing a grid for plotting a graph Pin
Praveen Raghuvanshi13-Jul-11 22:31
professionalPraveen Raghuvanshi13-Jul-11 22:31 
AnswerRe: Drawing a grid for plotting a graph Pin
BobJanova12-Jul-11 22:52
BobJanova12-Jul-11 22:52 
QuestionXMLTextReader - Find Max Depth Pin
Kevin Marois12-Jul-11 7:30
professionalKevin Marois12-Jul-11 7:30 
AnswerRe: XMLTextReader - Find Max Depth Pin
Heath Stewart12-Jul-11 12:27
protectorHeath Stewart12-Jul-11 12:27 
AnswerRe: XMLTextReader - Find Max Depth Pin
BobJanova13-Jul-11 0:48
BobJanova13-Jul-11 0:48 
QuestionVertical Alignment in RichTextbox Pin
Blubbo12-Jul-11 7:28
Blubbo12-Jul-11 7:28 
AnswerRe: Vertical Alignment in RichTextbox [modified] Pin
Carmelo La Monica12-Jul-11 7:55
professionalCarmelo La Monica12-Jul-11 7:55 
GeneralRe: Vertical Alignment in RichTextbox Pin
Blubbo12-Jul-11 8:00
Blubbo12-Jul-11 8:00 
GeneralRe: Vertical Alignment in RichTextbox Pin
Carmelo La Monica12-Jul-11 8:14
professionalCarmelo La Monica12-Jul-11 8:14 
GeneralRe: Vertical Alignment in RichTextbox Pin
Blubbo12-Jul-11 8:16
Blubbo12-Jul-11 8:16 
QuestionSQL DataGridView Pin
Falterfire12-Jul-11 6:02
Falterfire12-Jul-11 6:02 
AnswerRe: SQL DataGridView Pin
Dan Mos12-Jul-11 8:35
Dan Mos12-Jul-11 8:35 
GeneralRe: SQL DataGridView Pin
Falterfire12-Jul-11 8:58
Falterfire12-Jul-11 8:58 
AnswerRe: SQL DataGridView Pin
PIEBALDconsult12-Jul-11 17:42
mvePIEBALDconsult12-Jul-11 17:42 
QuestionManaged C# DLL called from native C main with callbacks Pin
Stuart Rubin12-Jul-11 4:18
Stuart Rubin12-Jul-11 4:18 
AnswerRe: Managed C# DLL called from native C main with callbacks Pin
Pete O'Hanlon12-Jul-11 5:57
mvePete O'Hanlon12-Jul-11 5:57 
GeneralRe: Managed C# DLL called from native C main with callbacks Pin
GuyThiebaut12-Jul-11 10:28
professionalGuyThiebaut12-Jul-11 10:28 

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.