|
Hi all,
Kinda new to the .NET/C# thing so maybe there's a simple solution for this (I hope). I'm creating a subclass of ListBox, but instead of normal listbox items I want it to display panels (containing various other controls). I know how to make it an "ownerdraw" listbox and I've provided the proper measurements for each panel in the "MeasureItem" override, but I don't know what to do in the "DrawItem" override in order to get the panels to be displayed. How does one do this? All the examples of ownerdraw listboxes I've seen use the Graphics.DrawRectangle(...) and Graphics.DrawString(...), etc., commands to draw things, when I really just want the panel control to draw itself.
Thanks!
Phil
|
|
|
|
|
I'm working on using RSA encryption in a Form Application. I'm stuck, How do I get access to the Public Key of the Public/Private Key pair ? Can I access it directly through RSAParameters ? I need to be able to send it over a socket.
Can I send the whole RSAParameters class over the socket some how ?
I'm triing to Serialize the RSAParameters Class but ehte resulting buffer is blank:
public byte [] GetPublicKeyBuff()
{
RSAParameters result = new RSAParameters();
try
{
BinaryFormatter formatter = new BinaryFormatter();
result = rsa.ExportParameters(false);
Stream s= new MemoryStream();
formatter.Serialize(s, result);
int iSize=(int)s.Length;
byte []PubKey = new byte[iSize];
s.Read(PubKey,0,iSize);
BinaryWriter bw = new BinaryWriter(File.OpenWrite("c:\\temp\\test\\pubkey.dat"));
bw.Write(PubKey,0,iSize);
bw.Close();
return PubKey;
}
catch (CryptographicException e)
{
Console.WriteLine(e.Message);
return null;
}
Any ideas out there ?
|
|
|
|
|
Hello, i am trying to make an application that will be nested within another app and will 1) create a BackUP folder if it doesn't exist, and 2) it will check for a number of files to see which exist and which not in the backup and act as told.
So far i made it check for the backup folder and create one but i can't execute more than one 'if' expression, thus i get stuck with only copying (back up) only one file. here's a fragment of the the code:
public static void FilesExist()<br />
{<br />
string[] strOFiles;<br />
strOFiles = new string[16];<br />
strOFiles[0] = @"..\login.cfg";<br />
strOFiles[1] = @".\BackUp\file1.cfg";<br />
strOFiles[2] = @"..\multi.idx";<br />
strOFiles[3] = @".\BackUp\file2.cfg";<br />
<br />
if (!File.Exists(strOFiles[1]))<br />
{<br />
File.Copy(strOFiles[0], strOFiles[1]);<br />
}<br />
else if (!File.Exists(strOFiles[3]))<br />
{<br />
File.Copy(strOFiles[2], strOFiles[3]);<br />
return;<br />
}<br />
<br />
}
maybe use a 'switch' stament, without a 'break;' until all code gets executed? thanks in advance
|
|
|
|
|
So, your array contains on even indices the backup file name and on odd indices the original file name...
From the code you have the easiest change is to delete the else because as soon as the first if condition is satisfied all others will be ignored because that are something "else".
The same would be true of the switch . By the way, Fall through is not permitted in C# switch statements unless is it falling through without doing anything.
switch(someValue)
{
case 1:
case 2:
break;
case 3:
case 4:
break;
}
Have you considered using a loop?
This is a better, more flexible solution...
for(int i=0; i<strOfFiles.Length; i+=2)
{
if (!File.Exists(strOfFiles[i+1]))
{
File.Copy(strOfFiles[i], strOfFiles[i+1]);
}
}
Of course you would have to set your array to be the correct length.
--Colin Mackay--
When Monty Python meets Star Trek: WHAT is your name? Captain Jean-Luc Picard. WHAT is your quest? I seek the Holy Grail. WHAT is the average velocity of a Bird of Prey? Romulan or Klingon? I ... I don't know AAAAAHHHHH!
|
|
|
|
|
I agree that the second solution is better, but I just wanted to point out that you can use goto case # to go to the next case instead of flowing through, which - as you said - isn't allowed.
There was discussion a long time back on MSDN or something as to why Microsoft didn't allow cases to flow through when they even provided a goto case statement; their answer seemed rather pointless. Oh well...
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Yeah, Colin, i tried the 'for', loop and it seems to do the job much smoother i get an exception (not crash) when no more files are meant to be copied. i suspect it's because it goes on until it reaches 15 (the total array length starting from 0)
exception: File name cannot be null.
Parameter name: sourceFileName.
Anyway i could work around if no more files are meant to be copied?
Edit: i tried doing:
if (strOFiles = "")<br />
break;
but either "" or 'null', don't work 'cause i canno implicity convert string to bool Any way to make this one work?
thank you.
|
|
|
|
|
I can't seem to get out of this exception, damn . Anyone has stumbled upon a similar matter?
|
|
|
|
|
I use Guid for my Table instead of autonumber in my database table. I show this table in a grid.When I use autonumber it generate primary key in datagrid of my application,now here there is no number and it doeasn't happend and when user add a new row in datagrid of my application they get error that this record is null. How can I handle it so Guid automatcly generate in datagrid like autonumber.Any idea?
Mazy
No sig. available now.
|
|
|
|
|
For an MS Access database to do this, it doesn't appear to be possible. You can, however, store a GUID as a Text field in MS Access. If you're using a DataGrid , you can use Guid.NewGuid when a new row is created (handle the DataTable.RowChanging and check that Action is DataRowAction.Add - this only works if using a DataSet or DataTable ).
Having the client generate the Guid will further ensure that the GUID is unique, since they are mathematically proven to be unique on different machines, but fast generation on a single machine can produce the same GUID (and we've verified that with our own tests).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath Stewart wrote:
you can use Guid.NewGuid when a new row is created (handle the DataTable.RowChanging and check that Action is DataRowAction.Add - this only works if using a DataSet or DataTable).
Yes Heath.That exactly what I did but it seams some checking happpend before this event and it sho a messagebox that said this field can not be null,Do you want to correct the vale? (or something like this),and then RowChanging fire. Of course my problem is only when user add data in datagrid itself.
Mazy
No sig. available now.
|
|
|
|
|
If you're using a strongly-typed DataSet , it's possible that you might have the DataColumn.AllowDBNull and / or the DataColumn.Unique properties set to false and true , respectively. These conditions might be validated before any events are fired on the underlying rows.
With the MSDE/SQL Server, you'd simply enter (newid()) as the default value for the field in the table on the server and that's it.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath Stewart wrote:
With the MSDE/SQL Server, you'd simply enter (newid()) as the default value for the field in the table on the server and that's it.
Yes that could be done in ACCESS too.
Heath Stewart wrote:
If you're using a strongly-typed DataSet, it's possible that you might have the DataColumn.AllowDBNull and / or the DataColumn.
Hehhee...you know what error I get now after set AllowDBNull to true?
---------------------------
Error when committing the row to the original data store.
---------------------------
Cannot change a proposed value in the RowChanging event. Do you want to correct the value?
---------------------------
Yes No
---------------------------
The whole point of using guid is be aware of Primarykey in the application rather than that AotoNomber. I don't wanna miss it.
Mazy
No sig. available now.
|
|
|
|
|
This happens more often with Debug builds than Release builds, but I often have a Form with lots of controls and, hence, lots of painting to do that launches another Form, whether it is an Open File Dialog or a new Form. Basically, the Form at the bottom of the z-order does some ugly flashing while the OpenFileDialog or new Form closes.
I've tried SuspendLayout/ResumeLayout on the Form at the bottom but this doesn't seem to help with its constituent controls. Any ideas on how to stop this?
I can show you screenshots if you think that would help.
|
|
|
|
|
SuspendLayout and ResumeLayout are really only useful when initializing controls. Once they're initialized, it's pointless to use them.
As for the problem, do you notice the flickering when passing another window over your application (a window from another application)? If so, painting isn't the error exactly. Whatever occurs in your app in this case when you close the form is eating up enough CPU cycles - or blocking the main UI thread completely - to cause slow repainting of invalidated regions.
If the behavior is the same whether you pass one of your windows, or a window from another application over yours (or minimize -> restore, whatever to invalidate your form), then you might have to consider overriding several of the more offensive controls and enable double-buffered painting. See the Control.SetStyle method and ControlStyles enumeration documentation for details.
If many of these controls are already custom controls that you've written, using a double-buffered approach to painting (if you haven't already) will help, but you should also be mindful of the invalidated region when handling OnPaint (its better to override OnEventName methods when possible, as opposed to handling the events in a child class) and only repaint the invalidated regions (again, if you haven't already).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I wanna check in my database if an item exist,what do you suggest is the best way for that?I myself get a quey whith WHERE condition contain that value ,if it return null so it doesn't exist. I use MS Access so I can't use stored procedure.
I want a way other than Unique property.
Mazy
No sig. available now.
|
|
|
|
|
Do you mean you want to check to see if a column, table, view, etc. exists in your database? If so, you can do this easily in SQL Server / MSDE (which is a hell of a lot better than MS Access, and MSDE is free (it is SQL Server without some of the advanced features and limited connections)) using the SCHEMA_INFORMATION tables.
For MS Access, it doesn't provide such meta-data that I'm aware of (I did a lot of programming with access many years ago, but haven't in the last couple years...thank God!). You can use a Module and use the object model to see if objects exists, but I'm not sure how you could execute such a function without using an interop assembly for MS Acccess.
You really should take a look at MSDE, though. It's a royalty-free, relatively small installation (you can even have up to 16 instances of MSDE/SQL Server running on a single machine) with REAL security (both SQL and Windows authentication modes) and is a true RDBMs.
Sorry I couldn't answer your question the way you wanted, but 1) I don't think it's possible (from what I remember, and from what the MS Access documentation says - or rather doesn't say), and 2) MS Access sucks for any serious programs. You can also take advantage of the System.Data.SqlClient namespace elements with MSDE, too - which gives you much better support that generic OLE DB (which is an abstract data access mechanism, after all).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for reply but I don't want to look about a column. I kmow those things about SCHEMA_INFORMATION and other things you say,I want to chheck existence of a record in table. I have two column:First Name and LastName. I want to check if First Name+LastName is unique. I do it in the way that I mentioned in first message but I want to know if there is better way or not.
Mazy
No sig. available now.
|
|
|
|
|
Sorry, your question didn't quite make sense. "Record" instead of "item" would've been the optimal word. I didn't quite follow what you meant.
The way you're doing it (or using the COUNT aggregate and checking for a result value of 1) is fine, but you can create a multi-field index that is unique, thus making a UNIQUE index as you could in MSDE/SQL Server. I know you said you didn't want to do this, but I don't know if you were aware that multi-field indexes are possible.
Just open the Indexes Window for your table. On a new line, type an index name (like "Name"), and select the first field you want. Below that, select the second field you want but do not type an index name. You can do this for up to 10 rows. Finally, go back to the first row and set Unique to Yes. This is documented in the MS Access help. This should also cause an OleDbException to be thrown, which you can catch in a try-catch block and handle gracefully. We do this with SQL Server on our web site quite a bit and just show friendly errors when they occur while logging more information to the trace log (or other event target).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath Stewart wrote:
I don't know if you were aware that multi-field indexes are possible.
I didn't aware of that. I do it in this way now
Well thank you. I learn something useful from you man.
Mazy
No sig. available now.
|
|
|
|
|
Hi!
How do you create an xml file using a C# windows forms?
And also, please tell me to how to read and write on it. Thanks a lot!
ps
Is it possible to query an xml file using C# code? if yes, can you tell me how?
"To teach is to learn twice"
|
|
|
|
|
|
Daljv,
Here is an article I wrote which does all of the things you want to do programatically in C# in a windows application.
http://codeproject.com/csharp/CSPersonalOrganizer1.asp
Good Luck
|
|
|
|
|
I could not find any function in C# that allows to call exe files. I need some function that does the equal of Visual C 6's WinExec (strCommand, nCmdShow).
e.g. WinExec ("calc.exe", 0);
opens the windows calculator and
WinExec ("notepad.exe", 0); opens the notepad.
Some same stuff in C# ????
|
|
|
|
|
|
I found it in MSDN and ExecCommand (strCommand, strArgs);
but I do not know in which namespace they exists. The msdn page that show the description of this method does not tell the namespace requirements. If you know please do let me know.
|
|
|
|