Click here to Skip to main content
15,891,136 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problem inserting records Pin
Christian Graus12-Sep-05 13:35
protectorChristian Graus12-Sep-05 13:35 
QuestionHow to use this in another handler?? Pin
Anonymous11-Sep-05 12:08
Anonymous11-Sep-05 12:08 
AnswerRe: How to use this in another handler?? Pin
Mohamad Al Husseiny11-Sep-05 12:15
Mohamad Al Husseiny11-Sep-05 12:15 
AnswerRe: How to use this in another handler?? Pin
Christian Graus11-Sep-05 15:27
protectorChristian Graus11-Sep-05 15:27 
QuestionTemplateColumn for DataTable Pin
Expert Coming11-Sep-05 11:13
Expert Coming11-Sep-05 11:13 
AnswerRe: TemplateColumn for DataTable Pin
Andy Brummer11-Sep-05 12:53
sitebuilderAndy Brummer11-Sep-05 12:53 
GeneralRe: TemplateColumn for DataTable Pin
Expert Coming11-Sep-05 13:26
Expert Coming11-Sep-05 13:26 
QuestionUnhandled Ex..Param Null: Value pen??? Pin
Anonymous11-Sep-05 10:22
Anonymous11-Sep-05 10:22 
I'm trying to get my App to always redraw some DrawLine(..) funcs when I
Code compiles ok but then blows sky high w/ "Unhandled Exception"
"Parameter Name: pen"
Help- thanksConfused | :confused:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text.RegularExpressions;

namespace ComplexTest2
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
//Member fields.
private bool bShowValue = false;
private PointF xyOrigin = new PointF();
private PointF cmplxValA = new PointF();
private PointF cmplxValB = new PointF();
//Compiler alert to Pen activePen;
Pen activePen;

//Indent client area to draw rectangle.
public const float xIndent = 25;
public const float yIndent = 25;
//Instantiate the Rectangle for the graph.
public RectangleF graphRect = new RectangleF(xIndent, yIndent, 450, 450);
private System.Windows.Forms.Button buttonAdd;
private System.Windows.Forms.Label labelValueAReal;
private System.Windows.Forms.Label labelValueBReal;
private System.Windows.Forms.Label labelValueAComplex;
private System.Windows.Forms.TextBox textComplexAReal;
private System.Windows.Forms.TextBox textComplexBReal;
private System.Windows.Forms.TextBox textComplexAComplex;
private System.Windows.Forms.TextBox textComplexBComplex;
private System.Windows.Forms.Label labelValueBComplex;
private System.Windows.Forms.Button complexAOK;
private System.Windows.Forms.Button complexBOK;
private System.Windows.Forms.Button button1;

///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.textComplexAReal = new System.Windows.Forms.TextBox();
this.labelValueAReal = new System.Windows.Forms.Label();
this.labelValueBReal = new System.Windows.Forms.Label();
this.textComplexBReal = new System.Windows.Forms.TextBox();
this.textComplexAComplex = new System.Windows.Forms.TextBox();
this.labelValueAComplex = new System.Windows.Forms.Label();
this.textComplexBComplex = new System.Windows.Forms.TextBox();
this.labelValueBComplex = new System.Windows.Forms.Label();
this.buttonAdd = new System.Windows.Forms.Button();
this.complexAOK = new System.Windows.Forms.Button();
this.complexBOK = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textComplexAReal
//
this.textComplexAReal.Location = new System.Drawing.Point(144, 488);
this.textComplexAReal.Name = "textComplexAReal";
this.textComplexAReal.Size = new System.Drawing.Size(72, 20);
this.textComplexAReal.TabIndex = 0;
this.textComplexAReal.Text = "";
this.textComplexAReal.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// labelValueAReal
//
this.labelValueAReal.Font = new System.Drawing.Font("Comic Sans MS", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.labelValueAReal.Location = new System.Drawing.Point(32, 488);
this.labelValueAReal.Name = "labelValueAReal";
this.labelValueAReal.Size = new System.Drawing.Size(104, 16);
this.labelValueAReal.TabIndex = 1;
this.labelValueAReal.Text = "Value A: Real";
//
// labelValueBReal
//
this.labelValueBReal.Font = new System.Drawing.Font("Comic Sans MS", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.labelValueBReal.Location = new System.Drawing.Point(32, 520);
this.labelValueBReal.Name = "labelValueBReal";
this.labelValueBReal.Size = new System.Drawing.Size(104, 16);
this.labelValueBReal.TabIndex = 2;
this.labelValueBReal.Text = "Value B: Real";
//
// textComplexBReal
//
this.textComplexBReal.Location = new System.Drawing.Point(144, 520);
this.textComplexBReal.Name = "textComplexBReal";
this.textComplexBReal.Size = new System.Drawing.Size(72, 20);
this.textComplexBReal.TabIndex = 3;
this.textComplexBReal.Text = "";
this.textComplexBReal.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// textComplexAComplex
//
this.textComplexAComplex.Location = new System.Drawing.Point(408, 488);
this.textComplexAComplex.Name = "textComplexAComplex";
this.textComplexAComplex.Size = new System.Drawing.Size(72, 20);
this.textComplexAComplex.TabIndex = 4;
this.textComplexAComplex.Text = "";
this.textComplexAComplex.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// labelValueAComplex
//
this.labelValueAComplex.Font = new System.Drawing.Font("Comic Sans MS", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.labelValueAComplex.Location = new System.Drawing.Point(240, 488);
this.labelValueAComplex.Name = "labelValueAComplex";
this.labelValueAComplex.Size = new System.Drawing.Size(144, 16);
this.labelValueAComplex.TabIndex = 5;
this.labelValueAComplex.Text = "Value A: Imaginary";
//
// textComplexBComplex
//
this.textComplexBComplex.Location = new System.Drawing.Point(408, 520);
this.textComplexBComplex.Name = "textComplexBComplex";
this.textComplexBComplex.Size = new System.Drawing.Size(72, 20);
this.textComplexBComplex.TabIndex = 6;
this.textComplexBComplex.Text = "";
this.textComplexBComplex.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// labelValueBComplex
//
this.labelValueBComplex.Font = new System.Drawing.Font("Comic Sans MS", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.labelValueBComplex.Location = new System.Drawing.Point(240, 520);
this.labelValueBComplex.Name = "labelValueBComplex";
this.labelValueBComplex.Size = new System.Drawing.Size(136, 16);
this.labelValueBComplex.TabIndex = 7;
this.labelValueBComplex.Text = "Value B: Imaginary";
//
// buttonAdd
//
this.buttonAdd.Font = new System.Drawing.Font("Comic Sans MS", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.buttonAdd.Location = new System.Drawing.Point(496, 48);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.TabIndex = 8;
this.buttonAdd.Text = "A + B";
//
// complexAOK
//
this.complexAOK.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.complexAOK.Location = new System.Drawing.Point(496, 488);
this.complexAOK.Name = "complexAOK";
this.complexAOK.TabIndex = 9;
this.complexAOK.Text = "Enter A:";
this.complexAOK.Click += new System.EventHandler(this.complexA_OK_Click);
//
// complexBOK
//
this.complexBOK.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.complexBOK.Location = new System.Drawing.Point(496, 520);
this.complexBOK.Name = "complexBOK";
this.complexBOK.TabIndex = 10;
this.complexBOK.Text = "Enter B:";
this.complexBOK.Click += new System.EventHandler(this.complexB_OK_Click);
//
// button1
//
this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.button1.Location = new System.Drawing.Point(496, 384);
this.button1.Name = "button1";
this.button1.TabIndex = 11;
this.button1.Text = "Clear";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(592, 566);
this.Controls.Add(this.button1);
this.Controls.Add(this.complexBOK);
this.Controls.Add(this.complexAOK);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.textComplexBComplex);
this.Controls.Add(this.textComplexAComplex);
this.Controls.Add(this.textComplexBReal);
this.Controls.Add(this.textComplexAReal);
this.Controls.Add(this.labelValueBComplex);
this.Controls.Add(this.labelValueAComplex);
this.Controls.Add(this.labelValueBReal);
this.Controls.Add(this.labelValueAReal);
this.Name = "Form1";
this.Text = "Complex Pair";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.ResumeLayout(false);

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
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);
DrawComplexNumberA(this.CreateGraphics(), activePen, cmplxValA.X, cmplxValA.Y);
DrawComplexNumberB(this.CreateGraphics(), activePen, cmplxValB.X, cmplxValB.Y);
}
//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 activePen = new Pen(Color.Coral, 4);
//
try
{
bShowValue = true;
cmplxValA.X = (float)Convert.ToDouble(this.textComplexAReal.Text);
cmplxValA.Y = (float)Convert.ToDouble(this.textComplexAComplex.Text);
DrawComplexNumberA(g,activePen, cmplxValA.X, cmplxValA.Y);
}
catch
{
MessageBox.Show("Invalid Complex A Number", "Error!");
}
}

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

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

void DrawComplexNumberB(Graphics g, Pen activePen, double re_, double im_)
{
g.DrawLine(activePen, (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: Unhandled Ex..Param Null: Value pen??? Pin
Anonymous11-Sep-05 10:38
Anonymous11-Sep-05 10:38 
QuestionRe: Unhandled Ex..Param Null: Value pen??? Pin
Guffa11-Sep-05 10:42
Guffa11-Sep-05 10:42 
AnswerRe: Unhandled Ex..Param Null: Value pen??? Pin
Anonymous11-Sep-05 10:47
Anonymous11-Sep-05 10:47 
GeneralRe: Unhandled Ex..Param Null: Value pen??? Pin
Guffa11-Sep-05 10:57
Guffa11-Sep-05 10:57 
GeneralRe: Unhandled Ex..Param Null: Value pen??? Pin
Anonymous11-Sep-05 11:03
Anonymous11-Sep-05 11:03 
AnswerRe: Unhandled Ex..Param Null: Value pen??? Pin
Mohamad Al Husseiny11-Sep-05 11:32
Mohamad Al Husseiny11-Sep-05 11:32 
GeneralRe: Unhandled Ex..Param Null: Value pen??? Pin
Anonymous11-Sep-05 12:17
Anonymous11-Sep-05 12:17 
GeneralRe: Unhandled Ex..Param Null: Value pen??? Pin
Mohamad Al Husseiny11-Sep-05 12:19
Mohamad Al Husseiny11-Sep-05 12:19 
Questionproblem in DLL calling Pin
Jassim Rahma11-Sep-05 10:01
Jassim Rahma11-Sep-05 10:01 
QuestionRe: problem in DLL calling Pin
Guffa11-Sep-05 10:43
Guffa11-Sep-05 10:43 
QuestionDevelopment of setup and deployment projects(MSI files)! Pin
lata07mahi11-Sep-05 9:55
lata07mahi11-Sep-05 9:55 
AnswerRe: Development of setup and deployment projects(MSI files)! Pin
Mohamad Al Husseiny11-Sep-05 10:06
Mohamad Al Husseiny11-Sep-05 10:06 
QuestionConst vars Pin
Niklas Ulvinge11-Sep-05 9:26
Niklas Ulvinge11-Sep-05 9:26 
AnswerRe: Const vars Pin
Guffa11-Sep-05 9:41
Guffa11-Sep-05 9:41 
GeneralRe: Const vars Pin
Niklas Ulvinge11-Sep-05 21:43
Niklas Ulvinge11-Sep-05 21:43 
AnswerRe: Const vars Pin
S. Senthil Kumar12-Sep-05 0:24
S. Senthil Kumar12-Sep-05 0:24 
GeneralRe: Const vars Pin
Niklas Ulvinge12-Sep-05 3:42
Niklas Ulvinge12-Sep-05 3:42 

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.