|
This is a development version to get past a hump point, it contains only the controls necessary to bind to the dataset and enforce the required business rule constraints. The problem is databinding the selected index of a combobox. If you can't help please stay out of the loop.
|
|
|
|
|
rich_wenger wrote:
If you can't help please stay out of the loop.
I can help, but first I need to know what is going wrong, and I'm sure not going to read 1000 lines to try and work that out. So you find it easier to work on proof of concept when none of your code is readable ? Brilliant.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
Sorry, the error I get is 'An unhandled exception of type 'System.Data.NoNullAllowedException' occurred in system.data.dll'; but this error only occurrs if I attempt to insert a record without first performing a search. Otherwise the insert fires successfully but over-writes an existing record (doesn't create a new one).
|
|
|
|
|
This code is unreadable. It also is useless, you've pasted your entire file in here, which tells me you've done nothing to work out exactly where the error is. Do you know how to use the debugger ?
I tried to create this project myself to see if it would run ( although I didn't expect it to ), but private ImmediateAccessWIP.dsStaffPhysicians dsStaffPhysicians1; means that no-one can try to run your code to see what's going on. So why post all this boiler plate stuff here ?
Debug your code, figure out exactly what is happening, what is being called, and where things go wrong. Then, post the offending code and more people will try to help, because it will look like you did something first, and we'll have some idea where we are looking for a problem.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm sorry. I've assumed that you were familiar with VS2003 you would know everything above the Main() method was IDE generated (therefore it's most likely the problem exits below). I have attempted to debug the code; if you know how to databind a combobox on the selected index that would be of help. Otherwise please end the thread.
|
|
|
|
|
rich_wenger wrote:
I've assumed that you were familiar with VS2003 you would know everything above the Main() method was IDE generated
But you assumed I'd like to download that code every time I read this page ? And that it's my job to trawl through this IDE generated code to find your stuff ?
rich_wenger wrote:
I have attempted to debug the code
So - what happened ?
rich_wenger wrote:
if you know how to databind a combobox on the selected index that would be of help
How do you mean ? You want to databind one control based on the selected index of another ?
rich_wenger wrote:
Otherwise please end the thread.
This is a community site. I'm a developer who uses this site and is trying to help you, I am not staff on this site. No-one ends threads here, the site doesn't even support thread locking AFAIK.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
But you're not trying to help; you're trying to lecture. I'm looking for help. If you PC is slow copy the code to notepad, maybe that will help. I didn't assume anything about your job; I'm new to C-Sharp and asking for help databinding a control to a dataset. Do you have any exptertise in that area or not?
|
|
|
|
|
rich_wenger wrote:
But you're not trying to help; you're trying to lecture. I'm looking for help.
You want me to help, without pointing out the things you're doing wrong ? I'm trying both to give you advice as to why no-one has helped you ( your post showed all the signs of you giving the problem no thought yourself, it contains a lot of code that cannot be the problem, you don't bother to say where the problem is, or even exactly what it is ), and to work out what's going on so I can offer help.
rich_wenger wrote:
If you PC is slow copy the code to notepad, maybe that will help.
I have a fast computer, but my network connection is slow. I copied the code to VS, as it happens, but it isn't enough to compile and run ( which would be the only reason for posting so much code ). The point is that some people read this site on 28.8, they are being forced to download all this pointless code every time they open this page, and people who read your post will almost all immediately disregard it because it is so long and obviously unfocused.
rich_wenger wrote:
I'm new to C-Sharp and asking for help databinding a control to a dataset.
Well, it depends on the type of control, a combobox or listview needs to be told what columns to databind to, and you need to also select a table or view from the dataset to bind against.
rich_wenger wrote:
Do you have any exptertise in that area or not?
If I didn't, I wouldn't have bothered answering at all.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
I don't what ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
private void button1_Click(object sender, System.EventArgs e)
{
/*bool*/ bValueState = false;
Invalidate();
}
|
|
|
|
|
Can you explain more
MCAD
|
|
|
|
|
To reuse the one handler for multiple buttons, use the sender property to work out which button invoked the method.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Why isn't this working?
TemplateColumn tcTextBox = new TemplateColumn();<br />
tcTextBox.ItemTemplate = new DataGridTemplate(ListItemType.Header, "Change");<br />
tcTextBox.ItemTemplate = new DataGridTemplate(ListItemType.Item, "Change");<br />
tcTextBox.EditItemTemplate = new DataGridTemplate(ListItemType.EditItem, "Change");<br />
tcTextBox.ItemTemplate = new DataGridTemplate(ListItemType.Footer, "Change");<br />
DataColumn dcTextBox = new DataColumn(tcTextBox.ToString());<br />
dtshowskills.Columns.Add(dcTextBox);<br />
<br />
public void InstantiateIn(System.Web.UI.Control container)<br />
{<br />
Literal lc = new Literal();<br />
switch(templateType)<br />
{<br />
case ListItemType.Header:<br />
lc.Text = "" + columnName + "";<br />
container.Controls.Add(lc);<br />
break;<br />
case ListItemType.Item:<br />
lc.Text = "Item " + columnName;<br />
container.Controls.Add(lc);<br />
break;<br />
case ListItemType.EditItem:<br />
TextBox tb = new TextBox();<br />
tb.Text = "";<br />
container.Controls.Add(tb);<br />
break;<br />
case ListItemType.Footer:<br />
lc.Text = "" + columnName + "";<br />
container.Controls.Add(lc);<br />
break;<br />
}<br />
}<br />
}
Thanks in advance!
|
|
|
|
|
You forgot to mention your problem again. In the mean time, you might want to take a look at articles like this one:
http://www.codeproject.com/aspnet/datagriddemo.asp[^]
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
Now my problem is different. Now I can't get the datatable to add my template column, it won't actually add the textbox into it. And also, how do I get the program to call InitializeComponent first? This is my updated code.
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
// Make the Datagrid
CreateTable();
}
public void CreateTable ()
{
//Make the 'askills' array dynamically set
///Sets all of the Skills to the array 'askills'
askills[0] = "Attack";
askills[1] = "Strength";
askills[2] = "Defense";
askills[3] = "Ranged";
askills[4] = "Prayer";
askills[5] = "Magic";
askills[6] = "Runecrafting";
askills[7] = "Hitpoints";
askills[8] = "Agility";
askills[9] = "Herblore";
askills[10] = "Thieving";
askills[11] = "Crafting";
askills[12] = "Fleching";
askills[13] = "Slayer";
askills[14] = "Mining";
askills[15] = "Smelting";
askills[16] = "Fishing";
askills[17] = "Cooking";
askills[18] = "Firemaking";
askills[19] = "Woodcutting";
askills[20] = "Farming";
///Our connection string to the DB and open it
string szConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\inetpub\\kenkemkalrisell\\runescape\\databases\\runescapestats.mdb";
cn = new OleDbConnection(szConn);
///Open the database
OpenDB(cn);
StringBuilder szMyQuery = new StringBuilder ();
szMyQuery.AppendFormat ("SELECT User.Username, realStats.Attack, realStats.Strength, realStats.Defense, realStats.Ranged, realStats.Prayer, realStats.Magic, realStats.Runecrafting, realStats.Hitpoints, realStats.Agility, realStats.Herblore, realStats.Thieving, realStats.Crafting, realStats.Fleching, realStats.Slayer, realStats.Mining, realStats.Smelting, realStats.Fishing, realStats.Cooking, realStats.Firemaking, realStats.Woodcutting, realStats.Farming FROM [User] INNER JOIN realStats ON User.ID = realStats.ID WHERE (((User.Username)='{0}'))", szUsername);
OleDbCommand cmd = new OleDbCommand(szMyQuery.ToString (), cn);
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
int iAttackOrdinal = rdr.GetOrdinal("Attack");
int intAttack = rdr.GetInt32(iAttackOrdinal);
int iStrengthOrdinal = rdr.GetOrdinal("Strength");
int intStrength = rdr.GetInt32(iStrengthOrdinal);
int iDefenseOrdinal = rdr.GetOrdinal("Defense");
int intDefense = rdr.GetInt32(iDefenseOrdinal);
int iRangedOrdinal = rdr.GetOrdinal("Ranged");
int intRanged = rdr.GetInt32(iRangedOrdinal);
int iPrayerOrdinal = rdr.GetOrdinal("Prayer");
int intPrayer = rdr.GetInt32(iPrayerOrdinal);
int iMagicOrdinal = rdr.GetOrdinal("Magic");
int intMagic = rdr.GetInt32(iMagicOrdinal);
int iRunecraftingOrdinal = rdr.GetOrdinal("Runecrafting");
int intRunecrafting = rdr.GetInt32(iRunecraftingOrdinal);
int iHitpointsOrdinal = rdr.GetOrdinal("Hitpoints");
int intHitpoints = rdr.GetInt32(iHitpointsOrdinal);
int iAgilityOrdinal = rdr.GetOrdinal("Agility");
int intAgility = rdr.GetInt32(iAgilityOrdinal);
int iHerbloreOrdinal = rdr.GetOrdinal("Herblore");
int intHerblore = rdr.GetInt32(iHerbloreOrdinal);
int iThievingOrdinal = rdr.GetOrdinal("Thieving");
int intThieving = rdr.GetInt32(iThievingOrdinal);
int iCraftingOrdinal = rdr.GetOrdinal("Crafting");
int intCrafting = rdr.GetInt32(iCraftingOrdinal);
int iFlechingOrdinal = rdr.GetOrdinal("Fleching");
int intFleching = rdr.GetInt32(iFlechingOrdinal);
int iSlayerOrdinal = rdr.GetOrdinal("Slayer");
int intSlayer = rdr.GetInt32(iSlayerOrdinal);
int iMiningOrdinal = rdr.GetOrdinal("Mining");
int intMining = rdr.GetInt32(iMiningOrdinal);
int iSmeltingOrdinal = rdr.GetOrdinal("Smelting");
int intSmelting = rdr.GetInt32(iSmeltingOrdinal);
int iFishingOrdinal = rdr.GetOrdinal("Fishing");
int intFishing = rdr.GetInt32(iFishingOrdinal);
int iCookingOrdinal = rdr.GetOrdinal("Cooking");
int intCooking = rdr.GetInt32(iCookingOrdinal);
int iFiremakingOrdinal = rdr.GetOrdinal("Firemaking");
int intFiremaking = rdr.GetInt32(iFiremakingOrdinal);
int iWoodcuttingOrdinal = rdr.GetOrdinal("Woodcutting");
int intWoodcutting = rdr.GetInt32(iWoodcuttingOrdinal);
int iFarmingOrdinal = rdr.GetOrdinal("Farming");
int intFarming = rdr.GetInt32(iFarmingOrdinal);
alevel[0] = intAttack;
alevel[1] = intStrength;
alevel[2] = intDefense;
alevel[3] = intRanged;
alevel[4] = intPrayer;
alevel[5] = intMagic;
alevel[6] = intRunecrafting;
alevel[7] = intHitpoints;
alevel[8] = intAgility;
alevel[9] = intHerblore;
alevel[10] = intThieving;
alevel[11] = intCrafting;
alevel[12] = intFleching;
alevel[13] = intSlayer;
alevel[14] = intMining;
alevel[15] = intSmelting;
alevel[16] = intFishing;
alevel[17] = intCooking;
alevel[18] = intFiremaking;
alevel[19] = intWoodcutting;
alevel[20] = intFarming;
}
rdr.Close();
CloseDB(cn);
///The creation of the table that shows the user their stats from the database
///Dynamic Creation of the datatable
///Also sets up the new datatable
DataTable dtshowskills = new DataTable("USkills");
DataColumn dcuserSkill = new DataColumn("Skill");
dcuserSkill.DataType = System.Type.GetType("System.String");
dtshowskills.Columns.Add(dcuserSkill);
DataColumn dcuserLevel = new DataColumn("Level");
dcuserLevel.DataType = System.Type.GetType("System.Int32");
dtshowskills.Columns.Add(dcuserLevel);
DataColumn dcgoalLevel = new DataColumn("Goal");
dcgoalLevel.DataType = System.Type.GetType("System.Int32");
dtshowskills.Columns.Add(dcgoalLevel);
int i = 0;
while (i <= 20)
{
DataRow drskill = dtshowskills.NewRow();
drskill["Skill"] = askills[i];
drskill["Level"] = alevel[i];
drskill["Goal"] = agoal[i];
dtshowskills.Rows.Add(drskill);
i++;
}
TemplateColumn tcTextBoxes = new TemplateColumn();
tcTextBoxes.HeaderTemplate = new DataGridTemplate(ListItemType.Header, "Change Goals");
//tcTextBoxes.ItemTemplate = new DataGridTemplate(ListItemType.Item, "Change Goals");
tcTextBoxes.EditItemTemplate = new DataGridTemplate(ListItemType.EditItem, "Change Goals");
tcTextBoxes.FooterTemplate = new DataGridTemplate(ListItemType.Footer, "Change Goals");
dgSkills.Columns.Add(tcTextBoxes);
dgSkills.DataSource = dtshowskills;
dgSkills.DataBind();
}
public class DataGridTemplate : ITemplate
{
ListItemType templateType;
string columnName;
public DataGridTemplate(ListItemType type, string colname)
{
templateType = type;
columnName = colname;
}
public void InstantiateIn(System.Web.UI.Control container)
{
Literal lc = new Literal();
switch(templateType)
{
case ListItemType.Header:
lc.Text = "" + columnName + "";
container.Controls.Add(lc);
break;
case ListItemType.Item:
lc.Text = "Item " + columnName;
container.Controls.Add(lc);
break;
case ListItemType.EditItem:
TextBox tb = new TextBox();
tb.Text = "Hello";
container.Controls.Add(tb);
break;
case ListItemType.Footer:
lc.Text = "" + columnName + "";
container.Controls.Add(lc);
break;
}
}
}
Thanks for all your help.
|
|
|
|
|
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- thanks
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();
}
}
}
|
|
|
|
|
Sorry- Forgot to close some regions. Won't post so much code again...
|
|
|
|
|
Preferably only post the code that has something to do with the error, not all code that you ever have written... At least use the pre tag so that the code retains it's indentation.
Where in all that code do you get the exception? The stack trace from the error message would be helpful if one should try to follow the flow of the code.
---
b { font-weight: normal; }
|
|
|
|
|
Thanks,
Unfortunately I'm trying to self learn this stuff. I wouldn't know a "stack trace" from the Tooth Fairy.....
|
|
|
|
|
The stack trace is the part of the error message that shows the calls that were made in the code leading to the point where the error occured.
---
b { font-weight: normal; }
|
|
|
|
|
Guffa,
Is it this? --thanks Does this mean I "ran" a stack trace?
//////////////////////////////////
ystem.ArgumentNullException: Value cannot be null.
Parameter name: pen
at System.Drawing.Graphics.DrawLine(Pen pen, Single x1, Single y1, Single x2, Single y2)
at ComplexTest2.Form1.DrawComplexNumberA(Graphics g, Pen activePen, Double re_, Double im_) in c:\documents and settings\xyz\my documents\software eng\c#_projects\c#_ tempfiles\complextest2\form1.cs:line 341
at ComplexTest2.Form1.Form1_Paint(Object sender, PaintEventArgs e) in c:\documents and settings\xyz\my documents\software eng\c#_projects\c#_ tempfiles\complextest2\form1.cs:line 240
at System.Windows.Forms.Control.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Form.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
|
|
|
|
|
you declared active pen at form level and never Initialized it So when you called DrawComplexNumberA in your Form1_Paint and passed activePen to it you actually passed null value because activePen never initialized before you may say that you initialized it at
private void complexA_OK_Click(object sender, System.EventArgs e)
{
Graphics g = this.CreateGraphics();
<big>Pen activePen = new Pen(Color.Coral, 4);</big>
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!");
}
}
and do the similar thing in the other button but what you did here that you didn't initialized activePen you instead create new one which will not be visible outside complexA_OK_Click So to initialize activePen not create new one replace
<big>Pen </big>activePen = new Pen(Color.Coral, 4);
in complexA_OK_Click and complexB_OK_Click
With this one
activePen=new Pen(Color.Coral, 4);
Note that i remove the forward Pen Decleration
MCAD
-- modified at 18:10 Sunday 11th September, 2005
|
|
|
|
|
|