2
Answers

ENums and Properties in Custom Controls

Photo of jeep_thang

jeep_thang

20y
2.1k
1
I am a former vb/vb.net programmer, new to the entire C (C,C++,C#) thing. I have created a series of custom controls for our software, ther are graphical representations of machines that our software manages. My problem is that I have Custom properties on the controls that are of the custom enumerated type. ex. Here is the Variable public csMeterStyle.grfxAlarms mtrAlarm = csMeterStyle.grfxAlarms.None; Here is the property public csMeterStyle.grfxAlarms MeterAlarm { get { return mtrAlarm; } set { mtrAlarm = value; DrawObject(); } } Here is the class that contains the property type. THis is just bel;ow the namespace decleration on the control. public class csMeterStyle { public enum Orientation { UpDown = 0, LeftRight = 2 } public enum grfx3DStyle { Flat = 0, Shaded = 1, Line = 2 } public enum grfxQuality { HighQuality = 0, AntiAlias = 1, HighSpeed = 2, DefaultQuality = 3, None = 4 } public enum grfxState { None = 0, NotAuthorized = 1, NotPreset = 2, PresetInProgress = 3, LowFLowStart = 4, HighFlow = 5, LowFlowStop = 6, BatchStopped = 7, BatchEnded = 8, Failed = 9 } public enum grfxGround { None = 0, NotGrounded = 1, Grounded = 2, Emergency = 3 } public enum grfxAlarms { None = 0, FlowAlarm = 1, AdtvAlarm = 2, BlendAlarm = 3, OverfillAlarm = 4, Printer = 5 } public enum grfxType { FlowMeter=0, Propeller=1 } public enum grfxDirection { Left = 0, Right = 1, Up = 2, Down = 3 } } The problem that I am getting is when I drop the Custom Control on a Form and then view the all Tasks, in the initialize Component code, where the code is setting the value of the custom property, it gives me this error :The variable 'grfxAlarms' is either undeclared or was never assigned. What am I doing wrong here, this stuff works great in VB.net.

Answers (2)

0
Photo of frostyraver
NA 20 0 15y
I know in c# you can do something like this

// If there is selected items do this
if (lisbox.items.selected != null)
{
// Code for your program here if the listbox is selected
}
// If there are no items selected then display this
else
{
 // Error display code here
}

You could maybe set up an error checker that way?
0
Photo of sara khatib
NA 3 0 16y
thank you for replaying my letter but: 1-customer.id is an interger value declare in my customer class 2-rd[0] only have single value from the stored procedure (select min(id) from customer ) the problem is when there is no data in the table it return Null i try to put all my code in TRY{} and CATCH{} but i doesnt work ,if you have ny idea to this setuation i need it very much in my project thanks again
0
Photo of frostyraver
NA 20 0 16y
I might be of some help....i'm still learning this feel free to correct me :D.

customer.id <= is this customer id an int?

=convert.toint32(rd[0].tostring) <= your trying to convert an array of customer ids to an int?

I'm not sure elaborate on this subject. If your seeing this message it's because you have a string value somewhere, you might need more converts or something.