|
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 )
|
|
|
|
|
Christian Graus wrote:
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 ?
Yeah, that's odd. Here's what I did:
private void txtctrl_TextChanged(object sender, System.EventArgs e)
{
String txt = txtctrl.Text;
try
{
int y = Convert.ToInt32(txt);
}
catch (FormatException)
{
MyBtn.Enabled = false;
return;
}
MyBtn.Enabled = true;
}
It wasn't that difficult after all.
Best regards,
Alexandru Savescu
|
|
|
|
|
*grin* I knew it would not be a lot of work, I still think it's dumb that you need to roll such a simple piece of boilerplate code yourself for something so common it's been in there for donkeys years.
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 )
|
|
|
|
|
Christian Graus wrote:
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 ?
However using C# makes it simplistic to handle an event such as TextChange and validate that it is a valid number. The code to do the validation is far shorter than the length of this post.
Christian Graus wrote:
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.
Check the dotnet mailing list. There was a length discussion on why they do not currently support this feature.
Jared
jparsons@jparsons.org
www.prism.gatech.edu/~gte477n
|
|
|
|
|
jparsons wrote:
However using C# makes it simplistic to handle an event such as TextChange and validate that it is a valid number. The code to do the validation is far shorter than the length of this post.
That isn't the point.
jparsons wrote:
Check the dotnet mailing list. There was a length discussion on why they do not currently support this feature.
Was the gist of it what Eric Gunnerson said when I bought it up ? They decided it was too hard to impliment ? I disgaree, the CLR does not need to support it. The CLR does not support, for example, the difference between out and ref ( is it ref ? I forget ). The C# compiler does that, and supporting a const parameter would be pretty much the same sort of deal in reverse. Instead of making sure I *do* assign a value to this variable, make sure I *don't*.
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 )
|
|
|
|
|
Basic validation is done using the Validating and Validated events; however you probably want to stop the user from entering any text at all.
If you inherit from the TextBox class, you can intercept the OnKey* events to stop non-numbers from being entered in.
James
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
yes, and you can use the ErrorProvider component to give the user a good reason as to why it's wrong.
|
|
|
|
|
Ok, I am going to say no you Can't intercept the Text in the *OnKey* events unless you give me a sample. I have been trying to stop text being entered for days now and I am about to write a Custom handler using the WndProc function.
Basically, the OnKey events don't work. I've set "e.Handled = True" and I've even tried not passing the Argument to the Base Class. Nothing works and whatever Text the user enters goes into the TextBox!
|
|
|
|
|
Something like this perhaps?
protected override void OnKeyPress(KeyPressEventArgs e)
{
const char Delete = (char) (int) Keys.Delete;
const char Backspace = (char) 8;
char key = e.KeyChar;
string strKey = key.ToString();
System.Globalization.NumberFormatInfo nfi =
System.Globalization.NumberFormatInfo.CurrentInfo;
e.Handled = true;
if( key == Delete || key == Backspace )
e.Handled = false;
if( char.IsDigit(key) )
e.Handled = false;
if( nfi.NumberDecimalSeparator == strKey )
{
if( Text.IndexOf(nfi.NumberDecimalSeparator) == -1 )
e.Handled = false;
}
if( nfi.NegativeSign == strKey )
{
int selStart = SelectionStart;
int selLength = SelectionLength;
if( Text.IndexOf(nfi.NegativeSign) == -1 )
{
Text = nfi.NegativeSign + Text;
SelectionStart = selStart + nfi.NegativeSign.Length;
SelectionLength = selLength;
}
else
{
Text = Text.Remove(0, nfi.NegativeSign.Length);
if( selStart == 0 )
{
selLength -= nfi.NegativeSign.Length;
SelectionStart = 0;
SelectionLength = selLength;
}
else
{
SelectionStart = selStart -
nfi.NegativeSign.Length;
SelectionLength = selLength;
}
}
}
base.OnKeyPress(e);
} Usage: - Create a class that inherits from
System.Windows.Forms.TextBox - Add above method to it
- Use in application
HTH,
James
- out of order -
|
|
|
|
|
I am a Senior Developer who has recently been caught up with .NET euphoria.
I am about to write a web based application for Administering IIS Properties like
1) create domains
2) change metabase properties etc just like ISM.
I know how to do this using VBScript or ASP for that matter.
However we want to implement this as .NET application in C# or vb.net or asp.net
I know java(100%), c# ( just started) , VBSctips (good enough), c++ (100%)
Can somebody suggest which would be a better choice for me keeping in mind the following points
1) I do care about performance. I change one check box in IIS properties and save. This should not take irritatingly long time.
This application will be used by many people simultaneously on a windows server. Te most frequent operation will be changing metabase properties.
2) I need to access the following Windows stuff
a) windows users/groups
b) registry ( i can use VBScript if I want to enumerate registry)
c) File System files
3) This application is to be accessed by a known set of people with login/password
Should I use SOAP/XML stuff as well or do I make is a Simple WebApplication
Any Suggestions?
Swarup Das
|
|
|
|
|
|
is there a way to do this? i need a rectangle with rounded corners, but it also needs to be filled in. Help me plz.
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|