|
hi,
I am new to this stuff.
i have an abstract class which i should inherit from another class. it is not a problem if it a console based application but if the class, that i would like to inherit the abstract class, is gui based (that inherits System.Windows.Forms.Form) then i have a problem.
how should i resolve this problem
with best regards,
rnv
|
|
|
|
|
In theory you should be able to inherit from the abstract class, regardless of the new class gui, unless there's some methods that have to be overidden. How exactly is the problem expressed? Compile error or runtime error?
Stewart DIBBS
|
|
|
|
|
thanks,
here is what i did but got error that the class is not an interface
public class MyClass : System.Windows.Forms.Form, MyAbstractClass
{
....
}
what is the correct syntax?
regards,
rnv
|
|
|
|
|
.NET does not support multiple inheritance. You can only inherit from one base class. Although, you can inherit from multiple interfaces.
You might consider looking at refactoring MyAbstractClass so that can be used in something like the Strategy pattern.
public class MyClass : System.Windows.Forms.Form
{
protected MyFormerlyAbstractClass functionality = new MyFormerlyAbstractClass();
public void SomeMethod()
{
functionality.SomeMethodOnMyFormerlyAbstractClass();
}
}
You could also create an interface to expose the methods that MyAbstractClass would have exposed then implement them in MyClass like this:
public void SomeInterfaceMethod()
{
functionalty.SomeInterfaceMethod();
}
that way, external objects that interact with MyClass won't see any difference to how you would have wanted it anyway.
It isn't a perfect solution, but I think it would work for you.
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
I have to interface to an OEM unmanaged library that uses structs. My code mostly works but I'm stuck on one point. The library .H contains
<code>typedef struct
{ unsigned long size;
unsigned long _private_data[64];
} Settings;</code>
and
<code>ReadSettings (HANDLE h, Settings* pSettings);</code>
which I've coded in C# as
<code>[StructLayoutAttribute(LayoutKind.Explicit)]
public struct Settings
{
[FieldOffsetAttribute(0)]
public uint size;
[FieldOffsetAttribute(4)]
public uint[] _private_data; // 64
public void InitSettings() // because my constructor does not get called...
{
size = 260; // size in bytes
_private_data = new uint[64];
}
public QCam_Settings(int zero) // required but not called ...why?
{
size = 260; // size in bytes (is this correct? Its OK in C++.)
_private_data = new uint[64];
}
}</code>and
<code>ReadSettings(IntPtr myHandle, ref Settings mySettings);</code>
then later
<code> Settings mySettings = new Settings();
mySettings.InitSettings();</code>
This gets used in a call to
<code>ReadSettings(handle, ref mySettings);</code>
This compiles correctly but generates a "Object reference not set to an instance of an object." error at runtime. Also tried using an array so the ref might work
<code>Settings mySettings[] = new Settings[1];
mySettings[0].InitSettings();
ReadSettings(handle, ref mySettings[0]);</code>
but get the same runtime error.
The OEM library has another struct that I can call successfully using the above. I've been on this for three days: anyone got an idea what I'm doing wrong?
Stewart DIBBS
Ottawa, Canada
|
|
|
|
|
|
Thanks for the clue. After a few minutes of experimentation, actual code that works is now
[FieldOffsetAttribute(4), MarshalAs(UnmanagedType.ByValArray,SizeConst=64)]<br />
public uint[] _private_data;
So simple ... yet so hard to solve without third-party input...
Stewart DIBBS
|
|
|
|
|
1. How to create animation and store it in Drawing.Image object? Not from a file? but from an array of Bitmap for ex.
2. How to extract all frames from Image object for editing?
|
|
|
|
|
You could type "animated image" into the search box on the home page of CodeProject and find this article.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
So I can't create animation and store it in Image class?
Thx anyway
|
|
|
|
|
He didn't say that.
He said "You could type 'animated image' into the search box on the home page of CodeProject..." ! Then you can click on and read the appropriate articles returned by the search function.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
There are NO articles about 'animated image'
The most appropriate was "NGif" article about creating .gif using separate class.
But I need to store animation in Image class in some way.
And .gif has only 256 colors - I need 24bit color.
|
|
|
|
|
How to cancel a tabcontrol selectedindex event?
I can't find a proper event to do this.
in 2.0 framework, some events were added:
Deselected : Occurs when a tab is deselected.
Deselecting : Occurs before a tab is deselected, enabling a handler to cancel the tab change.
but how is it possible in .net < 2.0
thanks in advance,
Niko
|
|
|
|
|
You could hack the change by creating your own derived class from TabControl and just monitor the SelectedIndexChanged event. The following code will prevent a user from selecting the third tab in the MyTabControl class.
using System;
using System.Windows.Forms;
namespace WindowsApplication1
{
public class MyTabControl : TabControl
{
private int lastSelectedIndex = 0;
public MyTabControl() : base()
{
lastSelectedIndex = this.SelectedIndex;
this.SelectedIndexChanged +=
new EventHandler( SelectedIndexChanged );
}
private void SelectedIndexChanged( object sender, EventArgs e )
{
if( this.SelectedIndex == 2 )
{
this.SelectedIndex = lastSelectedIndex;
}
else
{
lastSelectedIndex = this.SelectedIndex;
}
}
}
}
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Hi All,
I want to add a contextual menu item when the user drag and drop any
folder or file using right mouse button from local folder to a shared
web folder or vice a versa.how can i achieve this and which interface
i have to implement and where in registry i have to register it.using
icontextmenu and ishellextinit interface and registering them for
HKCR\Folder\shellex\dragdrophandlers and
HKCR\Directory\shellex\dragdrophandlers works for local folders and
network share folder but it does not work for shared web folder which
generally comes under my network places .i also tried registering it
under HKCR\Network\shellex , although there is no dragdrophandlers key
is beneath it so i created one and under it i registered my shell
extension and also tried by registering my shell extension under
HKCR\Network\shellex directly.can anybody tell me how to do
this.Thanks in Advance.
Rakesh
|
|
|
|
|
Anybody know how make object with function like OLE CONTAINER in DELPHI
I want to take out Word and Exsel for read and write.
|
|
|
|
|
Hi all,
I always wondered, when using the lock statement, people lock other variables that the one which we want to serialize access to. Eg, if we want to serialize the call to a static int(varname++;), why do we chose to lock on another variable? Do we assume that whenever we will want to access this variable again, we're going to check if this variable has been locked previously?
Thanks
|
|
|
|
|
They do it as a matter of convenience; the variables on which they lock will always exist.
In C#, for example, let's say we want to access an instance variable within the class from more than one thread running within the class. So, we'd lock on the instance of the class since we know the class exists since we're running those methods!
lock( this )
If we want to access a static variable within a class from more than one thread, we use the runtime information to lock on that class, since we know the class exists, since we're attempting to change the value of a static variable contained within it.
lock( typeof( MyClass ) ) .
I hope that makes sense.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
I have a problem!
i have an Array of buttons, and all of the buttons are connected to one event, let us say OnClick Event, now when i get in to the Event function i Cust the sender to a temp button in the function but the problem is that i want or better say need the buttons indexes becaue i need to check the buttons around the selected one.
How can i solve this problem?
Thanks you all!
|
|
|
|
|
Store the button index in the button's Tag property
|
|
|
|
|
What do you mean?
please give e.g.
Thanks
|
|
|
|
|
What the last free name means is the following:
Button[] buttons = new Button[ numberOfButtons ];
for( int i = 0; i < numberOfButtons; i++ )
{
buttons[ i ] = new Button();
buttons[ i ].Tag = i;
buttons[ i ].Text = String.Format( "Button {0}", i );
} And, in your button click event handler
Button b = ( Button ) sender;
int buttonIndex = ( int ) b.Tag;
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
what about a Matrix? [,]?
|
|
|
|
|
Okay, I don't know the specific class Matrix to which you have referred. However, let's assume that you have a Matrix class that acts like an n x m array of object s. Then, you could have the following code:
Matrix m = new Matrix( n, m );
for( int i = 0; i < n; i++ )
{
for( int j = 0; j < m; j++ )
{
m[ i, j ] = new Button();
m[ i, j ].Tag = new int[] { i, j };
}
}
And you could then acess the button in your event handler like so:
Button b = ( Button ) sender;
int[] index = ( int[] ) b.Tag;
That would then contain your index where the row index is in the first entry of index and the column entry in the second.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
i have a point.
how to compare this condition
PointF point=new PointF();
point = x.Intersect(y);
first time i am getting (429.5,215) as point
next time i am getting (+infinity,NaN) as point
So I like to have point which is having values in the point(numerice values).but not infinity or NaN
for this only I need to write (If condition).
if(point is not infinite)
{
}
if point is infinite then it not should enter in the if condition.
sometimes i get infinite values in the point.
what is the syntax for the above one.
Please help me out.
Thanks in Advance
Satya
satya
-- modified at 8:07 Friday 25th November, 2005
|
|
|
|