|
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
|
|
|
|
|
|
|
Hi,
I am trying to create an eventlog DLL which uses vistaDB but I have a
problem calling it.. can you please help...
I have created the DLL but I don't know what is the problem in calling it?!
the DLL:
using System;
using VistaDB;
namespace eventlogDLL
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class eventlog
{
public eventlog()
{
//
// TODO: Add constructor logic here
//
}
public void addlog(string log_app, string log_description, string
log_user, string log_ip, string log_os, string log_computer)
{
// Database;
VistaDBDatabase logDatabase = new VistaDBDatabase();
VistaDBTable logTable = new VistaDBTable();
// Database File;
// string strDatabase =
Path.GetDirectoryName(Application.ExecutablePath) +
"\\Database\\eventlog.vdb";
string strDatabase = "C:\\Documents and Settings\\Jassim Rahma\\My
Documents\\Visual Studio Projects\\Ezi-Work\\Database\\eventlog.vdb";
// connect to database;
logDatabase.DatabaseName = strDatabase;
logDatabase.Cypher = CypherType.Blowfish;
logDatabase.Password = "17218881";
logDatabase.Parameters = 0;
logDatabase.Exclusive = true;
logDatabase.Connect();
// open proposal age tables;
logTable.Database = logDatabase;
logTable.TableName = "EVENT_LOG";
logTable.Open();
// add new eventlog;
logTable.Insert();
logTable.PutString("EZI_NAME", log_app);
logTable.PutMemo("HIGHEST_SUM_INSURED", log_description);
logTable.PutString("EZI_REMARKS", log_user);
logTable.PutString("CREATED_BY_USER", log_ip);
logTable.PutString("CREATED_BY_USER", log_os);
logTable.PutString("CREATED_BY_COMPUTER", log_computer);
logTable.PutDateTime("CREATED_BY_DATE", DateTime.Now);
logTable.Post();
//Close table
logTable.Close();
//Close database
logDatabase.Close();
}
}
}
and calling it:
using eventlogDLL;
eventlog EventLog = new eventlog();
eventlog.addlog("Ezi-Life", "New Ezi-Life Record was added", "jrahma",
"192.168.250.11", "Windows XP", "JASIM");
Best Regards,
Jassim Rahma
|
|
|
|
|
What is the problem then?
---
b { font-weight: normal; }
|
|
|
|
|
Hi all,
Can anyone guide me on development of setup and deployment projects in .net or any other windows installer tool?
Please help at the earliest.Any help would be appreciated.
Regards,
Lata Agrawal
|
|
|
|
|
|
I want to make some variables contstant.
This is the important part of the code:
namespace NiklasUlvinge.ChipsEater
{
abstract class Item
{
...
protected Brush surf = Brushes.LightGray;
protected Pen side = Pens.DarkGray;
protected Pen loff = Pens.Black;
protected Pen lon = Pens.Red;
...
}
...
}
I want child's to Item to be able ot accsess those pens, and it would be better if they where constant.
If I make the constant it give's me error like Pens.Red isn't a constant variable.
How do I make them constant?
Niklas Ulvinge aka IDK
|
|
|
|
|
You don't. Objects can't be constants.
You can make them static, though.
---
b { font-weight: normal; }
|
|
|
|
|
Thanks, that's what I was looking for.
Niklas Ulvinge aka IDK
|
|
|
|
|
Make them readonly . That way, no one else can do surf = Brushes.Yellow or something like that.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Now it is:
readonly static protected Brush surf = Brushes.LightGray;
Isn't that the same as a const,
Readonly and only belongs to the type?
Niklas Ulvinge aka IDK
|
|
|
|
|