Click here to Skip to main content
15,895,142 members
Home / Discussions / C#
   

C#

 
QuestionWeb enable a Windows C# app Pin
StrayGrey10-Sep-05 20:06
StrayGrey10-Sep-05 20:06 
AnswerRe: Web enable a Windows C# app Pin
Guffa11-Sep-05 0:02
Guffa11-Sep-05 0:02 
QuestionDataTable PlaceHolder Pin
Expert Coming10-Sep-05 18:40
Expert Coming10-Sep-05 18:40 
AnswerRe: DataTable PlaceHolder Pin
rudy.net11-Sep-05 16:41
rudy.net11-Sep-05 16:41 
QuestionUsing GDI+ functions in a class library Pin
Steve Messer10-Sep-05 17:43
Steve Messer10-Sep-05 17:43 
AnswerRe: Using GDI+ functions in a class library Pin
Andrew Kirillov10-Sep-05 21:03
Andrew Kirillov10-Sep-05 21:03 
GeneralRe: Using GDI+ functions in a class library Pin
Steve Messer10-Sep-05 21:39
Steve Messer10-Sep-05 21:39 
QuestionMessageBox erases lines drawn???? Pin
Anonymous10-Sep-05 16:00
Anonymous10-Sep-05 16:00 
I have a WinForm that contains a RectF. I have methods to draw inside the RectF as in, DrawLine(...).
I also have a bool flag in a try/catch block that throws up a MessageBox if the line params (they come from TextBoxes linked to Button events) are false.
Now here's the problem....
When I click the "OK" or the "x" on the MessageBox, the line(s) gets erased partially, based on where the MessageBox overlapped the line.
The RectF, the graph axes and labels all remain. What's up w/ that??
thanks....
Here's some of the code.....
////////////////////////////////////////////////////////////////////////
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
DrawGraphRectF(e.Graphics);
DrawXYAxes(e.Graphics);
DrawGraphXandYTicks(e.Graphics);
}
//Background "reference" rectangle
void DrawGraphRectF(Graphics g)
{
Pen rectPen = new Pen(Color.BlueViolet);
g.DrawRectangle(rectPen, xIndent, yIndent, graphRect.Width, graphRect.Height);
g.FillRectangle(new SolidBrush(Color.Snow), xIndent + 1, yIndent + 1, graphRect.Width - 1, graphRect.Height - 1);
rectPen.Dispose();
}

//Draw x and y axes.
void DrawXYAxes(Graphics g)
{
Pen axisPen = new Pen(new SolidBrush(Color.BlueViolet), 1);
g.DrawLine(axisPen, xIndent, yIndent + graphRect.Height/2, xIndent + graphRect.Width, yIndent + graphRect.Height/2);
g.DrawLine(axisPen, xIndent + graphRect.Width/2, yIndent, xIndent + graphRect.Width/2, yIndent + graphRect.Height);
axisPen.Dispose();
}

//Draw tick marks on the axes.
void DrawGraphXandYTicks(Graphics g)
{
Pen tickPen = new Pen(new SolidBrush(Color.Black), 1);
//Draw x-axis ticks and label graph.
float fxAxis = -8.0f;
float fyAxis = 8.0f;
PointF xtickPoint = new PointF(xIndent, yIndent + graphRect.Height/2);
PointF ytickPoint = new PointF(xIndent + graphRect.Width/2, yIndent);
Font labelFont = new Font("Courier",6);
SolidBrush labelBrush = new SolidBrush(Color.Black);
StringFormat strFmt = new StringFormat();

//Draw x axis ticks and float labels.
for(float fx = 2 * xtickPoint.X; fx <= graphRect.Width; fx += xtickPoint.X)
{
//string measureString = f.ToString("f1");
//float measureLength = measureString.Length;
if(fxAxis == 0.0f)
{
fxAxis += 1.0f;
fx += xtickPoint.X;
}
g.DrawLine(tickPen, fx, xtickPoint.Y - 2, fx, xtickPoint.Y + 2);
g.DrawString((fxAxis > 0? "+" : "" ) + fxAxis.ToString("f1"), labelFont, labelBrush, fx - 7, xtickPoint.Y + 7);
fxAxis++;
}

//Draw y-axis ticks and float labels.
for(float fy = 2 * ytickPoint.Y; fy <= graphRect.Height; fy += ytickPoint.Y)
{
if(fyAxis == 0.0f)
{
fyAxis -= 1.0f;
fy += ytickPoint.Y;
}
g.DrawLine(tickPen, ytickPoint.X - 2, fy, xtickPoint.Y + 2, fy);
g.DrawString((fyAxis > 0? "+" : "") + fyAxis.ToString("f1"), labelFont, labelBrush, ytickPoint.X + 5, fy - 3);
fyAxis--;
}
tickPen.Dispose();
}

private void complexA_OK_Click(object sender, System.EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen cmplxPen = new Pen(Color.Coral, 4);
//
try
{
bShowValue = true;
mValReal = Convert.ToDouble(this.textComplexAReal.Text);
mValComplex = Convert.ToDouble(this.textComplexAComplex.Text);
DrawComplexNumber(g,cmplxPen, mValReal, mValComplex);
bShowValue = false;
}
catch
{
MessageBox.Show("Invalid Complex A Number", "Error!");
}
}

private void complexB_OK_Click(object sender, System.EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen cmplxPen = new Pen(Color.Green, 4);
//
try
{
mValReal = Convert.ToDouble(this.textComplexBReal.Text);
mValComplex = Convert.ToDouble(this.textComplexBComplex.Text);
DrawComplexNumber(g, cmplxPen, mValReal, mValComplex);
}
catch
{
MessageBox.Show("Invalid Complex B Number", "Error!");
}
}

void DrawComplexNumber(Graphics g, Pen cmplxPen, double re_, double im_)
{
g.DrawLine(cmplxPen, (xIndent + graphRect.Width/2), (yIndent + graphRect.Height/2), (xIndent + graphRect.Width/2) + (float)(re_ * xIndent), (yIndent + graphRect.Height/2) - (float)(im_ * yIndent));
}

private void button1_Click(object sender, System.EventArgs e)
{
Invalidate();
}

}
}
AnswerRe: MessageBox erases lines drawn???? Pin
Dave Kreskowiak10-Sep-05 16:17
mveDave Kreskowiak10-Sep-05 16:17 
QuestionAnyway to be notified of time changes Pin
monrobot1310-Sep-05 13:27
monrobot1310-Sep-05 13:27 
AnswerRe: Anyway to be notified of time changes Pin
Mohamad Al Husseiny10-Sep-05 14:33
Mohamad Al Husseiny10-Sep-05 14:33 
GeneralRe: Anyway to be notified of time changes Pin
Dave Kreskowiak10-Sep-05 16:08
mveDave Kreskowiak10-Sep-05 16:08 
GeneralRe: Anyway to be notified of time changes Pin
Mohamad Al Husseiny11-Sep-05 7:22
Mohamad Al Husseiny11-Sep-05 7:22 
GeneralRe: Anyway to be notified of time changes Pin
Dave Kreskowiak12-Sep-05 1:25
mveDave Kreskowiak12-Sep-05 1:25 
AnswerRe: Anyway to be notified of time changes Pin
Dave Kreskowiak10-Sep-05 16:09
mveDave Kreskowiak10-Sep-05 16:09 
AnswerRe: Anyway to be notified of time changes Pin
Andy Brummer10-Sep-05 17:11
sitebuilderAndy Brummer10-Sep-05 17:11 
GeneralRe: Anyway to be notified of time changes Pin
monrobot1311-Sep-05 7:28
monrobot1311-Sep-05 7:28 
AnswerRe: Anyway to be notified of time changes Pin
Matt Gerrans10-Sep-05 20:03
Matt Gerrans10-Sep-05 20:03 
QuestionWhich treenode called the contextmenustrip? Pin
MrR_10-Sep-05 12:48
MrR_10-Sep-05 12:48 
Answer[Message Deleted] Pin
Mohamad Al Husseiny10-Sep-05 13:44
Mohamad Al Husseiny10-Sep-05 13:44 
AnswerRe: Which treenode called the contextmenustrip? Pin
Mohamad Al Husseiny10-Sep-05 13:57
Mohamad Al Husseiny10-Sep-05 13:57 
GeneralRe: Which treenode called the contextmenustrip? Pin
MrR_10-Sep-05 17:38
MrR_10-Sep-05 17:38 
AnswerRe: Which treenode called the contextmenustrip? Pin
Mohamad Al Husseiny11-Sep-05 7:35
Mohamad Al Husseiny11-Sep-05 7:35 
QuestionNeed to pass a Pen into Form_1Paint Pin
Anonymous10-Sep-05 8:02
Anonymous10-Sep-05 8:02 
AnswerSorry, forgot to add the Function-&gt; HERE Pin
...---...10-Sep-05 8:04
...---...10-Sep-05 8:04 

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.