473,603 Members | 2,603 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need a bit of C# help

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.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;

namespace MCFCorpDevProd
{
/// <summary>
/// Summary description for GearSelectionDl g.
/// </summary>
public class GearSelectionDl g : System.Windows. Forms.Form
{
private System.Windows. Forms.GroupBox groupBoxEngine;
private System.Windows. Forms.GroupBox
groupBoxSprocke tSizes;
private System.Windows. Forms.NumericUp Down
numericUpDownSm allestCounter;
private System.Windows. Forms.NumericUp Down
numericUpDownLa rgestCounter;
private System.Windows. Forms.NumericUp Down
numericUpDownSm allestAxle;
private System.Windows. Forms.NumericUp Down
numericUpDownLa rgestAxle;
private System.Windows. Forms.Label
labelSmallestCo unter;
private System.Windows. Forms.Label
labelLargestCou nter;
private System.Windows. Forms.Label
labelSmallestAx leSprocket;
private System.Windows. Forms.Label
labelLargestAxl eSprocket;
private System.Windows. Forms.Label label1;
private System.Windows. Forms.GroupBox
groupBoxMaximum EngineRPM;
private System.Windows. Forms.Label label2;
private System.Windows. Forms.Button buttonClose;
private System.Windows. Forms.TextBox textBoxResults;
private System.Windows. Forms.NumericUp Down
numericUpDownRP M;
private System.Windows. Forms.Button buttonCopy;
private System.Windows. Forms.RadioButt on
radioButtonEngi ne1;
private System.Windows. Forms.RadioButt on
radioButtonEngi ne2;
private System.Windows. Forms.RadioButt on
radioButtonEngi ne3;
private System.Windows. Forms.RadioButt on
radioButtonEngi ne4;
private System.Windows. Forms.RadioButt on
radioButtonEngi ne5;
private System.Windows. Forms.RadioButt on
radioButtonEngi ne6;
private System.Windows. Forms.GroupBox groupBoxRoller;
private System.Windows. Forms.NumericUp Down
numericUpDownRo llerCircumferen ce;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components =
null;

public GearSelectionDl g(krsMainMdiFor m l_formParent)
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

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

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Disp ose();
}
}
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 InitializeCompo nent()
{
System.Resource s.ResourceManag er resources =
new System.Resource s.ResourceManag er(typeof(GearS electionDlg));
this.groupBoxEn gine = new
System.Windows. Forms.GroupBox( );
this.radioButto nEngine1 = new
System.Windows. Forms.RadioButt on();
this.radioButto nEngine2 = new
System.Windows. Forms.RadioButt on();
this.radioButto nEngine3 = new
System.Windows. Forms.RadioButt on();
this.radioButto nEngine4 = new
System.Windows. Forms.RadioButt on();
this.radioButto nEngine5 = new
System.Windows. Forms.RadioButt on();
this.radioButto nEngine6 = new
System.Windows. Forms.RadioButt on();
this.groupBoxSp rocketSizes = new
System.Windows. Forms.GroupBox( );
this.numericUpD ownSmallestCoun ter = new
System.Windows. Forms.NumericUp Down();
this.numericUpD ownLargestCount er = new
System.Windows. Forms.NumericUp Down();
this.numericUpD ownSmallestAxle = new
System.Windows. Forms.NumericUp Down();
this.numericUpD ownLargestAxle = new
System.Windows. Forms.NumericUp Down();
this.labelSmall estCounter = new
System.Windows. Forms.Label();
this.labelLarge stCounter = new
System.Windows. Forms.Label();
this.labelSmall estAxleSprocket = new
System.Windows. Forms.Label();
this.labelLarge stAxleSprocket = new
System.Windows. Forms.Label();
this.groupBoxRo ller = new
System.Windows. Forms.GroupBox( );
this.numericUpD ownRollerCircum ference = new
System.Windows. Forms.NumericUp Down();
this.label1 = new
System.Windows. Forms.Label();
this.groupBoxMa ximumEngineRPM = new
System.Windows. Forms.GroupBox( );
this.numericUpD ownRPM = new
System.Windows. Forms.NumericUp Down();
this.label2 = new
System.Windows. Forms.Label();
this.buttonClos e = new
System.Windows. Forms.Button();
this.textBoxRes ults = new
System.Windows. Forms.TextBox() ;
this.buttonCopy = new
System.Windows. Forms.Button();
this.groupBoxEn gine.SuspendLay out();
this.groupBoxSp rocketSizes.Sus pendLayout();

((System.Compon entModel.ISuppo rtInitialize)(t his.numericUpDo wnSmallestCount er)).BeginInit( );

((System.Compon entModel.ISuppo rtInitialize)(t his.numericUpDo wnLargestCounte r)).BeginInit() ;

((System.Compon entModel.ISuppo rtInitialize)(t his.numericUpDo wnSmallestAxle) ).BeginInit();

((System.Compon entModel.ISuppo rtInitialize)(t his.numericUpDo wnLargestAxle)) .BeginInit();
this.groupBoxRo ller.SuspendLay out();

((System.Compon entModel.ISuppo rtInitialize)(t his.numericUpDo wnRollerCircumf erence)).BeginI nit();
this.groupBoxMa ximumEngineRPM. SuspendLayout() ;

((System.Compon entModel.ISuppo rtInitialize)(t his.numericUpDo wnRPM)).BeginIn it();
this.SuspendLay out();
//
// groupBoxEngine
//

this.groupBoxEn gine.Controls.A dd(this.radioBu ttonEngine1);

this.groupBoxEn gine.Controls.A dd(this.radioBu ttonEngine2);

this.groupBoxEn gine.Controls.A dd(this.radioBu ttonEngine3);

this.groupBoxEn gine.Controls.A dd(this.radioBu ttonEngine4);

this.groupBoxEn gine.Controls.A dd(this.radioBu ttonEngine5);

this.groupBoxEn gine.Controls.A dd(this.radioBu ttonEngine6);
this.groupBoxEn gine.Location = new
System.Drawing. Point(16, 16);
this.groupBoxEn gine.Name = "groupBoxEngine ";
this.groupBoxEn gine.Size = new
System.Drawing. Size(440, 80);
this.groupBoxEn gine.TabIndex = 0;
this.groupBoxEn gine.TabStop = false;
this.groupBoxEn gine.Text = "Engine";
//
// radioButtonEngi ne1
//
this.radioButto nEngine1.FlatSt yle =
System.Windows. Forms.FlatStyle .System;
this.radioButto nEngine1.Locati on = new
System.Drawing. Point(8, 24);
this.radioButto nEngine1.Name =
"radioButtonEng ine1";
this.radioButto nEngine1.TabInd ex = 2;
this.radioButto nEngine1.Text = "Engine 1";
this.radioButto nEngine1.Checke dChanged += new
System.EventHan dler(this.radio ButtonEngine1_V alueChanged);
//
// radioButtonEngi ne2
//
this.radioButto nEngine2.FlatSt yle =
System.Windows. Forms.FlatStyle .System;
this.radioButto nEngine2.Locati on = new
System.Drawing. Point(8, 48);
this.radioButto nEngine2.Name =
"radioButtonEng ine2";
this.radioButto nEngine2.TabInd ex = 2;
this.radioButto nEngine2.Text = "Engine 2";
this.radioButto nEngine2.Checke dChanged += new
System.EventHan dler(this.radio ButtonEngine2_V alueChanged);
//
// radioButtonEngi ne3
//
this.radioButto nEngine3.FlatSt yle =
System.Windows. Forms.FlatStyle .System;
this.radioButto nEngine3.Locati on = new
System.Drawing. Point(136, 24);
this.radioButto nEngine3.Name =
"radioButtonEng ine3";
this.radioButto nEngine3.TabInd ex = 2;
this.radioButto nEngine3.Text = "Engine 3";
this.radioButto nEngine3.Checke dChanged += new
System.EventHan dler(this.radio ButtonEngine3_V alueChanged);
//
// radioButtonEngi ne4
//
this.radioButto nEngine4.FlatSt yle =
System.Windows. Forms.FlatStyle .System;
this.radioButto nEngine4.Locati on = new
System.Drawing. Point(136, 48);
this.radioButto nEngine4.Name =
"radioButtonEng ine4";
this.radioButto nEngine4.TabInd ex = 2;
this.radioButto nEngine4.Text = "Engine 4";
this.radioButto nEngine4.Checke dChanged += new
System.EventHan dler(this.radio ButtonEngine4_V alueChanged);
//
// radioButtonEngi ne5
//
this.radioButto nEngine5.FlatSt yle =
System.Windows. Forms.FlatStyle .System;
this.radioButto nEngine5.Locati on = new
System.Drawing. Point(264, 24);
this.radioButto nEngine5.Name =
"radioButtonEng ine5";
this.radioButto nEngine5.Size = new
System.Drawing. Size(112, 24);
this.radioButto nEngine5.TabInd ex = 2;
this.radioButto nEngine5.Text = "Engine 5";
this.radioButto nEngine5.Checke dChanged += new
System.EventHan dler(this.radio ButtonEngine5_V alueChanged);
//
// radioButtonEngi ne6
//
this.radioButto nEngine6.FlatSt yle =
System.Windows. Forms.FlatStyle .System;
this.radioButto nEngine6.Locati on = new
System.Drawing. Point(264, 48);
this.radioButto nEngine6.Name =
"radioButtonEng ine6";
this.radioButto nEngine6.TabInd ex = 2;
this.radioButto nEngine6.Text = "Engine 6";
this.radioButto nEngine6.Checke dChanged += new
System.EventHan dler(this.radio ButtonEngine6_V alueChanged);
//
// groupBoxSprocke tSizes
//

this.groupBoxSp rocketSizes.Con trols.Add(this. numericUpDownSm allestCounter);

this.groupBoxSp rocketSizes.Con trols.Add(this. numericUpDownLa rgestCounter);

this.groupBoxSp rocketSizes.Con trols.Add(this. numericUpDownSm allestAxle);

this.groupBoxSp rocketSizes.Con trols.Add(this. numericUpDownLa rgestAxle);

this.groupBoxSp rocketSizes.Con trols.Add(this. labelSmallestCo unter);

this.groupBoxSp rocketSizes.Con trols.Add(this. labelLargestCou nter);

this.groupBoxSp rocketSizes.Con trols.Add(this. labelSmallestAx leSprocket);

this.groupBoxSp rocketSizes.Con trols.Add(this. labelLargestAxl eSprocket);
this.groupBoxSp rocketSizes.Loc ation = new
System.Drawing. Point(16, 104);
this.groupBoxSp rocketSizes.Nam e =
"groupBoxSprock etSizes";
this.groupBoxSp rocketSizes.Siz e = new
System.Drawing. Size(232, 160);
this.groupBoxSp rocketSizes.Tab Index = 1;
this.groupBoxSp rocketSizes.Tab Stop = false;
this.groupBoxSp rocketSizes.Tex t = "Sprocket
Sizes";
//
// numericUpDownSm allestCounter
//
this.numericUpD ownSmallestCoun ter.Location =
new System.Drawing. Point(16, 24);
this.numericUpD ownSmallestCoun ter.Maximum =
new System.Decimal( new int[] {

30,

0,

0,

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

10,

0,

0,

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

15,

0,

0,

0});
this.numericUpD ownSmallestCoun ter.GotFocus +=
new System.EventHan dler(this.numer icUpDownSmalles tCounter_GotFoc us);
this.numericUpD ownSmallestCoun ter.ValueChange d
+= new
System.EventHan dler(this.numer icUpDownSmalles tCounter_ValueC hanged);
//
// numericUpDownLa rgestCounter
//
this.numericUpD ownLargestCount er.Location =
new System.Drawing. Point(16, 56);
this.numericUpD ownLargestCount er.Maximum = new
System.Decimal( new int[] {

30,

0,

0,

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

10,

0,

0,

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

15,

0,

0,

0});
this.numericUpD ownLargestCount er.GotFocus +=
new System.EventHan dler(this.numer icUpDownLargest Counter_GotFocu s);
this.numericUpD ownLargestCount er.ValueChanged
+= new
System.EventHan dler(this.numer icUpDownLargest Counter_ValueCh anged);
//
// numericUpDownSm allestAxle
//
this.numericUpD ownSmallestAxle .Location = new
System.Drawing. Point(16, 88);
this.numericUpD ownSmallestAxle .Maximum = new
System.Decimal( new int[] {

35,

0,

0,

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

19,

0,

0,

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

21,

0,

0,

0});
this.numericUpD ownSmallestAxle .GotFocus += new
System.EventHan dler(this.numer icUpDownSmalles tAxle_GotFocus) ;
this.numericUpD ownSmallestAxle .ValueChanged +=
new System.EventHan dler(this.numer icUpDownSmalles tAxle_ValueChan ged);
//
// numericUpDownLa rgestAxle
//
this.numericUpD ownLargestAxle. Location = new
System.Drawing. Point(16, 120);
this.numericUpD ownLargestAxle. Maximum = new
System.Decimal( new int[] {

35,

0,

0,

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

19,

0,

0,

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

30,

0,

0,

0});
this.numericUpD ownLargestAxle. GotFocus += new
System.EventHan dler(this.numer icUpDownLargest Axle_GotFocus);
this.numericUpD ownLargestAxle. ValueChanged +=
new System.EventHan dler(this.numer icUpDownLargest Axle_ValueChang ed);
//
// labelSmallestCo unter
//
this.labelSmall estCounter.Loca tion = new
System.Drawing. Point(62, 24);
this.labelSmall estCounter.Name =
"labelSmallestC ounter";
this.labelSmall estCounter.Size = new
System.Drawing. Size(160, 23);
this.labelSmall estCounter.TabI ndex = 2;
this.labelSmall estCounter.Text = "Smallest
Counter Sprocket";
this.labelSmall estCounter.Text Align =
System.Drawing. ContentAlignmen t.MiddleLeft;
//
// labelLargestCou nter
//
this.labelLarge stCounter.Locat ion = new
System.Drawing. Point(62, 56);
this.labelLarge stCounter.Name =
"labelLargestCo unter";
this.labelLarge stCounter.Size = new
System.Drawing. Size(160, 23);
this.labelLarge stCounter.TabIn dex = 2;
this.labelLarge stCounter.Text = "Largest
Counter Sprocket";
this.labelLarge stCounter.TextA lign =
System.Drawing. ContentAlignmen t.MiddleLeft;
//
// labelSmallestAx leSprocket
//
this.labelSmall estAxleSprocket .Location = new
System.Drawing. Point(62, 88);
this.labelSmall estAxleSprocket .Name =
"labelSmallestA xleSprocket";
this.labelSmall estAxleSprocket .Size = new
System.Drawing. Size(160, 23);
this.labelSmall estAxleSprocket .TabIndex = 2;
this.labelSmall estAxleSprocket .Text =
"Smallest Axle Sprocket";
this.labelSmall estAxleSprocket .TextAlign =
System.Drawing. ContentAlignmen t.MiddleLeft;
//
// labelLargestAxl eSprocket
//
this.labelLarge stAxleSprocket. Location = new
System.Drawing. Point(62, 120);
this.labelLarge stAxleSprocket. Name =
"labelLargestAx leSprocket";
this.labelLarge stAxleSprocket. Size = new
System.Drawing. Size(160, 23);
this.labelLarge stAxleSprocket. TabIndex = 2;
this.labelLarge stAxleSprocket. Text = "Largest
Axle Sprocket";
this.labelLarge stAxleSprocket. TextAlign =
System.Drawing. ContentAlignmen t.MiddleLeft;
//
// groupBoxRoller
//

this.groupBoxRo ller.Controls.A dd(this.numeric UpDownRollerCir cumference);
this.groupBoxRo ller.Controls.A dd(this.label1) ;
this.groupBoxRo ller.Location = new
System.Drawing. Point(16, 272);
this.groupBoxRo ller.Name = "groupBoxRoller ";
this.groupBoxRo ller.Size = new
System.Drawing. Size(232, 56);
this.groupBoxRo ller.TabIndex = 2;
this.groupBoxRo ller.TabStop = false;
this.groupBoxRo ller.Text = "Roller";
//
// numericUpDownRo llerCircumferen ce
//

this.numericUpD ownRollerCircum ference.Decimal Places = 3;

this.numericUpD ownRollerCircum ference.Increme nt = new
System.Decimal( new int[] {

125,

0,

0,

196608});
this.numericUpD ownRollerCircum ference.Locatio n
= new System.Drawing. Point(16, 21);
this.numericUpD ownRollerCircum ference.Maximum
= new System.Decimal( new int[] {

50,

0,

0,

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

25,

0,

0,

0});
this.numericUpD ownRollerCircum ference.Name =
"numericUpDownR ollerCircumfere nce";
this.numericUpD ownRollerCircum ference.Size =
new System.Drawing. Size(56, 20);
this.numericUpD ownRollerCircum ference.TabInde x
= 0;
this.numericUpD ownRollerCircum ference.Value =
new System.Decimal( new int[] {

35,

0,

0,

0});
this.numericUpD ownRollerCircum ference.GotFocu s
+= new
System.EventHan dler(this.numer icUpDownRollerC ircumference_Go tFocus);

this.numericUpD ownRollerCircum ference.ValueCh anged += new
System.EventHan dler(this.numer icUpDownRollerC ircumference_Va lueChanged);
//
// label1
//
this.label1.Loc ation = new
System.Drawing. Point(77, 19);
this.label1.Nam e = "label1";
this.label1.Siz e = new
System.Drawing. Size(130, 23);
this.label1.Tab Index = 2;
this.label1.Tex t = "Roller Circumference";
this.label1.Tex tAlign =
System.Drawing. ContentAlignmen t.MiddleLeft;
//
// groupBoxMaximum EngineRPM
//

this.groupBoxMa ximumEngineRPM. Controls.Add(th is.numericUpDow nRPM);

this.groupBoxMa ximumEngineRPM. Controls.Add(th is.label2);
this.groupBoxMa ximumEngineRPM. Location = new
System.Drawing. Point(16, 336);
this.groupBoxMa ximumEngineRPM. Name =
"groupBoxMaximu mEngineRPM";
this.groupBoxMa ximumEngineRPM. Size = new
System.Drawing. Size(232, 56);
this.groupBoxMa ximumEngineRPM. TabIndex = 3;
this.groupBoxMa ximumEngineRPM. TabStop = false;
this.groupBoxMa ximumEngineRPM. Text = "RPM";
//
// numericUpDownRP M
//
this.numericUpD ownRPM.Incremen t = new
System.Decimal( new int[] {

25,

0,

0,

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

20000,

0,

0,

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

12000,

0,

0,

0});
this.numericUpD ownRPM.GotFocus += new
System.EventHan dler(this.numer icUpDownRPM_Got Focus);
this.numericUpD ownRPM.ValueCha nged += new
System.EventHan dler(this.numer icUpDownRPM_Val ueChanged);
//
// label2
//
this.label2.Loc ation = new
System.Drawing. Point(78, 16);
this.label2.Nam e = "label2";
this.label2.Siz e = new
System.Drawing. Size(124, 23);
this.label2.Tab Index = 2;
this.label2.Tex t = "Maximum Engine RPM";
this.label2.Tex tAlign =
System.Drawing. ContentAlignmen t.MiddleLeft;
//
// buttonClose
//
this.buttonClos e.FlatStyle =
System.Windows. Forms.FlatStyle .System;
this.buttonClos e.Location = new
System.Drawing. Point(16, 408);
this.buttonClos e.Name = "buttonClos e";
this.buttonClos e.TabIndex = 4;
this.buttonClos e.Text = "Close";
this.buttonClos e.Click += new
System.EventHan dler(this.butto nClose_Click);
//
// textBoxResults
//
this.textBoxRes ults.Location = new
System.Drawing. Point(256, 112);
this.textBoxRes ults.Multiline = true;
this.textBoxRes ults.Name = "textBoxResults ";
this.textBoxRes ults.ScrollBars =
System.Windows. Forms.ScrollBar s.Vertical;
this.textBoxRes ults.Size = new
System.Drawing. Size(200, 280);
this.textBoxRes ults.TabIndex = 5;
this.textBoxRes ults.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.EventHan dler(this.butto nCopy_Click);
//
// GearSelectionDl g
//
this.AutoScaleB aseSize = new
System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(472,
456);
this.Controls.A dd(this.textBox Results);
this.Controls.A dd(this.buttonC lose);

this.Controls.A dd(this.groupBo xMaximumEngineR PM);
this.Controls.A dd(this.groupBo xRoller);
this.Controls.A dd(this.groupBo xSprocketSizes) ;
this.Controls.A dd(this.groupBo xEngine);
this.Controls.A dd(this.buttonC opy);
this.FormBorder Style =
System.Windows. Forms.FormBorde rStyle.FixedSin gle;
this.Icon =
((System.Drawin g.Icon)(resourc es.GetObject("$ this.Icon")));
this.Name = "GearSelectionD lg";
this.ShowInTask bar = false;
this.SizeGripSt yle =
System.Windows. Forms.SizeGripS tyle.Hide;
this.StartPosit ion =
System.Windows. Forms.FormStart Position.Center Screen;
this.Text = "Gear Selection";
this.Load += new
System.EventHan dler(this.GearS electionDlg_Loa d);
this.groupBoxEn gine.ResumeLayo ut(false);

this.groupBoxSp rocketSizes.Res umeLayout(false );

((System.Compon entModel.ISuppo rtInitialize)(t his.numericUpDo wnSmallestCount er)).EndInit();

((System.Compon entModel.ISuppo rtInitialize)(t his.numericUpDo wnLargestCounte r)).EndInit();

((System.Compon entModel.ISuppo rtInitialize)(t his.numericUpDo wnSmallestAxle) ).EndInit();

((System.Compon entModel.ISuppo rtInitialize)(t his.numericUpDo wnLargestAxle)) .EndInit();
this.groupBoxRo ller.ResumeLayo ut(false);

((System.Compon entModel.ISuppo rtInitialize)(t his.numericUpDo wnRollerCircumf erence)).EndIni t();

this.groupBoxMa ximumEngineRPM. ResumeLayout(fa lse);

((System.Compon entModel.ISuppo rtInitialize)(t his.numericUpDo wnRPM)).EndInit ();
this.ResumeLayo ut(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 ApplyCalculatio ns()
{
decimal mPrimaryReducti onRatio = 0;
decimal mSixthGearRatio =
0;

if(this.radioBu ttonEngine1.Che cked)
{
mPrimaryReducti onRatio =
63/20M;
mSixthGearRatio =
24/24M;
}
else if(this.radioBu ttonEngine2.Che cked)
{
mPrimaryReducti onRatio =
65/19M;
mSixthGearRatio =
23/26M;
}
else if(this.radioBu ttonEngine3.Che cked)
{
mPrimaryReducti onRatio =
65/19M;
mSixthGearRatio =
24/24M;
}
else if(this.radioBu ttonEngine4.Che cked)
{
mPrimaryReducti onRatio =
69/17M;
mSixthGearRatio =
24/25M;
}
else if(this.radioBu ttonEngine5.Che cked)
{
mPrimaryReducti onRatio =
65/20M;
mSixthGearRatio =
24/24M;
}
else if(this.radioBu ttonEngine6.Che cked)
{
mPrimaryReducti onRatio =
65/20M;
mSixthGearRatio =
24/24M;
}

decimal mRollerCircumfe rence =
this.numericUpD ownRollerCircum ference.Value;
int mSmallCounter =
Convert.ToInt32 (this.numericUp DownSmallestCou nter.Value);
int mLargeCounter =
Convert.ToInt32 (this.numericUp DownLargestCoun ter.Value);
int mSmallAxle =
Convert.ToInt32 (this.numericUp DownSmallestAxl e.Value);
int mLargeAxle =
Convert.ToInt32 (this.numericUp DownLargestAxle .Value);
decimal mRpm =
this.numericUpD ownRPM.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.textBoxRes ults.Text =
"Gears\tRatio\t Speed\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*(mRollerC ircumference/12)) /
((mRatio*(mPrim aryReductionRat io*mSixthGearRa tio)) * 88);
mRatio = Math.Round(mRat io,
3);
mMph =
Math.Round(mPre Total, 2);
//arraymph.Add(mM ph + "" +
mRatio + "" + mCurrentCounter + "" + mCurrentAxle);
arraymph.Add (new
conversions(mCu rrentCounter, mCurrentAxle, mRatio, mMph));

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

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

foreach ( conversions a in g)
{

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

//arraymph.Sort(n ew mysort());
//arraymph.Revers e(g, s);
//foreach (decimal a in
arraymph)
//{
//
this.textBoxRes ults.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_Cli ck(object sender,
System.EventArg s e)
{
Close();
}
private void radioButtonEngi ne6_ValueChange d(object
sender, System.EventArg s e)
{
this.ApplyCalcu lations();
}
private void radioButtonEngi ne5_ValueChange d(object
sender, System.EventArg s e)
{
this.ApplyCalcu lations();
}
private void radioButtonEngi ne4_ValueChange d(object
sender, System.EventArg s e)
{
this.ApplyCalcu lations();
}
private void radioButtonEngi ne3_ValueChange d(object
sender, System.EventArg s e)
{
this.ApplyCalcu lations();
}
private void radioButtonEngi ne1_ValueChange d(object
sender, System.EventArg s e)
{
this.ApplyCalcu lations();
}
private void radioButtonEngi ne2_ValueChange d(object
sender, System.EventArg s e)
{
this.ApplyCalcu lations();
}
private void
numericUpDownSm allestCounter_V alueChanged(obj ect sender,
System.EventArg s e)
{
this.ApplyCalcu lations();
}
private void
numericUpDownLa rgestCounter_Va lueChanged(obje ct sender,
System.EventArg s e)
{
this.ApplyCalcu lations();
}
private void
numericUpDownSm allestAxle_Valu eChanged(object sender, System.EventArg s
e)
{
this.ApplyCalcu lations();
}
private void
numericUpDownLa rgestAxle_Value Changed(object sender, System.EventArg s
e)
{
this.ApplyCalcu lations();
}
private void
numericUpDownRo llerCircumferen ce_ValueChanged (object sender,
System.EventArg s e)
{
ApplyCalculatio ns();
}
private void numericUpDownRP M_ValueChanged( object
sender, System.EventArg s e)
{
ApplyCalculatio ns();
}
private void buttonCopy_Clic k(object sender,
System.EventArg s e)
{
this.textBoxRes ults.SelectAll( );
this.textBoxRes ults.Copy();
}
private void
numericUpDownSm allestCounter_G otFocus(object sender, EventArgs e)
{
this.numericUpD ownSmallestCoun ter.Select(0,2) ;
}
private void numericUpDownRP M_GotFocus(obje ct sender,
EventArgs e)
{
this.numericUpD ownRPM.Select(0 ,5);
}
private void
numericUpDownRo llerCircumferen ce_GotFocus(obj ect sender, EventArgs e)
{

this.numericUpD ownRollerCircum ference.Select( 0,6);
}
private void numericUpDownLa rgestAxle_GotFo cus(object
sender, EventArgs e)
{
this.numericUpD ownLargestAxle. Select(0,2);
}
private void numericUpDownSm allestAxle_GotF ocus(object
sender, EventArgs e)
{
this.numericUpD ownSmallestAxle .Select(0,2);
}
private void
numericUpDownLa rgestCounter_Go tFocus(object sender, EventArgs e)
{
this.numericUpD ownLargestCount er.Select(0,2);
}

private void GearSelectionDl g_Load(object sender,
System.EventArg s e)
{

}
}
}


End Code
---------------------------------
Nov 16 '05 #1
5 2380
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.Componen tModel.Containe r components = null;

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

// TODO: Add any initialization after the InitComponent call

}
public McLb(TestResult .SortByType sortby)
{
InitializeCompo nent();
SortBy = sortby;
}
public int AddItem(TestRes ult newitem)
{
newitem.GetSort +=new
MultiColumnList Box.McLb.TestRe sult.delGetSort (newitem_GetSor t);
return Items.Add(newit em);
}

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

public void SortResults(Tes tResult.SortByT ype sb)
{
SortBy = sb;
ArrayList a = new ArrayList(Items );
a.Sort();
Items.Clear();
Items.AddRange( (object[])a.ToArray(type of(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 InitializeCompo nent()
{
//
// McLb
//
this.DrawMode = System.Windows. Forms.DrawMode. OwnerDrawFixed;
this.DrawItem += new
System.Windows. Forms.DrawItemE ventHandler(thi s.McLb_DrawItem );

}
#endregion

public class TestResult : IComparable
{
public enum SortByType{Gear s, 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(stri ng gears, float ratio, float speed)
{
Gears = gears; Ratio = ratio; Speed = speed;
}
#region IComparable Members

public int CompareTo(objec t obj)
{
if(!(obj is TestResult))
throw new ArgumentExcepti on(
"TestResult can only be compared with another TestResult!");
if(GetSort != null)
{
SortByType sb = GetSort();
switch(sb)
{
case SortByType.Gear s:
return Gears.CompareTo (((TestResult)o bj).Gears);
case SortByType.Rati o:
return Ratio.CompareTo (((TestResult)o bj).Ratio);
case SortByType.Spee d :
return Speed.CompareTo (((TestResult)o bj).Speed);
default: break;
}
}
throw new InvalidOperatio nException("Sor t by not responded to" +
" or SortByType not handled.");
}

#endregion
}

private MultiColumnList Box.McLb.TestRe sult.SortByType newitem_GetSort ()
{
return SortBy;
}

private void McLb_DrawItem(o bject sender,
System.Windows. Forms.DrawItemE ventArgs e)
{
if((Items.Count == 0) || (e.Index == -1)) return;
TestResult tritem = (TestResult)Ite ms[e.Index];
Brush backbrush, textbrush;
if((e.State & DrawItemState.S elected) != 0)
{
backbrush = new SolidBrush(Syst emColors.Highli ght);
textbrush = new SolidBrush(Syst emColors.Highli ghtText);
}
else
{
backbrush = new SolidBrush(Back Color);
textbrush = new SolidBrush(Fore Color);
}
string[] items = new string[]
{
tritem.Gears,
string.Format(" {0:0.000}", tritem.Ratio),
string.Format(" {0:0.000}", tritem.Speed)
};
e.Graphics.Fill Rectangle(backb rush, e.Bounds);
int thirdwidth = e.Bounds.Width / 3;
StringFormat sf = new StringFormat(St ringFormatFlags .NoWrap);
sf.Alignment = StringAlignment .Near; //change to suit
sf.LineAlignmen t = 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.Draw String(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.

Nov 16 '05 #2
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(mCurren tCounter, mCurrentAxle, mRatio, mMph);

Thank you so much for the time.
Mark

On Tue, 7 Sep 2004 06:03:07 -0700, Patty O'Dors
<Pa********@dis cussions.micros oft.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.Componen tModel.Containe r components = null;

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

// TODO: Add any initialization after the InitComponent call

}
public McLb(TestResult .SortByType sortby)
{
InitializeCompo nent();
SortBy = sortby;
}
public int AddItem(TestRes ult newitem)
{
newitem.GetSort +=new
MultiColumnLis tBox.McLb.TestR esult.delGetSor t(newitem_GetSo rt);
return Items.Add(newit em);
}

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

public void SortResults(Tes tResult.SortByT ype sb)
{
SortBy = sb;
ArrayList a = new ArrayList(Items );
a.Sort();
Items.Clear();
Items.AddRange( (object[])a.ToArray(type of(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 InitializeCompo nent()
{
//
// McLb
//
this.DrawMode = System.Windows. Forms.DrawMode. OwnerDrawFixed;
this.DrawItem += new
System.Windows .Forms.DrawItem EventHandler(th is.McLb_DrawIte m);

}
#endregion

public class TestResult : IComparable
{
public enum SortByType{Gear s, 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(stri ng gears, float ratio, float speed)
{
Gears = gears; Ratio = ratio; Speed = speed;
}
#region IComparable Members

public int CompareTo(objec t obj)
{
if(!(obj is TestResult))
throw new ArgumentExcepti on(
"TestResult can only be compared with another TestResult!");
if(GetSort != null)
{
SortByType sb = GetSort();
switch(sb)
{
case SortByType.Gear s:
return Gears.CompareTo (((TestResult)o bj).Gears);
case SortByType.Rati o:
return Ratio.CompareTo (((TestResult)o bj).Ratio);
case SortByType.Spee d :
return Speed.CompareTo (((TestResult)o bj).Speed);
default: break;
}
}
throw new InvalidOperatio nException("Sor t by not responded to" +
" or SortByType not handled.");
}

#endregion
}

private MultiColumnList Box.McLb.TestRe sult.SortByType newitem_GetSort ()
{
return SortBy;
}

private void McLb_DrawItem(o bject sender,
System.Windows .Forms.DrawItem EventArgs e)
{
if((Items.Count == 0) || (e.Index == -1)) return;
TestResult tritem = (TestResult)Ite ms[e.Index];
Brush backbrush, textbrush;
if((e.State & DrawItemState.S elected) != 0)
{
backbrush = new SolidBrush(Syst emColors.Highli ght);
textbrush = new SolidBrush(Syst emColors.Highli ghtText);
}
else
{
backbrush = new SolidBrush(Back Color);
textbrush = new SolidBrush(Fore Color);
}
string[] items = new string[]
{
tritem.Gears,
string.Format(" {0:0.000}", tritem.Ratio),
string.Format(" {0:0.000}", tritem.Speed)
};
e.Graphics.Fill Rectangle(backb rush, e.Bounds);
int thirdwidth = e.Bounds.Width / 3;
StringFormat sf = new StringFormat(St ringFormatFlags .NoWrap);
sf.Alignment = StringAlignment .Near; //change to suit
sf.LineAlignmen t = 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.Draw String(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.


Nov 16 '05 #3
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(mCurren tCounter, mCurrentAxle, mRatio, mMph);

Thank you so much for the time.
Mark

On Tue, 7 Sep 2004 06:03:07 -0700, Patty O'Dors
<Pa********@dis cussions.micros oft.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.Componen tModel.Containe r components = null;

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

// TODO: Add any initialization after the InitComponent call

}
public McLb(TestResult .SortByType sortby)
{
InitializeCompo nent();
SortBy = sortby;
}
public int AddItem(TestRes ult newitem)
{
newitem.GetSort +=new
MultiColumnLis tBox.McLb.TestR esult.delGetSor t(newitem_GetSo rt);
return Items.Add(newit em);
}

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

public void SortResults(Tes tResult.SortByT ype sb)
{
SortBy = sb;
ArrayList a = new ArrayList(Items );
a.Sort();
Items.Clear();
Items.AddRange( (object[])a.ToArray(type of(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 InitializeCompo nent()
{
//
// McLb
//
this.DrawMode = System.Windows. Forms.DrawMode. OwnerDrawFixed;
this.DrawItem += new
System.Windows .Forms.DrawItem EventHandler(th is.McLb_DrawIte m);

}
#endregion

public class TestResult : IComparable
{
public enum SortByType{Gear s, 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(stri ng gears, float ratio, float speed)
{
Gears = gears; Ratio = ratio; Speed = speed;
}
#region IComparable Members

public int CompareTo(objec t obj)
{
if(!(obj is TestResult))
throw new ArgumentExcepti on(
"TestResult can only be compared with another TestResult!");
if(GetSort != null)
{
SortByType sb = GetSort();
switch(sb)
{
case SortByType.Gear s:
return Gears.CompareTo (((TestResult)o bj).Gears);
case SortByType.Rati o:
return Ratio.CompareTo (((TestResult)o bj).Ratio);
case SortByType.Spee d :
return Speed.CompareTo (((TestResult)o bj).Speed);
default: break;
}
}
throw new InvalidOperatio nException("Sor t by not responded to" +
" or SortByType not handled.");
}

#endregion
}

private MultiColumnList Box.McLb.TestRe sult.SortByType newitem_GetSort ()
{
return SortBy;
}

private void McLb_DrawItem(o bject sender,
System.Windows .Forms.DrawItem EventArgs e)
{
if((Items.Count == 0) || (e.Index == -1)) return;
TestResult tritem = (TestResult)Ite ms[e.Index];
Brush backbrush, textbrush;
if((e.State & DrawItemState.S elected) != 0)
{
backbrush = new SolidBrush(Syst emColors.Highli ght);
textbrush = new SolidBrush(Syst emColors.Highli ghtText);
}
else
{
backbrush = new SolidBrush(Back Color);
textbrush = new SolidBrush(Fore Color);
}
string[] items = new string[]
{
tritem.Gears,
string.Format(" {0:0.000}", tritem.Ratio),
string.Format(" {0:0.000}", tritem.Speed)
};
e.Graphics.Fill Rectangle(backb rush, e.Bounds);
int thirdwidth = e.Bounds.Width / 3;
StringFormat sf = new StringFormat(St ringFormatFlags .NoWrap);
sf.Alignment = StringAlignment .Near; //change to suit
sf.LineAlignmen t = 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.Draw String(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.


Nov 16 '05 #4
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:
....\multilistb ox.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?)

....\multilistb ox.cs(116,10): error CS0246: The type or namespace name
'MultiColumnLis tBox' 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********@dis cussions.micros oft.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(mCurren tCounter, mCurrentAxle, mRatio, mMph);

Thank you so much for the time.
Mark

On Tue, 7 Sep 2004 06:03:07 -0700, Patty O'Dors
<Pa********@dis cussions.micros oft.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.Componen tModel.Containe r components = null;
>
> public McLb.TestResult .SortByType SortBy = TestResult.Sort ByType.Gears;
> //default?
> public McLb()
> {
> // This call is required by the Windows.Forms Form Designer.
> InitializeCompo nent();
>
> // TODO: Add any initialization after the InitComponent call
>
> }
> public McLb(TestResult .SortByType sortby)
> {
> InitializeCompo nent();
> SortBy = sortby;
> }
> public int AddItem(TestRes ult newitem)
> {
> newitem.GetSort +=new
>MultiColumnLis tBox.McLb.TestR esult.delGetSor t(newitem_GetSo rt);
> return Items.Add(newit em);
> }
>
> /// <summary>
> /// Clean up any resources being used.
> /// </summary>
> protected override void Dispose( bool disposing )
> {
> if( disposing )
> {
> if( components != null )
> components.Disp ose();
> }
> base.Dispose( disposing );
> }
>
> public void SortResults(Tes tResult.SortByT ype sb)
> {
> SortBy = sb;
> ArrayList a = new ArrayList(Items );
> a.Sort();
> Items.Clear();
> Items.AddRange( (object[])a.ToArray(type of(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 InitializeCompo nent()
> {
> //
> // McLb
> //
> this.DrawMode = System.Windows. Forms.DrawMode. OwnerDrawFixed;
> this.DrawItem += new
>System.Windows .Forms.DrawItem EventHandler(th is.McLb_DrawIte m);
>
> }
> #endregion
>
> public class TestResult : IComparable
> {
> public enum SortByType{Gear s, 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(stri ng gears, float ratio, float speed)
> {
> Gears = gears; Ratio = ratio; Speed = speed;
> }
> #region IComparable Members
>
> public int CompareTo(objec t obj)
> {
> if(!(obj is TestResult))
> throw new ArgumentExcepti on(
> "TestResult can only be compared with another TestResult!");
> if(GetSort != null)
> {
> SortByType sb = GetSort();
> switch(sb)
> {
> case SortByType.Gear s:
> return Gears.CompareTo (((TestResult)o bj).Gears);
> case SortByType.Rati o:
> return Ratio.CompareTo (((TestResult)o bj).Ratio);
> case SortByType.Spee d :
> return Speed.CompareTo (((TestResult)o bj).Speed);
> default: break;
> }
> }
> throw new InvalidOperatio nException("Sor t by not responded to" +
> " or SortByType not handled.");
> }
>
> #endregion
> }
>
> private MultiColumnList Box.McLb.TestRe sult.SortByType newitem_GetSort ()
> {
> return SortBy;
> }
>
> private void McLb_DrawItem(o bject sender,
>System.Windows .Forms.DrawItem EventArgs e)
> {
> if((Items.Count == 0) || (e.Index == -1)) return;
> TestResult tritem = (TestResult)Ite ms[e.Index];
> Brush backbrush, textbrush;
> if((e.State & DrawItemState.S elected) != 0)
> {
> backbrush = new SolidBrush(Syst emColors.Highli ght);
> textbrush = new SolidBrush(Syst emColors.Highli ghtText);
> }
> else
> {
> backbrush = new SolidBrush(Back Color);
> textbrush = new SolidBrush(Fore Color);
> }
> string[] items = new string[]
> {
> tritem.Gears,
> string.Format(" {0:0.000}", tritem.Ratio),
> string.Format(" {0:0.000}", tritem.Speed)
> };
> e.Graphics.Fill Rectangle(backb rush, e.Bounds);
> int thirdwidth = e.Bounds.Width / 3;
> StringFormat sf = new StringFormat(St ringFormatFlags .NoWrap);
> sf.Alignment = StringAlignment .Near; //change to suit
> sf.LineAlignmen t = 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.Draw String(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.
>>



Nov 16 '05 #5
MFC
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.listBox 1 = new System.Windows. Forms.ListBox() ;

with this:
this.listBox 1 = new McLb();

Error when debugging:
...\multilistb ox.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?)

...\multilistb ox.cs(116,10): error CS0246: The type or namespace name
'MultiColumnLi stBox' 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********@di scussions.micro soft.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.Window s.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(mCurren tCounter, mCurrentAxle, mRatio, mMph);

Thank you so much for the time.
Mark

On Tue, 7 Sep 2004 06:03:07 -0700, Patty O'Dors
<Pa********@dis cussions.micros oft.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.Componen tModel.Containe r components = null;
>
> public McLb.TestResult .SortByType SortBy = TestResult.Sort ByType.Gears;
> //default?
> public McLb()
> {
> // This call is required by the Windows.Forms Form Designer.
> InitializeCompo nent();
>
> // TODO: Add any initialization after the InitComponent call
>
> }
> public McLb(TestResult .SortByType sortby)
> {
> InitializeCompo nent();
> SortBy = sortby;
> }
> public int AddItem(TestRes ult newitem)
> {
> newitem.GetSort +=new
>MultiColumnLis tBox.McLb.TestR esult.delGetSor t(newitem_GetSo rt);
> return Items.Add(newit em);
> }
>
> /// <summary>
> /// Clean up any resources being used.
> /// </summary>
> protected override void Dispose( bool disposing )
> {
> if( disposing )
> {
> if( components != null )
> components.Disp ose();
> }
> base.Dispose( disposing );
> }
>
> public void SortResults(Tes tResult.SortByT ype sb)
> {
> SortBy = sb;
> ArrayList a = new ArrayList(Items );
> a.Sort();
> Items.Clear();
> Items.AddRange( (object[])a.ToArray(type of(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 InitializeCompo nent()
> {
> //
> // McLb
> //
> this.DrawMode = System.Windows. Forms.DrawMode. OwnerDrawFixed;
> this.DrawItem += new
>System.Windows .Forms.DrawItem EventHandler(th is.McLb_DrawIte m);
>
> }
> #endregion
>
> public class TestResult : IComparable
> {
> public enum SortByType{Gear s, 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(stri ng gears, float ratio, float speed)
> {
> Gears = gears; Ratio = ratio; Speed = speed;
> }
> #region IComparable Members
>
> public int CompareTo(objec t obj)
> {
> if(!(obj is TestResult))
> throw new ArgumentExcepti on(
> "TestResult can only be compared with another TestResult!");
> if(GetSort != null)
> {
> SortByType sb = GetSort();
> switch(sb)
> {
> case SortByType.Gear s:
> return Gears.CompareTo (((TestResult)o bj).Gears);
> case SortByType.Rati o:
> return Ratio.CompareTo (((TestResult)o bj).Ratio);
> case SortByType.Spee d :
> return Speed.CompareTo (((TestResult)o bj).Speed);
> default: break;
> }
> }
> throw new InvalidOperatio nException("Sor t by not responded to" +
> " or SortByType not handled.");
> }
>
> #endregion
> }
>
> private MultiColumnList Box.McLb.TestRe sult.SortByType newitem_GetSort ()
> {
> return SortBy;
> }
>
> private void McLb_DrawItem(o bject sender,
>System.Windows .Forms.DrawItem EventArgs e)
> {
> if((Items.Count == 0) || (e.Index == -1)) return;
> TestResult tritem = (TestResult)Ite ms[e.Index];
> Brush backbrush, textbrush;
> if((e.State & DrawItemState.S elected) != 0)
> {
> backbrush = new SolidBrush(Syst emColors.Highli ght);
> textbrush = new SolidBrush(Syst emColors.Highli ghtText);
> }
> else
> {
> backbrush = new SolidBrush(Back Color);
> textbrush = new SolidBrush(Fore Color);
> }
> string[] items = new string[]
> {
> tritem.Gears,
> string.Format(" {0:0.000}", tritem.Ratio),
> string.Format(" {0:0.000}", tritem.Speed)
> };
> e.Graphics.Fill Rectangle(backb rush, e.Bounds);
> int thirdwidth = e.Bounds.Width / 3;
> StringFormat sf = new StringFormat(St ringFormatFlags .NoWrap);
> sf.Alignment = StringAlignment .Near; //change to suit
> sf.LineAlignmen t = 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.Draw String(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.
>>


Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6320
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, column 13: there is no attribute "SRC" <bgsound src="C:\My Documents\zingwent.mids"> You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is...
5
2176
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: Objectives The purpose of this assignment is to have you practice the design of object-oriented classes, including one or more of the following concepts
0
1831
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, all dont work "Re:" need help "Re:need help"
9
2917
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 a device. The definition of the table is as follows: CREATE TABLE devicedata ( device_id int NOT NULL REFERENCES devices(id), -- id in the device
7
3296
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 buffer into the character pointer. The code looks like the following: #include <stdio.h> #include <stdlib.h> #include "stdafx.h" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call,
15
4587
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 communicate with a MySQL database table on a web server, from inside of my company's Access-VBA application. I know VBA pretty well but have never before needed to do this HTTP/XML/MySQL type functions.
16
2518
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 uses IE to talk with a server. The user on the client (IE) sees an ASP net page containing a TextBox. He can write some text in this text box and push a submit button.
8
2733
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 the sequence nos and it should be such that i can access it through the structure .plz help me .
0
3936
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 Inbox Reply from Craig Somerford <uscos@2barter.net> hide details 10:25 pm (3 minutes ago)
20
4250
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 is structured as an upside-down tree, and (if I remember correctly) never more than 4 levels. The site basically grew (like the creeping black blob) ... all the pages were created in Notepad over the last
0
8415
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8405
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8273
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6735
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5441
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3903
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3951
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1514
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.