|
In the MFC/Win32 world, my dialog's OnOK() handler would return if a validation error occured or EndDialog (IDOK) if everything was OK. How do I do the same thing in a Form ?
private void OnBtnOK(object sender, EventArgs e)
{
if (validationFails())
return;
else {
}
}
-- modified at 13:39 Saturday 1st April, 2006
this.DialogResult = DialogResult.whatever;<br />
Close();
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Is it possible to enforce that abstract method will be implemented by every class in the hierarchy, even by those classes that derived from classes that ALREADY implemented the abstract method?
Thanks in advanced.
Ilan
|
|
|
|
|
e-laj wrote: Is it possible to enforce that abstract method will be implemented by every class in the hierarchy, even by those classes that derived from classes that ALREADY implemented the abstract method?
No. I not aware of any tricks that will allow that either. You can check the assembly via reflection when it gets loaded an throw an Exception perhaps...
|
|
|
|
|
public abstract class Class1
{
protected abstract void Method1();
}
public interface IInterface1
{
void Method1();
}
public class Class2: Class1
{
protected override void Method1()
{
//....
}
public void HelperMethod()
{
this.Method1();
}
}
public class Class3 : Class2, IInterface1
{
}
this would do it, I don't really see why you would to through all this trouble but it will work.
Class1 is abstract and declares a protected abstract method that Class2 must implement.
Interface1 also requires the same method.
Class3 inherits Class2 and the interface, but because the method is protected, it can't see it, so it needs to explicitly implement it because of the interface, additionally, the HelperMethod gives public access to Method1, this way the method is still public but the Method that follows the rules is not visible to the classes down the hierarchy.
|
|
|
|
|
You missed the keyword, enforce, what he wants to do is perfectly possible, just not enforcable...
|
|
|
|
|
no, I didn't miss it, using the interface in this context has the sole purpose of enforcing it, that's the only reason to declare the same method in an abstract class and an interface, he is still inheritting from the class he wants to inherits but the compiler will force the developer to implement the method in the third class.
And btw, I tested it, if you don't implement the method in the last class you get a compiler error, even though it inherits Class2 that already implemented the method.
|
|
|
|
|
And what about classes inheriting the 3rd class?
|
|
|
|
|
that wasn't the requirement, you can either declare the third class as sealed (then they can't inherit it) or otherwise continue hidding the methods from the child class by declaring them protected and not public, I haven't tested this though.
|
|
|
|
|
I missed something important, interface members have to be public and therefore will be visible to the child classes.
The answer will be that it will work up to the second generation, not beyond, if it's a requirement that classes have to inherit Class3 then it can't be done through design and needs some other solution.
If the requirement is to only inherit from the second class, then all childer classes can be sealed to force to inherit from Class2 or Class1 but not from Class3 and beyond.
Reflection would not be a solution because it would enforce it at runtime, not compile time, basically it would simply throw an error if the separate implementation is not there but it would compile fine.
-- modified at 23:14 Saturday 1st April, 2006
|
|
|
|
|
ricardojb wrote: Reflection would not be a solution because it would enforce it at runtime, not compile time, basically it would simply throw an error if the separate implementation is not there but it would compile fine.
Yes, that's what I told him. I sure as hell hope a person using the code would try debug it at least once, and get notified on the 'enforcement'...
|
|
|
|
|
No I didn't, try it.
what he wants to do is having the compiler enforcing it and the code I posted will just do it.
The interface will require the class to implement the method, normally that wouldn't be enough to enforce to rewrite it because it's already implemented by a parent class, but because it's protected and not public or internal, the child class won't see it and therefore the compiler requires the implementation of the interface.
I didn't say it but it should be obvious that both methods (in the interface and the abstract class) need to have the exact same signature, that is, same name, same return type and same parameters.
|
|
|
|
|
How can I enter in a textbox(for example textbox1) a list of coefficients and convert this list of coefficients from input string to an array of doubles so I can use it to obtain numerator and denominator of a function? Help me please cause I am a beginner.Best regards
|
|
|
|
|
I don't know how you separate each number, but let's assume it's comma separated values, like 1,3,9,75.
The first thing you have to do is separate this values, you can use the Split method of the string class.
char[] separator = new char[1];
separator[0] = ',';
string[] numbers = textbox1.Text.Split(separator);
double[] coeficients = new double[numbers.Lenght];
for (int i = 0; i < numbers.Lenght; i++)
{
try
{
coeficients[i] = double.Parse(numbers[i]);
}
catch
{
}
}
|
|
|
|
|
I have 2 functions PlaySound() & PlaySound_1, I want the PlaySound() will run when Form_Load & the PlaySound_1() will run when a specified function is fired.
And both of those sound don't stop others sound.
How can I do that? Thanks!
Hung!
private void PlaySound()
{
try
{
Sound.PlaySoundWin32("LoopyMusic.wav", 0, (int)(SND.SND_ASYNC | SND.SND_NOSTOP | SND.SND_LOOP));
}
catch
{
if (System.IO.File.Exists("LoopyMusic.wav"))
{
Sound.PlaySoundWinCE("LoopyMusic.wav", 0, (int)(SND.SND_ASYNC | SND.SND_NOSTOP | SND.SND_LOOP));
}
}
}
private void PlaySound_1()
{
try
{
Sound.PlaySoundWin32("time.wav", 0, (int)(SND.SND_ASYNC | SND.SND_FILENAME | SND.SND_NOSTOP | SND.SND_NOWAIT));
}
catch
{
if (System.IO.File.Exists("time.wav"))
{
Sound.PlaySoundWinCE("time.wav", 0, (int)(SND.SND_ASYNC | SND.SND_FILENAME | SND.SND_NOSTOP | SND.SND_NOWAIT));
}
}
}
I have done as follow:
[FORM_LOAD]
Thread thr = new Thread(new ThreadStart(PlaySound));
thr.Start();
[AN EVENT IS FIRED]
PlaySound_1();
Hung
|
|
|
|
|
I want to develop spell checker for Microsoft Word for Sanskrit language. How can I able to do this.
iinf
|
|
|
|
|
Ask the manufacturer for some kind of SDK...
|
|
|
|
|
I am interested in developing the polpular sudoku game.....
for my nokia 60 series phone(6630). I have seen some sudoku articles here @ CP
My Questions are:
1)Is it possible to write my game when I have expertise in c# only.
2)How to make my .NET c# code to work on symbian 60 series mobile phone (Nokia 6630, 6680 etc)
Any body got an idea please reply....
-- modified at 7:43 Saturday 1st April, 2006
|
|
|
|
|
Hi
I have a sting with the contents as above. How can I display it?
string sw = "0\0"
MessageBox.Show(sw); // doesn't work
cheers
|
|
|
|
|
Hi
In C#, the \ is the string escape character. To include a backslash write either of these:
string sw = "0\\0";
string sw = @"0\0";
----------------------------
Be excellent to each other
EasiReports[^] My free reporting component for WinForms.
|
|
|
|
|
Thanks. What should I do if its the output of a function? This is my code:
<br />
CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState;<br />
int iRx = 0;<br />
iRx = theSockId.thisSocket.EndReceive(asyn);<br />
char[] chars = new char[iRx + 1];<br />
System.Text.Decoder d = System.Text.Encoding.ASCII.GetDecoder();<br />
int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);<br />
string szData = new System.String(chars);<br />
<br />
buffer.Append(szData);<br />
string b = buffer.ToString();<br />
<br />
MessageBox.Show("buffer:"+b+" sz:"+szData);<br />
szData comes as a string with a character followed by a \0
cheers
-- modified at 8:32 Saturday 1st April, 2006
|
|
|
|
|
thepersonof wrote: char[] chars = new char[iRx + 1];
System.Text.Decoder d = System.Text.Encoding.ASCII.GetDecoder();
int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
string szData = new System.String(chars);
Thats is becos you are appending a \0! And buffer probably already contains a terminating \0.
|
|
|
|
|
You can't display the character \0, there is no character glyph for that character code in any fonts. It's used as an end marker for zero terminated strings. Strings in .NET don't use a terminator character, so you can just trim that character away.
If you want to show that there is a \0 character, you have to replace it with characters that are possible to display, for an example:
MessageBox.Show("buffer:"+b+" sz:"+szData.Replace("\x00", "[0]"));
---
b { font-weight: normal; }
|
|
|
|
|
Thanks.
I have another slight problem. When I try to recieve data a second time nothing is recieved. The OnDataREcieved callback runs repetedly with no data. do I need to do something to clear the socket befoer recieving more data.
Cheers
|
|
|
|
|
|
Hi
I have the following error:
Error 1 Inconsistent accessibility: field type 'System.Collections.Generic.List<u2.friend>' is less accessible than field 'u2.Prog.friends' C:\Documents and Settings\Ben\My Documents\Visual Studio 2005\Projects\u2\u2\Prog.cs 21 29 u2
The Glob class is internal and the Prog class is public.
This is the code that causes the error:
if (Glob.Prog.friends.Count == 0)
cheers
|
|
|
|