chuawenching Posted July 31, 2003 Posted July 31, 2003 Hi there. I had 3 questions to ask. 1) Public Event ButtonClicked(MessageBoxNumber As Integer, OKButton As Boolean, CancelButton As Boolean, ExitButton As Boolean) --> how to code this in c#? If not mistaken, if they used the keyword WithEvent i will use delegates and events. But now is the keyword event! Any sample codes base on top? 2) Public Property Let MessageBoxPrompt(MessageBoxNumber As Integer, ByVal vData As String) MBox(MessageBoxNumber).Prompt = vData End Property MBox is a type of MessageBox --> oh okay, i know c# got get and set, but there is no let. And can i assign property with arguments like MessageBoxNumber as integer, etc... 3) in vb6, you had in operator '\' for division integer, how can i achieve this in c#? Any help, please? Thanks. Regards, Chua Wen Ching :p Quote
Administrators PlausiblyDamp Posted July 31, 2003 Administrators Posted July 31, 2003 for number 2 - let is no longer needed when doing assignments anymore, all classes inherit from object now so only a property set is required. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
*Experts* Nerseus Posted July 31, 2003 *Experts* Posted July 31, 2003 For 1, do you want to know how to declare the event, raise the event, hook the event, or all three? For 3, all division by integers is, by default, rounded down (just like \). If you do division by anything other than integers, you convert the result to an Int (System.Convert.ToInt32() for example), which will round down automatically (I believe). What kind of math are you trying and what are you getting vs. what you expect? -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
chuawenching Posted July 31, 2003 Author Posted July 31, 2003 i expect integers... yeah for the 1st one, how to do all those three... for number 2, is it possible to show me some codes... i try to code it... but got problem.. once i do this... the types explained above of MessageBox, i declare as Struct MessageBox == SmallWindow.. something like that Code ==== private struct SmallWindowType { public string Prompt; public string Title; public float X1; public float Y1; public float BoxWidth; public float BoxHeight; public float BorderColor; public float BoxColor; public float TextColor; public float TitleColor; public bool OKButton; public bool CancelButton; public float ButtonColor; public float ButtonBorderColor; public float ButtonTextColor; public bool Clicked; public bool Grabbed; public float TmpX; public float TmpY; } .... private SmallWindowType[] SM = new SmallWindowType[10]; public string SmallWindowPrompt(int SmallWindowNumber, string vData) { get { return this.SM[smallWindowNumber]; } set { SM[smallWindowNumber] = vData; } } When i tried to code the set thing, there is compilation errors.. it expects a semicolon behind get and set. I think my method declaration got problems. Until now i seen property, they normall: private Font Haha { get{} set{} } and NOT private string haha(int a, int b) { get {} set {} } Any help? For the third one, do you mean i use back '/' but convert the results into integer? Thanks. Regards, Chua Wen Ching :p Quote
Administrators PlausiblyDamp Posted August 1, 2003 Administrators Posted August 1, 2003 try public string SmallWindowPrompt(int SmallWindowNumber) { get { return this.SM[smallWindowNumber]; } set { SM[smallWindowNumber] = value; } Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
chuawenching Posted August 1, 2003 Author Posted August 1, 2003 So where will i place this: ByVal vData As String ? should it be in public string SmallWindowPrompt(int SmallWindowNumber, string vData) -> ??? Thanks. Regards, Chua Wen Ching :p Quote
Administrators PlausiblyDamp Posted August 1, 2003 Administrators Posted August 1, 2003 Use the version I gave you instead of the public string SmallWindowPrompt(int SmallWindowNumber, string vData) method in your code. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
chuawenching Posted August 1, 2003 Author Posted August 1, 2003 Hmm.. ok... but isn't missing of string vData, does it not affect my outcome of my project... hmm.. maybe i am not good in property... mind you tell me, why i should i ignore it! Thanks.. thanks a lot. Regards, Chua Wen Ching :p Quote
Administrators PlausiblyDamp Posted August 1, 2003 Administrators Posted August 1, 2003 (edited) under C# all property set functions get an implicit parameter just called value, this will be whatever data is assigned to the property. edit - typo Edited August 1, 2003 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
chuawenching Posted August 1, 2003 Author Posted August 1, 2003 Thanks... Regards, Chua Wen Ching :p Quote
*Experts* Nerseus Posted August 1, 2003 *Experts* Posted August 1, 2003 Have you read the help for the events? You have to declare an event interface (what the function, or the handler of the event, will look like) first, then raise the event in code. To hook an event, you need to add an event handler. If you've ever added an event to a control (like a Button's Click event), you can see the syntax by looking at the automatically generated code (look for "+=" in code). I'd read up on events, delegates and such before you worry about coding events. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.