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(GearSelect ionDlg));
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.n umericUpDownSmallestCounter)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.n umericUpDownLargestCounter)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.n umericUpDownSmallestAxle)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.n umericUpDownLargestAxle)).BeginInit();
this.groupBoxRoller.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.n umericUpDownRollerCircumference)).BeginInit();
this.groupBoxMaximumEngineRPM.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.n umericUpDownRPM)).BeginInit();
this.SuspendLayout();
//
// groupBoxEngine
//
this.groupBoxEngine.Controls.Add(this.radioButtonE ngine1);
this.groupBoxEngine.Controls.Add(this.radioButtonE ngine2);
this.groupBoxEngine.Controls.Add(this.radioButtonE ngine3);
this.groupBoxEngine.Controls.Add(this.radioButtonE ngine4);
this.groupBoxEngine.Controls.Add(this.radioButtonE ngine5);
this.groupBoxEngine.Controls.Add(this.radioButtonE ngine6);
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_ValueC hanged);
//
// 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_ValueC hanged);
//
// 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_ValueC hanged);
//
// 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_ValueC hanged);
//
// 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_ValueC hanged);
//
// 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_ValueC hanged);
//
// groupBoxSprocketSizes
//
this.groupBoxSprocketSizes.Controls.Add(this.numer icUpDownSmallestCounter);
this.groupBoxSprocketSizes.Controls.Add(this.numer icUpDownLargestCounter);
this.groupBoxSprocketSizes.Controls.Add(this.numer icUpDownSmallestAxle);
this.groupBoxSprocketSizes.Controls.Add(this.numer icUpDownLargestAxle);
this.groupBoxSprocketSizes.Controls.Add(this.label SmallestCounter);
this.groupBoxSprocketSizes.Controls.Add(this.label LargestCounter);
this.groupBoxSprocketSizes.Controls.Add(this.label SmallestAxleSprocket);
this.groupBoxSprocketSizes.Controls.Add(this.label LargestAxleSprocket);
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.numericUpDownSmallestCoun ter_GotFocus);
this.numericUpDownSmallestCounter.ValueChanged
+= new
System.EventHandler(this.numericUpDownSmallestCoun ter_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.numericUpDownLargestCount er_GotFocus);
this.numericUpDownLargestCounter.ValueChanged
+= new
System.EventHandler(this.numericUpDownLargestCount er_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.numericUpDow nRollerCircumference);
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.DecimalPlace s = 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.numericUpDownRollerCircum ference_GotFocus);
this.numericUpDownRollerCircumference.ValueChanged += new
System.EventHandler(this.numericUpDownRollerCircum ference_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.nu mericUpDownRPM);
this.groupBoxMaximumEngineRPM.Controls.Add(this.la bel2);
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_ValueCha nged);
//
// 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.CenterScree n;
this.Text = "Gear Selection";
this.Load += new
System.EventHandler(this.GearSelectionDlg_Load);
this.groupBoxEngine.ResumeLayout(false);
this.groupBoxSprocketSizes.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.n umericUpDownSmallestCounter)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.n umericUpDownLargestCounter)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.n umericUpDownSmallestAxle)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.n umericUpDownLargestAxle)).EndInit();
this.groupBoxRoller.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.n umericUpDownRollerCircumference)).EndInit();
this.groupBoxMaximumEngineRPM.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.n umericUpDownRPM)).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.V alue);
int mSmallAxle =
Convert.ToInt32(this.numericUpDownSmallestAxle.Val ue);
int mLargeAxle =
Convert.ToInt32(this.numericUpDownLargestAxle.Valu e);
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(obje ct 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
--------------------------------- 5 2360
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(newi tem_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.McL b_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[i], Font, textbrush, textrect, sf);
}
}
}
"Patty O'Dors" wrote: You need an owner-drawn listbox. I'm a master at them. I'll knock you one up.
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
<Pa********@discussions.microsoft.com> wrote: 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(new item_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.Mc Lb_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[i], Font, textbrush, textrect, sf); } } } "Patty O'Dors" wrote:
You need an owner-drawn listbox. I'm a master at them. I'll knock you one up.
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" wrote: 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 <Pa********@discussions.microsoft.com> wrote:
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(new item_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.Mc Lb_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[i], Font, textbrush, textrect, sf); } } } "Patty O'Dors" wrote:
You need an owner-drawn listbox. I'm a master at them. I'll knock you one up.
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?)
On Thu, 9 Sep 2004 05:27:06 -0700, Patty O'Dors
<Pa********@discussions.microsoft.com> wrote: 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" wrote:
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 <Pa********@discussions.microsoft.com> wrote:
>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(new item_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.Mc Lb_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[i], Font, textbrush, textrect, sf); > } > } >} > > > >"Patty O'Dors" wrote: > >> You need an owner-drawn listbox. I'm a master at them. I'll knock you one up. >>
Still having difficulty implementing the custom component class ...:(
On Fri, 10 Sep 2004 16:30:51 GMT, MFC <si************@yahoo.com>
wrote: 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?)
On Thu, 9 Sep 2004 05:27:06 -0700, Patty O'Dors <Pa********@discussions.microsoft.com> wrote:
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" wrote:
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 <Pa********@discussions.microsoft.com> wrote:
>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(new item_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.Mc Lb_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[i], Font, textbrush, textrect, sf); > } > } >} > > > >"Patty O'Dors" wrote: > >> You need an owner-drawn listbox. I'm a master at them. I'll knock you one up. >>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: mike |
last post by:
Hello,
After trying to validate this page for a couple of days now I was
wondering if someone might be able to help me out. Below is a list of
snippets where I am having the errors.
1. Line 334,...
|
by: John Flynn |
last post by:
hi all
i'm going to be quick i have an assignment due which i have no idea how to
do. i work full time so i dont have the time to learn it and its due date
has crept up on me ..
As follows:...
|
by: xunling |
last post by:
i have a question about answering ..... this topic is "need help"
what do i have to write at te topic line, !after i have klicked the
"answer message" button
ive tried many possibilities,...
|
by: sk |
last post by:
I have an applicaton in which I collect data for different parameters
for a set of devices. The data are entered into a single table, each
set of name, value pairs time-stamped and associated with...
|
by: Timothy Shih |
last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I
wrote a simple function which takes in 2 buffers (one a byte buffer, one a
char buffer) and copies the contents of the byte...
|
by: Cheryl Langdon |
last post by:
Hello everyone,
This is my first attempt at getting help in this manner. Please
forgive me if this is an inappropriate request.
I suddenly find myself in urgent need of instruction on how to...
|
by: pamelafluente |
last post by:
I am still working with no success on that client/server
problem. I need your help. I will submit simplified versions
of my problem so we can see clearly what is going on.
My model:
A client...
|
by: skumar434 |
last post by:
i need to store the data from a data base in to structure
.............the problem is like this ....suppose there is a data base
which stores the sequence no and item type etc ...but i need only...
|
by: U S Contractors Offering Service A Non-profit |
last post by:
Brilliant technology helping those most in need Inbox
Reply
U S Contractors Offering Service A Non-profit
show details
10:37 pm (1 hour ago)
Brilliant technology helping those most in need ...
|
by: mike |
last post by:
I help manage a large web site, one that has over
600 html pages... It's a reference site for ham radio
folks and as an example, one page indexes over
1.8 gb of on-line PDF documents.
The site...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |