Need a bit of C# help

M

MFC

Ok, after three C# books, (C# How to Program, Programming in the Key
of C#, and C# Weekend Crash Course) and three weeks, I believe I have
tried everything to make a certain form function correctly. I am
trying to learn C# after playing around for a bit with procedural
programming with PHP, not OOP, and believe I have learned quite a bit
in three weeks, just not enough to accomplish this one task.

If anyone has a bit of free time and wants to impress the hell out of
me, I would love to get this problem behind me. Thanks to Jon a few
weeks back for giving me some direction, and I tried to get it
running, but to no avail.

Specifics:

1) Form is part of an MDI app developed in VS 2003 Architect

2) Form basically calculates the speed an engine operates based on
certain parameters the user enters. (gear sizes, roller circumference,
max rpm, etc.)

3) Results should calculate each time a variable has been changed by
the user, preferably without the user clicking a calculate button.

4) This is the part the gives me the headache: Results need to be
sorted in a textbox, or possibly a listview with columns, but that's
not a necessity, sorted by engine speed(mph) or ratio, either one, and
each ratio and gear combination need to be listed as well. Example of
one line:

Gears Ratio Speed
15/21 1.400 75.47
....next line, etc....

If you view the form, it will hopefully make better sense. Also,
currently, the form blows up if you select anything except and engine
first. I can fix that, but just have not since I have been trying to
get the results sorted in the textbox.

Looking forward to whatever help is received ...sorry, no prizes :/


Thanks,

Mark




Begin Code
---------------------------------


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace MCFCorpDevProd
{
/// <summary>
/// Summary description for GearSelectionDlg.
/// </summary>
public class GearSelectionDlg : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBoxEngine;
private System.Windows.Forms.GroupBox
groupBoxSprocketSizes;
private System.Windows.Forms.NumericUpDown
numericUpDownSmallestCounter;
private System.Windows.Forms.NumericUpDown
numericUpDownLargestCounter;
private System.Windows.Forms.NumericUpDown
numericUpDownSmallestAxle;
private System.Windows.Forms.NumericUpDown
numericUpDownLargestAxle;
private System.Windows.Forms.Label
labelSmallestCounter;
private System.Windows.Forms.Label
labelLargestCounter;
private System.Windows.Forms.Label
labelSmallestAxleSprocket;
private System.Windows.Forms.Label
labelLargestAxleSprocket;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.GroupBox
groupBoxMaximumEngineRPM;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button buttonClose;
private System.Windows.Forms.TextBox textBoxResults;
private System.Windows.Forms.NumericUpDown
numericUpDownRPM;
private System.Windows.Forms.Button buttonCopy;
private System.Windows.Forms.RadioButton
radioButtonEngine1;
private System.Windows.Forms.RadioButton
radioButtonEngine2;
private System.Windows.Forms.RadioButton
radioButtonEngine3;
private System.Windows.Forms.RadioButton
radioButtonEngine4;
private System.Windows.Forms.RadioButton
radioButtonEngine5;
private System.Windows.Forms.RadioButton
radioButtonEngine6;
private System.Windows.Forms.GroupBox groupBoxRoller;
private System.Windows.Forms.NumericUpDown
numericUpDownRollerCircumference;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components =
null;

public GearSelectionDlg(krsMainMdiForm l_formParent)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after
InitializeComponent call
//
MdiParent = l_formParent;
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not
modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources =
new System.Resources.ResourceManager(typeof(GearSelectionDlg));
this.groupBoxEngine = new
System.Windows.Forms.GroupBox();
this.radioButtonEngine1 = new
System.Windows.Forms.RadioButton();
this.radioButtonEngine2 = new
System.Windows.Forms.RadioButton();
this.radioButtonEngine3 = new
System.Windows.Forms.RadioButton();
this.radioButtonEngine4 = new
System.Windows.Forms.RadioButton();
this.radioButtonEngine5 = new
System.Windows.Forms.RadioButton();
this.radioButtonEngine6 = new
System.Windows.Forms.RadioButton();
this.groupBoxSprocketSizes = new
System.Windows.Forms.GroupBox();
this.numericUpDownSmallestCounter = new
System.Windows.Forms.NumericUpDown();
this.numericUpDownLargestCounter = new
System.Windows.Forms.NumericUpDown();
this.numericUpDownSmallestAxle = new
System.Windows.Forms.NumericUpDown();
this.numericUpDownLargestAxle = new
System.Windows.Forms.NumericUpDown();
this.labelSmallestCounter = new
System.Windows.Forms.Label();
this.labelLargestCounter = new
System.Windows.Forms.Label();
this.labelSmallestAxleSprocket = new
System.Windows.Forms.Label();
this.labelLargestAxleSprocket = new
System.Windows.Forms.Label();
this.groupBoxRoller = new
System.Windows.Forms.GroupBox();
this.numericUpDownRollerCircumference = new
System.Windows.Forms.NumericUpDown();
this.label1 = new
System.Windows.Forms.Label();
this.groupBoxMaximumEngineRPM = new
System.Windows.Forms.GroupBox();
this.numericUpDownRPM = new
System.Windows.Forms.NumericUpDown();
this.label2 = new
System.Windows.Forms.Label();
this.buttonClose = new
System.Windows.Forms.Button();
this.textBoxResults = new
System.Windows.Forms.TextBox();
this.buttonCopy = new
System.Windows.Forms.Button();
this.groupBoxEngine.SuspendLayout();
this.groupBoxSprocketSizes.SuspendLayout();

((System.ComponentModel.ISupportInitialize)(this.numericUpDownSmallestCounter)).BeginInit();

((System.ComponentModel.ISupportInitialize)(this.numericUpDownLargestCounter)).BeginInit();

((System.ComponentModel.ISupportInitialize)(this.numericUpDownSmallestAxle)).BeginInit();

((System.ComponentModel.ISupportInitialize)(this.numericUpDownLargestAxle)).BeginInit();
this.groupBoxRoller.SuspendLayout();

((System.ComponentModel.ISupportInitialize)(this.numericUpDownRollerCircumference)).BeginInit();
this.groupBoxMaximumEngineRPM.SuspendLayout();

((System.ComponentModel.ISupportInitialize)(this.numericUpDownRPM)).BeginInit();
this.SuspendLayout();
//
// groupBoxEngine
//

this.groupBoxEngine.Controls.Add(this.radioButtonEngine1);

this.groupBoxEngine.Controls.Add(this.radioButtonEngine2);

this.groupBoxEngine.Controls.Add(this.radioButtonEngine3);

this.groupBoxEngine.Controls.Add(this.radioButtonEngine4);

this.groupBoxEngine.Controls.Add(this.radioButtonEngine5);

this.groupBoxEngine.Controls.Add(this.radioButtonEngine6);
this.groupBoxEngine.Location = new
System.Drawing.Point(16, 16);
this.groupBoxEngine.Name = "groupBoxEngine";
this.groupBoxEngine.Size = new
System.Drawing.Size(440, 80);
this.groupBoxEngine.TabIndex = 0;
this.groupBoxEngine.TabStop = false;
this.groupBoxEngine.Text = "Engine";
//
// radioButtonEngine1
//
this.radioButtonEngine1.FlatStyle =
System.Windows.Forms.FlatStyle.System;
this.radioButtonEngine1.Location = new
System.Drawing.Point(8, 24);
this.radioButtonEngine1.Name =
"radioButtonEngine1";
this.radioButtonEngine1.TabIndex = 2;
this.radioButtonEngine1.Text = "Engine 1";
this.radioButtonEngine1.CheckedChanged += new
System.EventHandler(this.radioButtonEngine1_ValueChanged);
//
// radioButtonEngine2
//
this.radioButtonEngine2.FlatStyle =
System.Windows.Forms.FlatStyle.System;
this.radioButtonEngine2.Location = new
System.Drawing.Point(8, 48);
this.radioButtonEngine2.Name =
"radioButtonEngine2";
this.radioButtonEngine2.TabIndex = 2;
this.radioButtonEngine2.Text = "Engine 2";
this.radioButtonEngine2.CheckedChanged += new
System.EventHandler(this.radioButtonEngine2_ValueChanged);
//
// radioButtonEngine3
//
this.radioButtonEngine3.FlatStyle =
System.Windows.Forms.FlatStyle.System;
this.radioButtonEngine3.Location = new
System.Drawing.Point(136, 24);
this.radioButtonEngine3.Name =
"radioButtonEngine3";
this.radioButtonEngine3.TabIndex = 2;
this.radioButtonEngine3.Text = "Engine 3";
this.radioButtonEngine3.CheckedChanged += new
System.EventHandler(this.radioButtonEngine3_ValueChanged);
//
// radioButtonEngine4
//
this.radioButtonEngine4.FlatStyle =
System.Windows.Forms.FlatStyle.System;
this.radioButtonEngine4.Location = new
System.Drawing.Point(136, 48);
this.radioButtonEngine4.Name =
"radioButtonEngine4";
this.radioButtonEngine4.TabIndex = 2;
this.radioButtonEngine4.Text = "Engine 4";
this.radioButtonEngine4.CheckedChanged += new
System.EventHandler(this.radioButtonEngine4_ValueChanged);
//
// radioButtonEngine5
//
this.radioButtonEngine5.FlatStyle =
System.Windows.Forms.FlatStyle.System;
this.radioButtonEngine5.Location = new
System.Drawing.Point(264, 24);
this.radioButtonEngine5.Name =
"radioButtonEngine5";
this.radioButtonEngine5.Size = new
System.Drawing.Size(112, 24);
this.radioButtonEngine5.TabIndex = 2;
this.radioButtonEngine5.Text = "Engine 5";
this.radioButtonEngine5.CheckedChanged += new
System.EventHandler(this.radioButtonEngine5_ValueChanged);
//
// radioButtonEngine6
//
this.radioButtonEngine6.FlatStyle =
System.Windows.Forms.FlatStyle.System;
this.radioButtonEngine6.Location = new
System.Drawing.Point(264, 48);
this.radioButtonEngine6.Name =
"radioButtonEngine6";
this.radioButtonEngine6.TabIndex = 2;
this.radioButtonEngine6.Text = "Engine 6";
this.radioButtonEngine6.CheckedChanged += new
System.EventHandler(this.radioButtonEngine6_ValueChanged);
//
// groupBoxSprocketSizes
//

this.groupBoxSprocketSizes.Controls.Add(this.numericUpDownSmallestCounter);

this.groupBoxSprocketSizes.Controls.Add(this.numericUpDownLargestCounter);

this.groupBoxSprocketSizes.Controls.Add(this.numericUpDownSmallestAxle);

this.groupBoxSprocketSizes.Controls.Add(this.numericUpDownLargestAxle);

this.groupBoxSprocketSizes.Controls.Add(this.labelSmallestCounter);

this.groupBoxSprocketSizes.Controls.Add(this.labelLargestCounter);

this.groupBoxSprocketSizes.Controls.Add(this.labelSmallestAxleSprocket);

this.groupBoxSprocketSizes.Controls.Add(this.labelLargestAxleSprocket);
this.groupBoxSprocketSizes.Location = new
System.Drawing.Point(16, 104);
this.groupBoxSprocketSizes.Name =
"groupBoxSprocketSizes";
this.groupBoxSprocketSizes.Size = new
System.Drawing.Size(232, 160);
this.groupBoxSprocketSizes.TabIndex = 1;
this.groupBoxSprocketSizes.TabStop = false;
this.groupBoxSprocketSizes.Text = "Sprocket
Sizes";
//
// numericUpDownSmallestCounter
//
this.numericUpDownSmallestCounter.Location =
new System.Drawing.Point(16, 24);
this.numericUpDownSmallestCounter.Maximum =
new System.Decimal(new int[] {

30,

0,

0,

0});
this.numericUpDownSmallestCounter.Minimum =
new System.Decimal(new int[] {

10,

0,

0,

0});
this.numericUpDownSmallestCounter.Name =
"numericUpDownSmallestCounter";
this.numericUpDownSmallestCounter.Size = new
System.Drawing.Size(40, 20);
this.numericUpDownSmallestCounter.TabIndex =
0;
this.numericUpDownSmallestCounter.Value = new
System.Decimal(new int[] {

15,

0,

0,

0});
this.numericUpDownSmallestCounter.GotFocus +=
new System.EventHandler(this.numericUpDownSmallestCounter_GotFocus);
this.numericUpDownSmallestCounter.ValueChanged
+= new
System.EventHandler(this.numericUpDownSmallestCounter_ValueChanged);
//
// numericUpDownLargestCounter
//
this.numericUpDownLargestCounter.Location =
new System.Drawing.Point(16, 56);
this.numericUpDownLargestCounter.Maximum = new
System.Decimal(new int[] {

30,

0,

0,

0});
this.numericUpDownLargestCounter.Minimum = new
System.Decimal(new int[] {

10,

0,

0,

0});
this.numericUpDownLargestCounter.Name =
"numericUpDownLargestCounter";
this.numericUpDownLargestCounter.Size = new
System.Drawing.Size(40, 20);
this.numericUpDownLargestCounter.TabIndex = 0;
this.numericUpDownLargestCounter.Value = new
System.Decimal(new int[] {

15,

0,

0,

0});
this.numericUpDownLargestCounter.GotFocus +=
new System.EventHandler(this.numericUpDownLargestCounter_GotFocus);
this.numericUpDownLargestCounter.ValueChanged
+= new
System.EventHandler(this.numericUpDownLargestCounter_ValueChanged);
//
// numericUpDownSmallestAxle
//
this.numericUpDownSmallestAxle.Location = new
System.Drawing.Point(16, 88);
this.numericUpDownSmallestAxle.Maximum = new
System.Decimal(new int[] {

35,

0,

0,

0});
this.numericUpDownSmallestAxle.Minimum = new
System.Decimal(new int[] {

19,

0,

0,

0});
this.numericUpDownSmallestAxle.Name =
"numericUpDownSmallestAxle";
this.numericUpDownSmallestAxle.Size = new
System.Drawing.Size(40, 20);
this.numericUpDownSmallestAxle.TabIndex = 0;
this.numericUpDownSmallestAxle.Value = new
System.Decimal(new int[] {

21,

0,

0,

0});
this.numericUpDownSmallestAxle.GotFocus += new
System.EventHandler(this.numericUpDownSmallestAxle_GotFocus);
this.numericUpDownSmallestAxle.ValueChanged +=
new System.EventHandler(this.numericUpDownSmallestAxle_ValueChanged);
//
// numericUpDownLargestAxle
//
this.numericUpDownLargestAxle.Location = new
System.Drawing.Point(16, 120);
this.numericUpDownLargestAxle.Maximum = new
System.Decimal(new int[] {

35,

0,

0,

0});
this.numericUpDownLargestAxle.Minimum = new
System.Decimal(new int[] {

19,

0,

0,

0});
this.numericUpDownLargestAxle.Name =
"numericUpDownLargestAxle";
this.numericUpDownLargestAxle.Size = new
System.Drawing.Size(40, 20);
this.numericUpDownLargestAxle.TabIndex = 0;
this.numericUpDownLargestAxle.Value = new
System.Decimal(new int[] {

30,

0,

0,

0});
this.numericUpDownLargestAxle.GotFocus += new
System.EventHandler(this.numericUpDownLargestAxle_GotFocus);
this.numericUpDownLargestAxle.ValueChanged +=
new System.EventHandler(this.numericUpDownLargestAxle_ValueChanged);
//
// labelSmallestCounter
//
this.labelSmallestCounter.Location = new
System.Drawing.Point(62, 24);
this.labelSmallestCounter.Name =
"labelSmallestCounter";
this.labelSmallestCounter.Size = new
System.Drawing.Size(160, 23);
this.labelSmallestCounter.TabIndex = 2;
this.labelSmallestCounter.Text = "Smallest
Counter Sprocket";
this.labelSmallestCounter.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// labelLargestCounter
//
this.labelLargestCounter.Location = new
System.Drawing.Point(62, 56);
this.labelLargestCounter.Name =
"labelLargestCounter";
this.labelLargestCounter.Size = new
System.Drawing.Size(160, 23);
this.labelLargestCounter.TabIndex = 2;
this.labelLargestCounter.Text = "Largest
Counter Sprocket";
this.labelLargestCounter.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// labelSmallestAxleSprocket
//
this.labelSmallestAxleSprocket.Location = new
System.Drawing.Point(62, 88);
this.labelSmallestAxleSprocket.Name =
"labelSmallestAxleSprocket";
this.labelSmallestAxleSprocket.Size = new
System.Drawing.Size(160, 23);
this.labelSmallestAxleSprocket.TabIndex = 2;
this.labelSmallestAxleSprocket.Text =
"Smallest Axle Sprocket";
this.labelSmallestAxleSprocket.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// labelLargestAxleSprocket
//
this.labelLargestAxleSprocket.Location = new
System.Drawing.Point(62, 120);
this.labelLargestAxleSprocket.Name =
"labelLargestAxleSprocket";
this.labelLargestAxleSprocket.Size = new
System.Drawing.Size(160, 23);
this.labelLargestAxleSprocket.TabIndex = 2;
this.labelLargestAxleSprocket.Text = "Largest
Axle Sprocket";
this.labelLargestAxleSprocket.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// groupBoxRoller
//

this.groupBoxRoller.Controls.Add(this.numericUpDownRollerCircumference);
this.groupBoxRoller.Controls.Add(this.label1);
this.groupBoxRoller.Location = new
System.Drawing.Point(16, 272);
this.groupBoxRoller.Name = "groupBoxRoller";
this.groupBoxRoller.Size = new
System.Drawing.Size(232, 56);
this.groupBoxRoller.TabIndex = 2;
this.groupBoxRoller.TabStop = false;
this.groupBoxRoller.Text = "Roller";
//
// numericUpDownRollerCircumference
//

this.numericUpDownRollerCircumference.DecimalPlaces = 3;

this.numericUpDownRollerCircumference.Increment = new
System.Decimal(new int[] {

125,

0,

0,

196608});
this.numericUpDownRollerCircumference.Location
= new System.Drawing.Point(16, 21);
this.numericUpDownRollerCircumference.Maximum
= new System.Decimal(new int[] {

50,

0,

0,

0});
this.numericUpDownRollerCircumference.Minimum
= new System.Decimal(new int[] {

25,

0,

0,

0});
this.numericUpDownRollerCircumference.Name =
"numericUpDownRollerCircumference";
this.numericUpDownRollerCircumference.Size =
new System.Drawing.Size(56, 20);
this.numericUpDownRollerCircumference.TabIndex
= 0;
this.numericUpDownRollerCircumference.Value =
new System.Decimal(new int[] {

35,

0,

0,

0});
this.numericUpDownRollerCircumference.GotFocus
+= new
System.EventHandler(this.numericUpDownRollerCircumference_GotFocus);

this.numericUpDownRollerCircumference.ValueChanged += new
System.EventHandler(this.numericUpDownRollerCircumference_ValueChanged);
//
// label1
//
this.label1.Location = new
System.Drawing.Point(77, 19);
this.label1.Name = "label1";
this.label1.Size = new
System.Drawing.Size(130, 23);
this.label1.TabIndex = 2;
this.label1.Text = "Roller Circumference";
this.label1.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// groupBoxMaximumEngineRPM
//

this.groupBoxMaximumEngineRPM.Controls.Add(this.numericUpDownRPM);

this.groupBoxMaximumEngineRPM.Controls.Add(this.label2);
this.groupBoxMaximumEngineRPM.Location = new
System.Drawing.Point(16, 336);
this.groupBoxMaximumEngineRPM.Name =
"groupBoxMaximumEngineRPM";
this.groupBoxMaximumEngineRPM.Size = new
System.Drawing.Size(232, 56);
this.groupBoxMaximumEngineRPM.TabIndex = 3;
this.groupBoxMaximumEngineRPM.TabStop = false;
this.groupBoxMaximumEngineRPM.Text = "RPM";
//
// numericUpDownRPM
//
this.numericUpDownRPM.Increment = new
System.Decimal(new int[] {

25,

0,

0,

0});
this.numericUpDownRPM.Location = new
System.Drawing.Point(16, 19);
this.numericUpDownRPM.Maximum = new
System.Decimal(new int[] {

20000,

0,

0,

0});
this.numericUpDownRPM.Name =
"numericUpDownRPM";
this.numericUpDownRPM.Size = new
System.Drawing.Size(56, 20);
this.numericUpDownRPM.TabIndex = 0;
this.numericUpDownRPM.Value = new
System.Decimal(new int[] {

12000,

0,

0,

0});
this.numericUpDownRPM.GotFocus += new
System.EventHandler(this.numericUpDownRPM_GotFocus);
this.numericUpDownRPM.ValueChanged += new
System.EventHandler(this.numericUpDownRPM_ValueChanged);
//
// label2
//
this.label2.Location = new
System.Drawing.Point(78, 16);
this.label2.Name = "label2";
this.label2.Size = new
System.Drawing.Size(124, 23);
this.label2.TabIndex = 2;
this.label2.Text = "Maximum Engine RPM";
this.label2.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// buttonClose
//
this.buttonClose.FlatStyle =
System.Windows.Forms.FlatStyle.System;
this.buttonClose.Location = new
System.Drawing.Point(16, 408);
this.buttonClose.Name = "buttonClose";
this.buttonClose.TabIndex = 4;
this.buttonClose.Text = "Close";
this.buttonClose.Click += new
System.EventHandler(this.buttonClose_Click);
//
// textBoxResults
//
this.textBoxResults.Location = new
System.Drawing.Point(256, 112);
this.textBoxResults.Multiline = true;
this.textBoxResults.Name = "textBoxResults";
this.textBoxResults.ScrollBars =
System.Windows.Forms.ScrollBars.Vertical;
this.textBoxResults.Size = new
System.Drawing.Size(200, 280);
this.textBoxResults.TabIndex = 5;
this.textBoxResults.Text = "";
//
// buttonCopy
//
this.buttonCopy.FlatStyle =
System.Windows.Forms.FlatStyle.System;
this.buttonCopy.Location = new
System.Drawing.Point(256, 408);
this.buttonCopy.Name = "buttonCopy";
this.buttonCopy.Size = new
System.Drawing.Size(200, 23);
this.buttonCopy.TabIndex = 4;
this.buttonCopy.Text = "Copy Results to
Clipboard";
this.buttonCopy.Click += new
System.EventHandler(this.buttonCopy_Click);
//
// GearSelectionDlg
//
this.AutoScaleBaseSize = new
System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(472,
456);
this.Controls.Add(this.textBoxResults);
this.Controls.Add(this.buttonClose);

this.Controls.Add(this.groupBoxMaximumEngineRPM);
this.Controls.Add(this.groupBoxRoller);
this.Controls.Add(this.groupBoxSprocketSizes);
this.Controls.Add(this.groupBoxEngine);
this.Controls.Add(this.buttonCopy);
this.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon =
((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "GearSelectionDlg";
this.ShowInTaskbar = false;
this.SizeGripStyle =
System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Gear Selection";
this.Load += new
System.EventHandler(this.GearSelectionDlg_Load);
this.groupBoxEngine.ResumeLayout(false);

this.groupBoxSprocketSizes.ResumeLayout(false);

((System.ComponentModel.ISupportInitialize)(this.numericUpDownSmallestCounter)).EndInit();

((System.ComponentModel.ISupportInitialize)(this.numericUpDownLargestCounter)).EndInit();

((System.ComponentModel.ISupportInitialize)(this.numericUpDownSmallestAxle)).EndInit();

((System.ComponentModel.ISupportInitialize)(this.numericUpDownLargestAxle)).EndInit();
this.groupBoxRoller.ResumeLayout(false);

((System.ComponentModel.ISupportInitialize)(this.numericUpDownRollerCircumference)).EndInit();

this.groupBoxMaximumEngineRPM.ResumeLayout(false);

((System.ComponentModel.ISupportInitialize)(this.numericUpDownRPM)).EndInit();
this.ResumeLayout(false);

}
#endregion


public class conversions
{
public decimal cc;
public decimal ca;
public decimal r;
public decimal m;

public conversions (decimal mCurrentCounter,
decimal mCurrentAxle, decimal mRatio, decimal mMph)
{
cc = mCurrentCounter;
ca = mCurrentAxle;
r = mRatio;
m = mMph;
MessageBox.Show("I am here 3");
}
public new string ToString()
{
return cc + "/" + ca + "\t" + r + "\t"
+ m;
}

}

public void ApplyCalculations()
{
decimal mPrimaryReductionRatio = 0;
decimal mSixthGearRatio =
0;

if(this.radioButtonEngine1.Checked)
{
mPrimaryReductionRatio =
63/20M;
mSixthGearRatio =
24/24M;
}
else if(this.radioButtonEngine2.Checked)
{
mPrimaryReductionRatio =
65/19M;
mSixthGearRatio =
23/26M;
}
else if(this.radioButtonEngine3.Checked)
{
mPrimaryReductionRatio =
65/19M;
mSixthGearRatio =
24/24M;
}
else if(this.radioButtonEngine4.Checked)
{
mPrimaryReductionRatio =
69/17M;
mSixthGearRatio =
24/25M;
}
else if(this.radioButtonEngine5.Checked)
{
mPrimaryReductionRatio =
65/20M;
mSixthGearRatio =
24/24M;
}
else if(this.radioButtonEngine6.Checked)
{
mPrimaryReductionRatio =
65/20M;
mSixthGearRatio =
24/24M;
}

decimal mRollerCircumference =
this.numericUpDownRollerCircumference.Value;
int mSmallCounter =
Convert.ToInt32(this.numericUpDownSmallestCounter.Value);
int mLargeCounter =
Convert.ToInt32(this.numericUpDownLargestCounter.Value);
int mSmallAxle =
Convert.ToInt32(this.numericUpDownSmallestAxle.Value);
int mLargeAxle =
Convert.ToInt32(this.numericUpDownLargestAxle.Value);
decimal mRpm =
this.numericUpDownRPM.Value;

int mCounterSteps =
(mLargeCounter - mSmallCounter) + 1;
int mAxleSteps =
(mLargeAxle - mSmallAxle) + 1;
int mTotalSteps =
mAxleSteps * mCounterSteps;
decimal mCurrentCounter =
mSmallCounter;
decimal mCurrentAxle =
mSmallAxle;
decimal mPreTotal;
decimal mRatio =
0;;
decimal mMph =
0;

this.textBoxResults.Text =
"Gears\tRatio\tSpeed\r\n-------------------------------------------------\r\n";

//decimal[] g;
//g = new decimal [ mTotalSteps ];
ArrayList arraymph = new ArrayList();

for (int i = 0; i < mAxleSteps; i++)
{
for (int x = 0; x < mCounterSteps;
x++)
{
mRatio =
mCurrentAxle/mCurrentCounter;
mPreTotal =
(mRpm*(mRollerCircumference/12)) /
((mRatio*(mPrimaryReductionRatio*mSixthGearRatio)) * 88);
mRatio = Math.Round(mRatio,
3);
mMph =
Math.Round(mPreTotal, 2);


//arraymph.Add(mMph + "" +
mRatio + "" + mCurrentCounter + "" + mCurrentAxle);
arraymph.Add (new
conversions(mCurrentCounter, mCurrentAxle, mRatio, mMph));



conversions[] g =
{
new
conversions(mCurrentCounter, mCurrentAxle, mRatio, mMph)
};

arraymph.Sort(new mysort());
//mysort s = new mysort();
//arraymph.Sort(g, s);

foreach ( conversions a in g)
{

this.textBoxResults.Text += "" + a.ToString() + "\r\n";
}

//arraymph.Sort(new mysort());
//arraymph.Reverse(g, s);
//foreach (decimal a in
arraymph)
//{
//
this.textBoxResults.Text += a + "\r\n";
//}
mCurrentCounter++;
}
mCurrentAxle++;
mCurrentCounter = mSmallCounter;
}

}
public class mysort : IComparer
{
public int Compare ( object a, object b )
{
//MessageBox.Show("TESTING NOTICE
#1");

decimal m1 = ((conversions)a).m ;
decimal m2 = ((conversions)b).m ;
decimal r1 = ((conversions)a).r ;
decimal r2 = ((conversions)b).r ;

if ( m1 == m2 )
{
return r1.CompareTo(r2);
}
if(m1 < m2 )
return -1;
return 1;
}
}
private void buttonClose_Click(object sender,
System.EventArgs e)
{
Close();
}
private void radioButtonEngine6_ValueChanged(object
sender, System.EventArgs e)
{
this.ApplyCalculations();
}
private void radioButtonEngine5_ValueChanged(object
sender, System.EventArgs e)
{
this.ApplyCalculations();
}
private void radioButtonEngine4_ValueChanged(object
sender, System.EventArgs e)
{
this.ApplyCalculations();
}
private void radioButtonEngine3_ValueChanged(object
sender, System.EventArgs e)
{
this.ApplyCalculations();
}
private void radioButtonEngine1_ValueChanged(object
sender, System.EventArgs e)
{
this.ApplyCalculations();
}
private void radioButtonEngine2_ValueChanged(object
sender, System.EventArgs e)
{
this.ApplyCalculations();
}
private void
numericUpDownSmallestCounter_ValueChanged(object sender,
System.EventArgs e)
{
this.ApplyCalculations();
}
private void
numericUpDownLargestCounter_ValueChanged(object sender,
System.EventArgs e)
{
this.ApplyCalculations();
}
private void
numericUpDownSmallestAxle_ValueChanged(object sender, System.EventArgs
e)
{
this.ApplyCalculations();
}
private void
numericUpDownLargestAxle_ValueChanged(object sender, System.EventArgs
e)
{
this.ApplyCalculations();
}
private void
numericUpDownRollerCircumference_ValueChanged(object sender,
System.EventArgs e)
{
ApplyCalculations();
}
private void numericUpDownRPM_ValueChanged(object
sender, System.EventArgs e)
{
ApplyCalculations();
}
private void buttonCopy_Click(object sender,
System.EventArgs e)
{
this.textBoxResults.SelectAll();
this.textBoxResults.Copy();
}
private void
numericUpDownSmallestCounter_GotFocus(object sender, EventArgs e)
{
this.numericUpDownSmallestCounter.Select(0,2);
}
private void numericUpDownRPM_GotFocus(object sender,
EventArgs e)
{
this.numericUpDownRPM.Select(0,5);
}
private void
numericUpDownRollerCircumference_GotFocus(object sender, EventArgs e)
{

this.numericUpDownRollerCircumference.Select(0,6);
}
private void numericUpDownLargestAxle_GotFocus(object
sender, EventArgs e)
{
this.numericUpDownLargestAxle.Select(0,2);
}
private void numericUpDownSmallestAxle_GotFocus(object
sender, EventArgs e)
{
this.numericUpDownSmallestAxle.Select(0,2);
}
private void
numericUpDownLargestCounter_GotFocus(object sender, EventArgs e)
{
this.numericUpDownLargestCounter.Select(0,2);
}

private void GearSelectionDlg_Load(object sender,
System.EventArgs e)
{

}
}
}




End Code
---------------------------------
 
G

Guest

Add a new Component Class to your project, and paste the following class into
it (watch for word wrap).
The important powerful feature to leverage here is that each member of the
listbox is an object, not a string or number. Don't use Items.Add to add to
it, use the custom AddItem method. Call the SortResults method when you want
to sort it.

public class McLb : ListBox
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public McLb.TestResult.SortByType SortBy = TestResult.SortByType.Gears;
//default?
public McLb()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call

}
public McLb(TestResult.SortByType sortby)
{
InitializeComponent();
SortBy = sortby;
}
public int AddItem(TestResult newitem)
{
newitem.GetSort +=new
MultiColumnListBox.McLb.TestResult.delGetSort(newitem_GetSort);
return Items.Add(newitem);
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}

public void SortResults(TestResult.SortByType sb)
{
SortBy = sb;
ArrayList a = new ArrayList(Items);
a.Sort();
Items.Clear();
Items.AddRange((object[])a.ToArray(typeof(object)));
}

#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// McLb
//
this.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.DrawItem += new
System.Windows.Forms.DrawItemEventHandler(this.McLb_DrawItem);

}
#endregion

public class TestResult : IComparable
{
public enum SortByType{Gears, Ratio, Speed}
public delegate SortByType delGetSort();
public event delGetSort GetSort;
public string Gears;
public float Ratio, Speed;
private TestResult(){} //force specification of parameters.
public TestResult(string gears, float ratio, float speed)
{
Gears = gears; Ratio = ratio; Speed = speed;
}
#region IComparable Members

public int CompareTo(object obj)
{
if(!(obj is TestResult))
throw new ArgumentException(
"TestResult can only be compared with another TestResult!");
if(GetSort != null)
{
SortByType sb = GetSort();
switch(sb)
{
case SortByType.Gears:
return Gears.CompareTo(((TestResult)obj).Gears);
case SortByType.Ratio:
return Ratio.CompareTo(((TestResult)obj).Ratio);
case SortByType.Speed :
return Speed.CompareTo(((TestResult)obj).Speed);
default: break;
}
}
throw new InvalidOperationException("Sort by not responded to" +
" or SortByType not handled.");
}

#endregion
}

private MultiColumnListBox.McLb.TestResult.SortByType newitem_GetSort()
{
return SortBy;
}

private void McLb_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
if((Items.Count == 0) || (e.Index == -1)) return;
TestResult tritem = (TestResult)Items[e.Index];
Brush backbrush, textbrush;
if((e.State & DrawItemState.Selected) != 0)
{
backbrush = new SolidBrush(SystemColors.Highlight);
textbrush = new SolidBrush(SystemColors.HighlightText);
}
else
{
backbrush = new SolidBrush(BackColor);
textbrush = new SolidBrush(ForeColor);
}
string[] items = new string[]
{
tritem.Gears,
string.Format("{0:0.000}", tritem.Ratio),
string.Format("{0:0.000}", tritem.Speed)
};
e.Graphics.FillRectangle(backbrush, e.Bounds);
int thirdwidth = e.Bounds.Width / 3;
StringFormat sf = new StringFormat(StringFormatFlags.NoWrap);
sf.Alignment = StringAlignment.Near; //change to suit
sf.LineAlignment = StringAlignment.Center;
for(int i = 0; i < 3; i++)
{
RectangleF textrect = new RectangleF(
e.Bounds.Left + (i * thirdwidth),
e.Bounds.Top,
thirdwidth,
e.Bounds.Height);
e.Graphics.DrawString(items, Font, textbrush, textrect, sf);
}
}
}
 
M

MFC

Wow, can't wait to get to that point in my C# travels ...after three
weeks, I'm at a level of confusion where I understand 10% of it 90% of
the time and 90% only 10% of the time :)

I'm having a bit of difficulty implementing the Component Class. I
added it to my project, but not sure how to call it. Would it be
something like:

new ListBox(mCurrentCounter, mCurrentAxle, mRatio, mMph);

Thank you so much for the time.


Mark

Add a new Component Class to your project, and paste the following class into
it (watch for word wrap).
The important powerful feature to leverage here is that each member of the
listbox is an object, not a string or number. Don't use Items.Add to add to
it, use the custom AddItem method. Call the SortResults method when you want
to sort it.

public class McLb : ListBox
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public McLb.TestResult.SortByType SortBy = TestResult.SortByType.Gears;
//default?
public McLb()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call

}
public McLb(TestResult.SortByType sortby)
{
InitializeComponent();
SortBy = sortby;
}
public int AddItem(TestResult newitem)
{
newitem.GetSort +=new
MultiColumnListBox.McLb.TestResult.delGetSort(newitem_GetSort);
return Items.Add(newitem);
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}

public void SortResults(TestResult.SortByType sb)
{
SortBy = sb;
ArrayList a = new ArrayList(Items);
a.Sort();
Items.Clear();
Items.AddRange((object[])a.ToArray(typeof(object)));
}

#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// McLb
//
this.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.DrawItem += new
System.Windows.Forms.DrawItemEventHandler(this.McLb_DrawItem);

}
#endregion

public class TestResult : IComparable
{
public enum SortByType{Gears, Ratio, Speed}
public delegate SortByType delGetSort();
public event delGetSort GetSort;
public string Gears;
public float Ratio, Speed;
private TestResult(){} //force specification of parameters.
public TestResult(string gears, float ratio, float speed)
{
Gears = gears; Ratio = ratio; Speed = speed;
}
#region IComparable Members

public int CompareTo(object obj)
{
if(!(obj is TestResult))
throw new ArgumentException(
"TestResult can only be compared with another TestResult!");
if(GetSort != null)
{
SortByType sb = GetSort();
switch(sb)
{
case SortByType.Gears:
return Gears.CompareTo(((TestResult)obj).Gears);
case SortByType.Ratio:
return Ratio.CompareTo(((TestResult)obj).Ratio);
case SortByType.Speed :
return Speed.CompareTo(((TestResult)obj).Speed);
default: break;
}
}
throw new InvalidOperationException("Sort by not responded to" +
" or SortByType not handled.");
}

#endregion
}

private MultiColumnListBox.McLb.TestResult.SortByType newitem_GetSort()
{
return SortBy;
}

private void McLb_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
if((Items.Count == 0) || (e.Index == -1)) return;
TestResult tritem = (TestResult)Items[e.Index];
Brush backbrush, textbrush;
if((e.State & DrawItemState.Selected) != 0)
{
backbrush = new SolidBrush(SystemColors.Highlight);
textbrush = new SolidBrush(SystemColors.HighlightText);
}
else
{
backbrush = new SolidBrush(BackColor);
textbrush = new SolidBrush(ForeColor);
}
string[] items = new string[]
{
tritem.Gears,
string.Format("{0:0.000}", tritem.Ratio),
string.Format("{0:0.000}", tritem.Speed)
};
e.Graphics.FillRectangle(backbrush, e.Bounds);
int thirdwidth = e.Bounds.Width / 3;
StringFormat sf = new StringFormat(StringFormatFlags.NoWrap);
sf.Alignment = StringAlignment.Near; //change to suit
sf.LineAlignment = StringAlignment.Center;
for(int i = 0; i < 3; i++)
{
RectangleF textrect = new RectangleF(
e.Bounds.Left + (i * thirdwidth),
e.Bounds.Top,
thirdwidth,
e.Bounds.Height);
e.Graphics.DrawString(items, Font, textbrush, textrect, sf);
}
}
}



Patty O'Dors said:
You need an owner-drawn listbox. I'm a master at them. I'll knock you one up.
 
G

Guest

No. There are two methods of adding a custom component:
1) (The recommended way)
Add a reference to the project the component class is in (if it's a separate
project), THEN, go to the toolbox and right click on it, go to add/remove
items, browse, find the DLL the component class is in, and select it. You
should then have an icon representing your new component, which you can then
drag onto your form.
2) (The quick way - good for if the component class is in the same project
as the main exe)
Add a standard listbox to your form, and then go into the code listing,
expand the 'component designer generated code' region, and replace
System.Windows.Forms.ListBox with the name of the custom listbox-derived
component I gave you (there should be two instances - one where it's
declared, one where its instantiated). Then build the project. If it builds
OK, switch back to the form designer view and it should update itself.

any problems post back


MFC said:
Wow, can't wait to get to that point in my C# travels ...after three
weeks, I'm at a level of confusion where I understand 10% of it 90% of
the time and 90% only 10% of the time :)

I'm having a bit of difficulty implementing the Component Class. I
added it to my project, but not sure how to call it. Would it be
something like:

new ListBox(mCurrentCounter, mCurrentAxle, mRatio, mMph);

Thank you so much for the time.


Mark

Add a new Component Class to your project, and paste the following class into
it (watch for word wrap).
The important powerful feature to leverage here is that each member of the
listbox is an object, not a string or number. Don't use Items.Add to add to
it, use the custom AddItem method. Call the SortResults method when you want
to sort it.

public class McLb : ListBox
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public McLb.TestResult.SortByType SortBy = TestResult.SortByType.Gears;
//default?
public McLb()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call

}
public McLb(TestResult.SortByType sortby)
{
InitializeComponent();
SortBy = sortby;
}
public int AddItem(TestResult newitem)
{
newitem.GetSort +=new
MultiColumnListBox.McLb.TestResult.delGetSort(newitem_GetSort);
return Items.Add(newitem);
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}

public void SortResults(TestResult.SortByType sb)
{
SortBy = sb;
ArrayList a = new ArrayList(Items);
a.Sort();
Items.Clear();
Items.AddRange((object[])a.ToArray(typeof(object)));
}

#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// McLb
//
this.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.DrawItem += new
System.Windows.Forms.DrawItemEventHandler(this.McLb_DrawItem);

}
#endregion

public class TestResult : IComparable
{
public enum SortByType{Gears, Ratio, Speed}
public delegate SortByType delGetSort();
public event delGetSort GetSort;
public string Gears;
public float Ratio, Speed;
private TestResult(){} //force specification of parameters.
public TestResult(string gears, float ratio, float speed)
{
Gears = gears; Ratio = ratio; Speed = speed;
}
#region IComparable Members

public int CompareTo(object obj)
{
if(!(obj is TestResult))
throw new ArgumentException(
"TestResult can only be compared with another TestResult!");
if(GetSort != null)
{
SortByType sb = GetSort();
switch(sb)
{
case SortByType.Gears:
return Gears.CompareTo(((TestResult)obj).Gears);
case SortByType.Ratio:
return Ratio.CompareTo(((TestResult)obj).Ratio);
case SortByType.Speed :
return Speed.CompareTo(((TestResult)obj).Speed);
default: break;
}
}
throw new InvalidOperationException("Sort by not responded to" +
" or SortByType not handled.");
}

#endregion
}

private MultiColumnListBox.McLb.TestResult.SortByType newitem_GetSort()
{
return SortBy;
}

private void McLb_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
if((Items.Count == 0) || (e.Index == -1)) return;
TestResult tritem = (TestResult)Items[e.Index];
Brush backbrush, textbrush;
if((e.State & DrawItemState.Selected) != 0)
{
backbrush = new SolidBrush(SystemColors.Highlight);
textbrush = new SolidBrush(SystemColors.HighlightText);
}
else
{
backbrush = new SolidBrush(BackColor);
textbrush = new SolidBrush(ForeColor);
}
string[] items = new string[]
{
tritem.Gears,
string.Format("{0:0.000}", tritem.Ratio),
string.Format("{0:0.000}", tritem.Speed)
};
e.Graphics.FillRectangle(backbrush, e.Bounds);
int thirdwidth = e.Bounds.Width / 3;
StringFormat sf = new StringFormat(StringFormatFlags.NoWrap);
sf.Alignment = StringAlignment.Near; //change to suit
sf.LineAlignment = StringAlignment.Center;
for(int i = 0; i < 3; i++)
{
RectangleF textrect = new RectangleF(
e.Bounds.Left + (i * thirdwidth),
e.Bounds.Top,
thirdwidth,
e.Bounds.Height);
e.Graphics.DrawString(items, Font, textbrush, textrect, sf);
}
}
}



Patty O'Dors said:
You need an owner-drawn listbox. I'm a master at them. I'll knock you one up.

 
M

MFC

Thanks for the reply.

Added the component class using the 2nd method you mentioned. I
then...

replaced this:
private System.Windows.Forms.ListBox listBox1;

with this:
private McLb listBox1;


and replaced this:
this.listBox1 = new System.Windows.Forms.ListBox();

with this:
this.listBox1 = new McLb();

Error when debugging:
....\multilistbox.cs(8,21): error CS0246: The type or namespace name
'ListBox' could not be found (are you missing a using directive or an
assembly reference?)

....\multilistbox.cs(116,10): error CS0246: The type or namespace name
'MultiColumnListBox' could not be found (are you missing a using
directive or an assembly reference?)





No. There are two methods of adding a custom component:
1) (The recommended way)
Add a reference to the project the component class is in (if it's a separate
project), THEN, go to the toolbox and right click on it, go to add/remove
items, browse, find the DLL the component class is in, and select it. You
should then have an icon representing your new component, which you can then
drag onto your form.
2) (The quick way - good for if the component class is in the same project
as the main exe)
Add a standard listbox to your form, and then go into the code listing,
expand the 'component designer generated code' region, and replace
System.Windows.Forms.ListBox with the name of the custom listbox-derived
component I gave you (there should be two instances - one where it's
declared, one where its instantiated). Then build the project. If it builds
OK, switch back to the form designer view and it should update itself.

any problems post back


MFC said:
Wow, can't wait to get to that point in my C# travels ...after three
weeks, I'm at a level of confusion where I understand 10% of it 90% of
the time and 90% only 10% of the time :)

I'm having a bit of difficulty implementing the Component Class. I
added it to my project, but not sure how to call it. Would it be
something like:

new ListBox(mCurrentCounter, mCurrentAxle, mRatio, mMph);

Thank you so much for the time.


Mark

Add a new Component Class to your project, and paste the following class into
it (watch for word wrap).
The important powerful feature to leverage here is that each member of the
listbox is an object, not a string or number. Don't use Items.Add to add to
it, use the custom AddItem method. Call the SortResults method when you want
to sort it.

public class McLb : ListBox
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public McLb.TestResult.SortByType SortBy = TestResult.SortByType.Gears;
//default?
public McLb()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call

}
public McLb(TestResult.SortByType sortby)
{
InitializeComponent();
SortBy = sortby;
}
public int AddItem(TestResult newitem)
{
newitem.GetSort +=new
MultiColumnListBox.McLb.TestResult.delGetSort(newitem_GetSort);
return Items.Add(newitem);
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}

public void SortResults(TestResult.SortByType sb)
{
SortBy = sb;
ArrayList a = new ArrayList(Items);
a.Sort();
Items.Clear();
Items.AddRange((object[])a.ToArray(typeof(object)));
}

#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// McLb
//
this.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.DrawItem += new
System.Windows.Forms.DrawItemEventHandler(this.McLb_DrawItem);

}
#endregion

public class TestResult : IComparable
{
public enum SortByType{Gears, Ratio, Speed}
public delegate SortByType delGetSort();
public event delGetSort GetSort;
public string Gears;
public float Ratio, Speed;
private TestResult(){} //force specification of parameters.
public TestResult(string gears, float ratio, float speed)
{
Gears = gears; Ratio = ratio; Speed = speed;
}
#region IComparable Members

public int CompareTo(object obj)
{
if(!(obj is TestResult))
throw new ArgumentException(
"TestResult can only be compared with another TestResult!");
if(GetSort != null)
{
SortByType sb = GetSort();
switch(sb)
{
case SortByType.Gears:
return Gears.CompareTo(((TestResult)obj).Gears);
case SortByType.Ratio:
return Ratio.CompareTo(((TestResult)obj).Ratio);
case SortByType.Speed :
return Speed.CompareTo(((TestResult)obj).Speed);
default: break;
}
}
throw new InvalidOperationException("Sort by not responded to" +
" or SortByType not handled.");
}

#endregion
}

private MultiColumnListBox.McLb.TestResult.SortByType newitem_GetSort()
{
return SortBy;
}

private void McLb_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
if((Items.Count == 0) || (e.Index == -1)) return;
TestResult tritem = (TestResult)Items[e.Index];
Brush backbrush, textbrush;
if((e.State & DrawItemState.Selected) != 0)
{
backbrush = new SolidBrush(SystemColors.Highlight);
textbrush = new SolidBrush(SystemColors.HighlightText);
}
else
{
backbrush = new SolidBrush(BackColor);
textbrush = new SolidBrush(ForeColor);
}
string[] items = new string[]
{
tritem.Gears,
string.Format("{0:0.000}", tritem.Ratio),
string.Format("{0:0.000}", tritem.Speed)
};
e.Graphics.FillRectangle(backbrush, e.Bounds);
int thirdwidth = e.Bounds.Width / 3;
StringFormat sf = new StringFormat(StringFormatFlags.NoWrap);
sf.Alignment = StringAlignment.Near; //change to suit
sf.LineAlignment = StringAlignment.Center;
for(int i = 0; i < 3; i++)
{
RectangleF textrect = new RectangleF(
e.Bounds.Left + (i * thirdwidth),
e.Bounds.Top,
thirdwidth,
e.Bounds.Height);
e.Graphics.DrawString(items, Font, textbrush, textrect, sf);
}
}
}



:

You need an owner-drawn listbox. I'm a master at them. I'll knock you one up.

 
M

MFC

Still having difficulty implementing the custom component class ...:(


Thanks for the reply.

Added the component class using the 2nd method you mentioned. I
then...

replaced this:
private System.Windows.Forms.ListBox listBox1;

with this:
private McLb listBox1;


and replaced this:
this.listBox1 = new System.Windows.Forms.ListBox();

with this:
this.listBox1 = new McLb();

Error when debugging:
...\multilistbox.cs(8,21): error CS0246: The type or namespace name
'ListBox' could not be found (are you missing a using directive or an
assembly reference?)

...\multilistbox.cs(116,10): error CS0246: The type or namespace name
'MultiColumnListBox' could not be found (are you missing a using
directive or an assembly reference?)





No. There are two methods of adding a custom component:
1) (The recommended way)
Add a reference to the project the component class is in (if it's a separate
project), THEN, go to the toolbox and right click on it, go to add/remove
items, browse, find the DLL the component class is in, and select it. You
should then have an icon representing your new component, which you can then
drag onto your form.
2) (The quick way - good for if the component class is in the same project
as the main exe)
Add a standard listbox to your form, and then go into the code listing,
expand the 'component designer generated code' region, and replace
System.Windows.Forms.ListBox with the name of the custom listbox-derived
component I gave you (there should be two instances - one where it's
declared, one where its instantiated). Then build the project. If it builds
OK, switch back to the form designer view and it should update itself.

any problems post back


MFC said:
Wow, can't wait to get to that point in my C# travels ...after three
weeks, I'm at a level of confusion where I understand 10% of it 90% of
the time and 90% only 10% of the time :)

I'm having a bit of difficulty implementing the Component Class. I
added it to my project, but not sure how to call it. Would it be
something like:

new ListBox(mCurrentCounter, mCurrentAxle, mRatio, mMph);

Thank you so much for the time.


Mark

On Tue, 7 Sep 2004 06:03:07 -0700, Patty O'Dors

Add a new Component Class to your project, and paste the following class into
it (watch for word wrap).
The important powerful feature to leverage here is that each member of the
listbox is an object, not a string or number. Don't use Items.Add to add to
it, use the custom AddItem method. Call the SortResults method when you want
to sort it.

public class McLb : ListBox
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public McLb.TestResult.SortByType SortBy = TestResult.SortByType.Gears;
//default?
public McLb()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call

}
public McLb(TestResult.SortByType sortby)
{
InitializeComponent();
SortBy = sortby;
}
public int AddItem(TestResult newitem)
{
newitem.GetSort +=new
MultiColumnListBox.McLb.TestResult.delGetSort(newitem_GetSort);
return Items.Add(newitem);
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}

public void SortResults(TestResult.SortByType sb)
{
SortBy = sb;
ArrayList a = new ArrayList(Items);
a.Sort();
Items.Clear();
Items.AddRange((object[])a.ToArray(typeof(object)));
}

#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// McLb
//
this.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.DrawItem += new
System.Windows.Forms.DrawItemEventHandler(this.McLb_DrawItem);

}
#endregion

public class TestResult : IComparable
{
public enum SortByType{Gears, Ratio, Speed}
public delegate SortByType delGetSort();
public event delGetSort GetSort;
public string Gears;
public float Ratio, Speed;
private TestResult(){} //force specification of parameters.
public TestResult(string gears, float ratio, float speed)
{
Gears = gears; Ratio = ratio; Speed = speed;
}
#region IComparable Members

public int CompareTo(object obj)
{
if(!(obj is TestResult))
throw new ArgumentException(
"TestResult can only be compared with another TestResult!");
if(GetSort != null)
{
SortByType sb = GetSort();
switch(sb)
{
case SortByType.Gears:
return Gears.CompareTo(((TestResult)obj).Gears);
case SortByType.Ratio:
return Ratio.CompareTo(((TestResult)obj).Ratio);
case SortByType.Speed :
return Speed.CompareTo(((TestResult)obj).Speed);
default: break;
}
}
throw new InvalidOperationException("Sort by not responded to" +
" or SortByType not handled.");
}

#endregion
}

private MultiColumnListBox.McLb.TestResult.SortByType newitem_GetSort()
{
return SortBy;
}

private void McLb_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
if((Items.Count == 0) || (e.Index == -1)) return;
TestResult tritem = (TestResult)Items[e.Index];
Brush backbrush, textbrush;
if((e.State & DrawItemState.Selected) != 0)
{
backbrush = new SolidBrush(SystemColors.Highlight);
textbrush = new SolidBrush(SystemColors.HighlightText);
}
else
{
backbrush = new SolidBrush(BackColor);
textbrush = new SolidBrush(ForeColor);
}
string[] items = new string[]
{
tritem.Gears,
string.Format("{0:0.000}", tritem.Ratio),
string.Format("{0:0.000}", tritem.Speed)
};
e.Graphics.FillRectangle(backbrush, e.Bounds);
int thirdwidth = e.Bounds.Width / 3;
StringFormat sf = new StringFormat(StringFormatFlags.NoWrap);
sf.Alignment = StringAlignment.Near; //change to suit
sf.LineAlignment = StringAlignment.Center;
for(int i = 0; i < 3; i++)
{
RectangleF textrect = new RectangleF(
e.Bounds.Left + (i * thirdwidth),
e.Bounds.Top,
thirdwidth,
e.Bounds.Height);
e.Graphics.DrawString(items, Font, textbrush, textrect, sf);
}
}
}



:

You need an owner-drawn listbox. I'm a master at them. I'll knock you one up.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top