|
You can't, not directly anyway.
You are limited to one base class, but you can implement as many interfaces as you desire.
The recommended way is to have class1 and class2 be interfaces (or just one of them be an interface). The downside is that it makes it more difficult to extend existing functionality because you have to reimplement everything.
I suppose one solution would be to have interfaces IClass1 and IClass2 then create your classes Class1 which implements IClass1 and Class2 which implements IClass2 .
Then your class that "inherits" from Class1 and Class2 implements both interfaces, relegating the method calls back to Class1 and Class2 objects if the base functionality is desired. And since you implement both interfaces you can cast the object to both interfaces as well.
Its not pretty but it should work for the most part.
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
So you can not do something like this?
<br />
class myClass:Class1<br />
{<br />
<br />
}<br />
<br />
class Class1:Class2<br />
{<br />
<br />
}<br />
Nick Parker
|
|
|
|
|
Nick Parker wrote:
So you can not do something like this?
class myClass:Class1
{
}
class Class1:Class2
{
}
Of sourse you can - that's single inheritance.
But you can't do:
<br />
class myClass: Class1, Class2<br />
{<br />
}<br />
The "solution" is to do the following:
<br />
class Class1<br />
{<br />
void foo(){};<br />
}<br />
<br />
interface IClass2<br />
{<br />
void bar();<br />
}<br />
<br />
class Class2: IClass2<br />
{<br />
void bar(){};<br />
}<br />
<br />
class MyClass: Class1, IClass2<br />
{<br />
Class2 m_implClass2 = new Class2;<br />
<br />
void bar()<br />
{<br />
m_implClass2.bar();<br />
}<br />
}<br />
<br />
Hope this helps!
Dale Thompson
|
|
|
|
|
Thanks for clearing me up on this one Dale.
Nick Parker
|
|
|
|
|
Sure thing.
Dale Thompson
|
|
|
|
|
This you can do.
I'm not really sure what this is called (baring a mini-object model).
I understand multiple inheritance as:
<br />
class mybase1<br />
{<br />
}<br />
class mybase2<br />
{<br />
}<br />
class mysuper:mybase1,mybase2<br />
{<br />
}<br />
<br />
Which you can't do in C#.
Cheers,
Simon
X-5 452 rules.
|
|
|
|
|
I want to make a program that recognize my voice and when I will speak, i will order the program to run something, like say"open + filetoopen" will open the program I want to start
I want to write something to a document, I can tell each word to my program and he can write it to the document.
Things like that. Anybody know how can I do this.I want something that recognize my voice and answer to her.
Thanks
|
|
|
|
|
Microsoft agent has some decent speech input, and I think a sample comes with the .NET framework. If not try www.microsoft.com/msagent
|
|
|
|
|
Can someone give me the basic steps to getting this going? I have a lump of code which takes a while to execute so I want to temporarily put a progress bar into the status bar while this is happening then remove it when the code has finished.
The docs mention using ownerdraw status bar panels, but I need a bit more detail on exactly how.
|
|
|
|
|
|
At last I found the way to compile manifest into C# exe file. Download program called PE Explorer (http://www.heaventools.com). This program can insert manifest resource into the final exe file. It's a little odd, but it works very well
|
|
|
|
|
I want to use this property for Button.Is that possible?
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
Not with the current set of .NET controls. Its easy after you figure out how to get the parent to draw itself on a Graphics object you give it, but so far I've hit a dead end there.
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
James T. Johnson wrote:
Its easy after you figure out how to get the parent to draw itself on a Graphics object you give it, but so far I've hit a dead end there.
What does this means James?
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
|
Thanks you,I'll do that.
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
In my aged c code, there is tons of "%.1f" in source.
How can i transfer it to c#?
i read the document of Console.Write.
the format is describe by {a,b:s}.
How can i get the same result as c format string like "%.1f"?
|
|
|
|
|
Are you asking how you can use "%.1f" in C# or for the format string that produces an equivilant to "%.1f"?
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|
|
You can use the Math.Round static function or the String.Format method (called implicitly below).
double d = 136.7835;
Console.WriteLine(Math.Round(d, 1));
Console.WriteLine("{0:.#}", d);
Both of these result in 136.8 which is what the C/C++ format specifier %.1f would provide.
Cheers,
Tom Archer
Author, Inside C#
|
|
|
|
|
Console.WriteLine("Test: {0:f1}", 765.7689);
The result will be 765.8 instead of 765.7, but usually that is the preferred output...
/moliate (just started learning C#)
|
|
|
|
|
I have written a C# windows application. However, when the program is running, and I want to shut down windows, every program closes except my C# program; and windows does not shut down. It just waits. When I close my program manually, windows shuts down without a problem. The cause is that I have overriden the Closing event of the main form like this:
private void WindowsCloserForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
OpenDialog(false);
}
I wanted this behaviour however: closing the form should not end the program, but just hide it. (Via an icon in the system tray you can close the program) If I do not override the Closing event, this problem does not occur. Can this be a bug in the framework, or am I forgetting something?
Ludwig
|
|
|
|
|
This thread should have an answer: Click here
--
David Wengier
Sonork ID: 100.14177 - Ch00k
|
|
|
|
|
I'm sorry, I didn't remember I already asked this question in this place. I'll try it out...
|
|
|
|
|
Well, I tried:
override protected void WndProc(ref Message m)
{
int message = m.Msg;
if ( message == 0x0012 ) //WM_QUIT
{
}
else
if ( message == 0x0010 ) //WM_CLOSE
{
// Who closed the form?
}
base.WndProc(ref m);
}
but is seems that quitting windows does not raise the WM_QUIT event. It raises the WM_CLOSE event, though. But how can I check who closed the form? I don't know how to use LParam of WParam?
|
|
|
|
|
I am truly at a loss... It appears that every single event that is raised to ask if the program/form should close just asks not providing any information as to why its asking.
I've even fiddled with using reflection to get at some internal members, but all I get is "member not found" errors
Here's what I've found if you want to investigate it further
Inside of the Application class is a nested type called ThreadContext.
You can get the Type for this with this bit of code.
public Type GetThreadContextType() {
MemberInfo[] typesInApp = typeof(Application).FindMembers(
MemberTypes.NestedType,
BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public,
new MemberFilter(memFilter), null
);
return MemberInfo[0].DeclaringType;
}
private bool memFilter(MemberInfo m, object filterCriteria)
{
if( m.Name.IndexOf("ThreadContext") != -1 )
return true;
else
return false;
} Now that class has a static method called "FromCurrent" which takes no arguments and returns the ThreadContext for the current application. This is retrieved by looking up a LocalDataStore on the Thread, the LocalDataStoreSlot is stored in a static field named tlsSlot , this slot corresponds to the thread's ThreadContext object.
Once you have an instance of ThreadContext you can call the GetState method passing in the value 0x10 to see if the Thread has an AppQuit message posted or pass in 0x08 to see if the Thread has a Quit message posted.
Here is the code I've been pounding out since you posted your message, if anyone can get it to work I'll buy you a beer the next time you are in the area
Type app = typeof(Application);
MemberInfo[] typesInApp = app.FindMembers(
MemberTypes.NestedType,
BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public,
new MemberFilter(memFilter), null
);
Type typeThreadContext = typesInApp[0].DeclaringType;
object threadContext = Thread.GetData(
(LocalDataStoreSlot) typeThreadContext.InvokeMember(
"tlsSlot",
BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Static,
null, null, new object [] { }
)
);
bool StatePostedAppQuit = (bool) typeThreadContext.InvokeMember(
"threadState",
BindingFlags.GetField | BindingFlags.NonPublic,
null, threadContext, new object[] { 0x10 }
);
bool StatePostedQuit = (bool) typeThreadContext.InvokeMember(
"threadState",
BindingFlags.GetField | BindingFlags.NonPublic,
null, threadContext, new object[] { 0x08 }
); You'll need the memFilter method from the first chunk of code above.
Feel free to completely destroy that bit of code, I'm getting an exception on the line that retrieves the threadContext. I've tried by using the FromCurrent method and the method above (which basically does what FromCurrent() does).
Now I get to go take my car in to get a flat tire fixed
James
Sonork: Hasaki
"I left there in the morning
with their God tucked underneath my arm
their half-assed smiles and the book of rules.
So I asked this God a question
and by way of firm reply,
He said - I'm not the kind you have to wind up on Sundays."
"Wind Up" from Aqualung, Jethro Tull 1971
|
|
|
|