|
pdriley wrote:
Unfortunately, setting in the constructor will override anything I do to the property page, so that's not all that much use either.
True
Look in System.Windows.Forms.Design, like I said I am not sure...you mite have to override all the properties that u want different defaults.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Thanks. I'll look at that.
Incidentally, you can't use override either...
public override bool AcceptsTab = true; will give you an "override is not valid for this item" message.
So I took "override" out and it compiled okay but gave me a warning saying "The keyword new is required on 'MyNameSpace.MyComponent.AcceptsTab' because it hides inherited member 'System.Windows.Forms.TextBoxBase.AcceptsTab'". This is what promptede me to start looking at "new"
Paul
|
|
|
|
|
Hi Paul
use new when u need to change (really overload) the member to have a different return type or protection level.
use override on protected members of an inherited class.
use nothing to hide member, compiler gives warning, but that is ok, we want that.
By overriding , I meant,
public override bool AcceptsTab
{
get { return base.AcceptTab;}
set { base.AcceptTab = true;}
}
Try that...
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Hi leppie,
I've just got it, and you're part right. Two problems with your idea: (1) I don't want to always set it to true and (2) you can't override AcceptsTab (among other things) because it's not virtual.
Initially, it's actually a lot more simple than you might think. In the component design mode, you can set any of the properties and this drops neatly into the InitializeComponent() function.
This still has a couple of nasty drawbacks though: It still assumes the default is "false", so (1) true shows up as Bold in the form designer and (2) if you set it to false the designer thinks it needs no code, so it doesn't actually override it. You can, of course, change it programmatically but I hate loose ends.
So, after much fiddling, I've discovered that this solves the problem:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[DefaultValue(true)]
new public bool AcceptsTab
{
get { return base.AcceptsTab; }
set { base.AcceptsTab = value; }
} Nice huh? When I've got this sorted out properly (and figured out how to do the same with a font), it may form a basis for my first article. This is not documented ANYWHERE, it took me ages to figure it out!
Paul
|
|
|
|
|
|
I want to create an Access database with C#. Did MS leave this out??? I can do this using DAO and C++!!! Not with ADO??? Why not?
|
|
|
|
|
Look for Adox. For some reason, they don't talk about it much in any of my books.
|
|
|
|
|
Does anyone know how to get a ComboBox in a toolbar without using a third party control? I need to use the standard .NET toolbar with a combobox.
|
|
|
|
|
|
There is no equivelent method to the Windows ZeroMemory function in C#. You need to remember that the memory in C# is managed for you. What are you trying to do, maybe I can help you find a solution.
Aalst
|
|
|
|
|
|
byte buffer = new byte[size];
IntPtr ptr = Marshal.AllocHGlobal(size * Marshal.SizeOf(typeof(byte)));
Marshal.Copy(buffer, 0, ptr, size);
I dunno if this will provide the same ?
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
i have discovered that when i changed the second parameter of mciSendCommand from MCI_OPEN to 0, it did not give the error, but nothing happened.
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
Nnamdi Onyeyiri wrote:
i have discovered that when i changed the second parameter of mciSendCommand from MCI_OPEN to 0, it did not give the error, but nothing happened.
MCI_OPEN = 0x0803;
MCI_OPEN_PARMS is a struct. What does the 2 have to do with each other?
I will have a look.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
MCI_OPEN = 0x0803;
i know that, im passing the value as 0x0803.
leppie wrote:
MCI_OPEN_PARMS is a struct. What does the 2 have to do with each other?
according to the article i gave the link for in my original post, it uses mciSendCommand(0, MCI_OPEN, flags, MyOpenParms);
but when i do this, i get the exception.
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
Hi , it was a bit trickey, but using int's did the job
[DllImport("winmm.dll" , CharSet = CharSet.Ansi)]
static extern int mciSendCommand(int device, int msg, int flags, int param);
const int MCI_OPEN = 0x0803;
const int MCI_DEVTYPE_CD_AUDIO = 516;
const int MCI_SET = 0x080D;
const int MCI_SET_DOOR_OPEN = 0x00000100;
const int MCI_SET_DOOR_CLOSED = 0x00000200;
[StructLayout(LayoutKind.Sequential)]
public class MCI_OPEN_PARMS
{
public int dwCallback;
public int wDeviceID;
public int lpstrDeviceType;
public int lpstrElementName;
public int lpstrAlias;
}
[Flags]
public enum MCIOPEN
{
SHAREABLE = 0x00000100,
ELEMENT = 0x00000200,
ALIAS = 0x00000400,
ELEMENT_ID = 0x00000800,
TYPE_ID = 0x00001000,
TYPE = 0x00002000,
}
and the implementation
MCIOPEN flags;
flags = MCIOPEN.TYPE | MCIOPEN.TYPE_ID | MCIOPEN.SHAREABLE;
MCI_OPEN_PARMS param = new MCI_OPEN_PARMS();
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(param));
param.lpstrDeviceType = MCI_DEVTYPE_CD_AUDIO;
Marshal.StructureToPtr(param, ptr, true);
int result = mciSendCommand(0, MCI_OPEN, (int) flags, ptr.ToInt32());
Marshal.PtrToStructure(ptr, param);
Marshal.FreeHGlobal(ptr);
result = mciSendCommand(param.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);
result = mciSendCommand(param.wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);
OK, I didnt bother with drive numbers
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
|
i know this doesn't apply if some values of your array were already changed, but the runtime asures you, that after constructing everything is set to zero.
thus
byte [] b = new byte[20];
for (int i=0; i<20; ++i)
if (b[i]!=0) MessageBox.Show("you will not see me");
runs without popping up that window.
:wq
|
|
|
|
|
And on top of all the other responses, it should be pointed out that you can always reinitialise any array with the Initialize method.
For example:
byte[] array = new byte[20];
for (int i=0;i<20;i++)
array[i] = i;
array.Initialize();
OR
string[] array = new string[20];
for (int i=0;i<20;i++)
array[i] = i.ToString();
array.Initialize();
One of these answers should help now
Paul
|
|
|
|
|
You should be able to make an "unsafe" call once you import it, something like this:
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
unsafe public static extern void ZeroMemory(System.IntPtr ptr ,uint size);
HTH
Nick Parker
|
|
|
|
|
hi, i'm stuck.
i'm currently trying to work with an old dll and marshalling and stuff went really fine until now. there's a function in that dll declared like
int foo(void *ppMessage);
the function will do some nasty stuff, allocate local memory for the result and write the pointer to the result in the parameter. (thats why there are two ps in the name)
in c++ it would be something like
byte *result;
foo(&result);
(*result)[0]
i have no idea, how to actually read the result using c# - does anyone know? looks somewhat unmanaged
thx in advance
:wq
|
|
|
|
|
ah. just found the Marshal-class - maybe this helps me...
:wq
|
|
|
|
|
First of all, are you sure about the signature of your C method ?
Isn't it more like this :
int foo(void **ppMessage);
To expose this C function to managed code, you need to declare it as :
[DllImport("user32.dll", CharSet=CharSet.Auto, CallingConvention=CallingConvention.Cdecl)]
public static extern int foo(out IntPtr ppMessage);
where user32.dll must be replaced with the actual DLL name.
And I swallow a small raisin.
|
|
|
|