|
leppie wrote:
And why does people write controls without default constructors?
Because they don't have VS.NET or they use MC++ to test it so they don't realize how important the default constructor is to the forms designer
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
|
You do use it, but you defer the setting of the various properties until a little bit later.
The "proper" way to create the control is to expose a Cards property which is a Collection of Card objects. The collection can then be modified at runtime and the control will update itself automatically.
An example of this set up is the ListView control; it exposes an Items collection which contains ListViewItems that represent the items in the control. This collection can be modified at runtime, or code can be output by the forms designer to add the items during the form's InitializeComponent() method.
At first this does not makes sense, but then there are added benefits to coding this way: The control is more flexible in that Cards can be added and removed at runtime; and it opens itself to be easier to use because it follows the standard set by the base controls.
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
I see what your saying, but the Cards array in the CardCtrl class needs to be sized correctly. So to add/remove cards at runtime, ive added an Add() and Remove() method.
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
Is there any way to figure out that specified assembly is loaded or not. What I am trying to do is I want to check if the assembly is already loaded or not. If not then load it if yes then use it from memory. I don't want to load the assembly all the time so just a check.
Thanks
|
|
|
|
|
|
How reliable and sturdy are the above classes?
Are they good enough to write a small server with upto 50 connections that will be passing a 40 character string to client machines over a LAN?
Any useful reading material for these and the base Socket classes? (beyond MSDN)
Michael
Time flies like an arrow. Fruit flies like a banana
|
|
|
|
|
|
How can I write a user defined struct (like the following struct) in binary form to a file?
<br />
[StructLayout(LayoutKind.Sequential)] <br />
public struct BITMAPFILEHEADER <br />
{<br />
public ushort bfType; <br />
public uint bfSize; <br />
public ushort bfReserved1; <br />
public ushort bfReserved2; <br />
public uint bfOffBits; <br />
}<br />
And how can I write the data of a memory block (the only thing I have is the the "IntPtr") in binary form to a file?
IntPtr p --> file
Thanks, Daniel.
|
|
|
|
|
you can use the BinaryFormatter class to serialize an object to a Stream.
This may or may not fit your needs.
|
|
|
|
|
using System.IO;
...
BITMAPFILEHEADER info = new BITMAPFILEHEADER();
info.bla = bla;
...
BinarySerializer bs = new BinarySerializer(typeof(BITMAPFILEHEADER));
Stream mystream = File.Create("SomeFile.ext");
bs.Serialize(mystream, info);
mystream.Close();
one question, what is the purpose of the attribute on your struct?
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
Thank you!
I need the attribut, because the struct is used as a parameter of a interop dll function.
Daniel.
|
|
|
|
|
|
Your options are:
1) Use BinaryWriter, and write them one by one
2) Use serialization (though I'm not sure it will give you exactly what you want on-disk
3) Use unsafe code.
To write the memory block, I think you're only option is unsafe. You'd need to do something like:
IntPtr i = // however you get it;
byte[] data = new byte[size of data];
fixed (byte* pByte = data)
{
*((MyStruct*) pByte) = *((MyStruct*) i.ToPointer());
}
If the data you point to isn't a structure, you'd probably want to copy byte by byte. You could also consider using fixed and using P/Invoke to call CopyMemory
|
|
|
|
|
Ok, I am back
I have a simple custom control. I would like to set a black border around it. However, there is no SetBorder or BorderStyle property for a Control object. Is there a way to do it, or do I have to draw a line around the control?
Thanks,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
Hi,
I would drop a panel in there, set it to DockStyle.Fill, then set its borders up like you want to. Then drop the rest of the control inside the panel.
Hope this helps
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
There is just one problem.
This control represents a resource in an experiment. I would have multiple resources one after the other and they would be stacked in that order. So, I would have to have a panel for every resource that I add. I think this could be an overkill. Don't you think so? If there was just one control, it would be all right, I think.
Thanks,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
I'm not so sure what u mean, but i dont think there should be a problem.
Best is to try it. It would only require a few extra lines in the control, so trying isnt an issue
pankajdaga wrote:
Without struggle, there is no progress
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Hey again,
I tried it and it works, no problem. However, the problem is that I have multiple controls ( typically 100 or so, can run higher) that I instantiate at run-time. I think it would be a lot of overhead to add a panel for each of them.
Since, I only need a black frame around it, I just draw lines at the edges of the control and that works fine
Thanks for the help though. This solution is perfect if you have only a few controls on the form
Pankaj
Without struggle, there is no progress
|
|
|
|
|
pankajdaga wrote:
Since, I only need a black frame around it, I just draw lines at the edges of the control and that works fine
thats wot I was gonna advise until I read the whole post.
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
Hi,
Try the DrawBorder() or DrawBorder3D() Methods of the ControlPaint class.
Thanks,
FiroZ
|
|
|
|
|
Hello,
I have just started developing an application in C# and I don't know how to validate data in a Text Box. To be exact I want it to accept only numbers. Can that be done somehow automatically?
Thanks!
Best regards,
Alexandru Savescu
|
|
|
|
|
Imagine my shock when I was told this is not possible in C#. You have to roll your own solution AFAIK. Yes, I know - what a joke. Ask me about const in C#, I dare you.....
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
|
|
|
|
|
So I have to handle the TextChange event and check to see if the user has entered a valid number?
And another off-topic question:
Can I declare const variables in the sharp thing?
Best regards,
Alexandru Savescu
|
|
|
|
|
Alexpro wrote:
So I have to handle the TextChange event and check to see if the user has entered a valid number?
Yes - what crap is that ? Are they telling me this ISN'T a Win32 text box coming up ? It sure looks like one, why can't I set the number style on it ?
Alexpro wrote:
Can I declare const variables in the sharp thing?
Yes, if they are known compile time values. But you certainly cannot pass a variable ( which is by reference ) as const. What the HELL is that ? C# is broken.
Christian
We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )
|
|
|
|