|
|
Don't know if anyone is interested in readin this, but I found the problem myself.
I did not realize that C structs are aligned to be a multiple of 4 bytes (32 bits, of course).
That's why I have to use 1464 in stead of 1462 bytes for my array.
Pretty stupid isn't it!
Gino
"D'Oh!" (Homer J. Simpson)
|
|
|
|
|
Hi.
I have a datagrid on my form that has the datasource set to a datatable in a class in different project but same solution. When I change the data in the datatable, the datagrid is very long to get the changes (~2 seconds) which is not great. I use a bit complicated architechture, but it should not matter. Here's roughly what i do:
_____
ClassState:
DataTable MyData = new DataTable();
(Fill in dummy data)
_____
ClassForm:
MyGrid.DataSource = ClassState.MyData;
ClassEvents.MyGetData();
_____ -->
ClassEvents:
DataTable temp = MyWebService.GetData();
classState.MyData.BeginLoadData();
Foreach(datarow dr in temp)
{
classState.MyData.ImportRow(dr);
}
classState.MyData.EndLoadData();
//From here and until the datagrid is updated it takes ~2 seconds. WHY??
____________
I timed and logged every line in my code and found out that it is the datagrid that i slow on getting the updates (or the datatable that is slow sending update notifications). It has nothing to do with getting data from the webservice.
Is there some way to tell the datatable to send notifications NOW??
Or could it have something to do with the fact that ClassState, ClassForm and Class events each is in it's own project (but same solution)?
Or do you have any other ideas?
|
|
|
|
|
We can show the text with DrawString,but I cannot get width & height of the text,though I need them.
Can you help me?Thanks
Future belongs to C#!
|
|
|
|
|
use the Graphics.MeasureString method.
To those who didn't make it, we will remember you. To those who did is back. - Megan Forbes in Black FridayAnother Post by NnamdiOnyeyiri
|
|
|
|
|
|
Get it here[^], but remember, it can only be used in non-commercial apps. Get it quick, because rumors are that it may be gone soon.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
|
Help?
I modified some code from an MSDN sample to try to use the RijndaelManaged object to encrypt a byte array(an uploaded file from a browser) and stuff it into an image field in SQLServer. Seems like an easy task, right?
The files are definitley scrambled. Just can't seem to un-scramble 'em. I created an Encrypt and a Decrypt function, both of which accept a byte array and return a byte array. The key and IV are hard coded at this point.
I've been through the step of encrypting and decrypting at the same time, to see if the un-encrypted file makes it into the database....no love. It's hammered.
Somethin' ain't right. Here's the code for the functions:
<br />
public byte[] EncryptStream(byte[] input)<br />
{<br />
RijndaelManaged rijn = new RijndaelManaged(); <br />
byte[] encrypted; <br />
byte[] key = new byte[]{0x22,0xc0,0x6d,0xcb,0x23,0xa6,0x3,0x1b,0x5a,0x1d,0xd3,<br />
0x9f,0x85,0xd,0xc1,0x72,0xed,0xf4,0x54,0xe6,0xba,0x65,<br />
0xc,0x22,0x62,0xbe,0xf3,0xec,0x14,0x81,0xa8,0xa};
byte[] IV = new byte[]{0x43,0xb1,0x93,0xb,0x1a,0x87,0x52,0x62,0xfb,0x8,0xd,0xc0,<br />
0xca,0x40,0xc2,0xdb};
<br />
ICryptoTransform encryptor = rijn.CreateEncryptor(key, IV);<br />
<br />
MemoryStream msEncrypt = new MemoryStream();<br />
CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);<br />
<br />
<br />
csEncrypt.Write(input, 0, input.Length);<br />
csEncrypt.FlushFinalBlock();<br />
<br />
encrypted = msEncrypt.ToArray(); <br />
<br />
return encrypted;<br />
<br />
}<br />
<br />
public byte[] DecryptStream(byte[] input)<br />
{<br />
RijndaelManaged rijn = new RijndaelManaged(); <br />
byte[] decrypted; <br />
byte[] key = new byte[]{0x22,0xc0,0x6d,0xcb,0x23,0xa6,0x3,0x1b,0x5a,0x1d,0xd3,<br />
0x9f,0x85,0xd,0xc1,0x72,0xed,0xf4,0x54,0xe6,0xba,0x65,<br />
0xc,0x22,0x62,0xbe,0xf3,0xec,0x14,0x81,0xa8,0xa};
byte[] IV = new byte[]{0x43,0xb1,0x93,0xb,0x1a,0x87,0x52,0x62,0xfb,0x8,0xd,0xc0,<br />
0xca,0x40,0xc2,0xdb};
<br />
<br />
<br />
ICryptoTransform decryptor = rijn.CreateDecryptor(key, IV);<br />
<br />
MemoryStream msDecrypt = new MemoryStream(input);<br />
CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read);<br />
<br />
decrypted = new byte[input.Length];<br />
<br />
csDecrypt.Read(decrypted, 0, decrypted.Length);<br />
<br />
return decrypted;<br />
}<br />
Thanks-
chlock
|
|
|
|
|
I'm just guessing here, one thing that comes to my mind now is the key and the initialization vector that may have some wrong values, as you've declared them as hardcoded arrays. Just to eliminate this doubt, try using the rijn.GenerateKey() and rijn.GenerateIV.
I hope that you have money because it’s necessary to be practical.
And I hope that at least once a year you put some money in front of you and say "you are mine" just to make clear who owns who. - Victor Hugo
|
|
|
|
|
OK-
I haven't taken the time to comb through the code and find what I was doing wrong. With all the arrays flying around, I suspect I just used the wrong variable somewhere.
The following code works. So it's there for anybody who wants a simple method for encrypting/decrypting byte arrays. It's hard to find examples that aren't written for the writing-an-encrypted-file-to-disk crowd.
Bear in mind that hard coding the key and IV theoretically leaves you open to some hacker reverse engineering your code and being able to easily decrypt your files. But my personal feeling on this matter is that it's infinitely more likely that a user will compromise security by leaving their password on a sticky note stuck to their monitor. And I'm not securing highly sensitive material anyway. If you have a need for greater security, use some other method for generating and keeping track of your keys and IV's.
<br />
public byte[] EncryptStream(byte[] input)<br />
{<br />
RijndaelManaged rijn = new RijndaelManaged(); <br />
byte[] encrypted; <br />
<br />
byte[] key = new byte[]{0x22,0xc0,0x6d,0xcb,0x23,0xa6,0x3,0x1b,0x5a,0x1d,0xd3,<br />
0x9f,0x85,0xd,0xc1,0x72,0xed,0xf4,0x54,0xe6,0xba,0x65,<br />
0xc,0x22,0x62,0xbe,0xf3,0xec,0x14,0x81,0xa8,0xa};
byte[] IV = new byte[]{0x43,0xb1,0x93,0xb,0x1a,0x87,0x52,0x62,0xfb,0x8,0xd,0xc0,<br />
0xca,0x40,0xc2,0xdb};
<br />
ICryptoTransform encryptor = rijn.CreateEncryptor(key, IV);<br />
<br />
MemoryStream msEncrypt = new MemoryStream();<br />
CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);<br />
<br />
<br />
csEncrypt.Write(input, 0, input.Length);<br />
csEncrypt.FlushFinalBlock();<br />
csEncrypt.Close();<br />
<br />
encrypted = msEncrypt.ToArray(); <br />
<br />
return encrypted;<br />
<br />
}<br />
<br />
public byte[] DecryptStream(byte[] encrypted)<br />
{<br />
RijndaelManaged myRijndael = new RijndaelManaged(); <br />
byte[] fromEncrypt; <br />
byte[] key = new byte[]{0x22,0xc0,0x6d,0xcb,0x23,0xa6,0x3,0x1b,0x5a,0x1d,0xd3,<br />
0x9f,0x85,0xd,0xc1,0x72,0xed,0xf4,0x54,0xe6,0xba,0x65,<br />
0xc,0x22,0x62,0xbe,0xf3,0xec,0x14,0x81,0xa8,0xa};
byte[] IV = new byte[]{0x43,0xb1,0x93,0xb,0x1a,0x87,0x52,0x62,0xfb,0x8,0xd,0xc0,<br />
0xca,0x40,0xc2,0xdb};
<br />
<br />
<br />
ICryptoTransform decryptor = myRijndael.CreateDecryptor(key, IV);<br />
<br />
MemoryStream msDecrypt = new MemoryStream(encrypted);<br />
CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read);<br />
<br />
fromEncrypt = new byte[encrypted.Length];<br />
<br />
csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);<br />
<br />
return fromEncrypt;<br />
}<br />
enjoy-
chlock
|
|
|
|
|
Hi,
I have a tool bar in my app, from which the user can drag components on to the a form. This works fine except that after dragging a control from the toolbar, once the mouse leaves the tool bar area the corresponding button remains in pressed state and will not become normal until the mouse is brought back on the tool bar. I want the button to become normal as soon as the mouse is release(on the form or elsewhere!)
Any ideas?
Thanks
|
|
|
|
|
I'll ask the obvious... Check if the button type is a toggle sytle.
-------------------------------
Joan
MomComputerGeek.com
|
|
|
|
|
This happens even with button style being set to either toggle or pushbutton
|
|
|
|
|
I have a C# Windows form app with its own installer... I'd like the installer to create several empty subfolders below the install dir that will hold data that will be created by the app... how can this be done...??
thanks,
vince
|
|
|
|
|
Why not just have the app check if the folder exists upon startup and create it if it does not exist? That way, users can delete the folders, and the application will not break.
|
|
|
|
|
thanks for the reply... as it turns out, that's exactly what I ended up doing
|
|
|
|
|
hello
i starting learning a c# and i am in my first step.
i find an exemple who talk about spliting a windows and i tryed to exucute but i acount a problem the sample don't work and i have many error .
i want to know the step to do to creat a project for this sample.
<br />
using System;<br />
using System.Drawing;<br />
using System.Windows.Forms;<br />
<br />
<br />
<br />
public class UnPanelUnSplitter : Form<br />
{<br />
private Splitter splitter1;<br />
private Panel panel1;<br />
<br />
<br />
public UnPanelUnSplitter()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
<br />
private void InitializeComponent()<br />
{<br />
this.splitter1 = new Splitter();<br />
this.panel1 = new Panel();<br />
this.SuspendLayout();<br />
this.splitter1.Dock = System.Windows.Forms.DockStyle.Left;<br />
this.panel1.BackColor = System.Drawing.Color.Yellow;<br />
this.panel1.Dock = System.Windows.Forms.DockStyle.Left;<br />
this.panel1.Resize += new EventHandler(PanelOnResize);<br />
this.panel1.Paint += new PaintEventHandler(PanelOnPaint);<br />
this.BackColor = System.Drawing.Color.Red;<br />
this.ClientSize = new System.Drawing.Size(319, 322);<br />
this.Controls.AddRange(new System.Windows.Forms.Control[] {<br />
this.splitter1,<br />
this.panel1});<br />
this.Text = "Un panel avec un splitter";<br />
this.ResumeLayout(false);<br />
this.Resize += new EventHandler(PanelOnResize);<br />
this.Paint += new PaintEventHandler(PanelOnPaint);<br />
<br />
}<br />
<br />
<br />
<br />
static void Main() <br />
{<br />
Application.Run(new UnPanelUnSplitter());<br />
}<br />
<br />
<br />
<br />
<br />
void PanelOnResize(object o, EventArgs e)<br />
{<br />
Control control = (Control)o;<br />
control.Invalidate(); <br />
}<br />
<br />
<br />
void PanelOnPaint(object o, PaintEventArgs args)<br />
{<br />
Control panel = (Control)o;<br />
Graphics grfx = args.Graphics;<br />
grfx.DrawLine(Pens.Black, 0, 0, panel.Width-1, panel.Height-1);<br />
grfx.DrawLine(Pens.Black, panel.Width-1, 0, 0, panel.Height-1);<br />
grfx.DrawEllipse(Pens.Black, 0, 0, panel.Width-1, panel.Height-1);<br />
}<br />
}<br />
|
|
|
|
|
hi !
i tried this little sample and it worked fine. (apart from the fakt that it doesn't look very pretty)
A)
start your editor
paste the code
save it as "split.cs"
compile at "VisualStudio .Net 2003 COMMAND PROMPT" with "csc split.cs"
run it: split.exe
-- or --
B)
make a new c# project. -> windows application
replace the code of Form1.cs with your code. run it.
if you have still errors, please post them.
|
|
|
|
|
>hello
>sorry,but it don't work and i guess that is from because i am newbies.
>when i select Form1.cs it appear a ressource but i don't see when i can put my code,and when i click on the form it send me to a code and when i put the code it don't work.
>please,can u explain me with detail how to add the code and when i find Form1.cs .
>thank u,and sorry for any distruption
--
there must be a "form1.cs" in your solution explorer (right sided). just right-click and select "view code"
now you see the whole code of this form (actually the whole code of the entire project/solution)
delete that code completely.
and paste your code instead.
now "form1.cs" is just your code.
thats it.
start the whole thing. it should work.
good luck.
andi
|
|
|
|
|
Hi
I´m trying to install Roman Kiss-WSE-DIME-project at
http://www.codeproject.com/cs/webservices/remotingdime.asp
But I keep on getting the error
"Remoting configuration failed with the exception System.IO.FileLoadException: The located assembly's manifest definition with name 'WSDimeChannel' does not match the assembly reference."
when I testdrive the WindowsClient.
I have done everything that the instruction says. Including draging the 3 dll to the %windows%/assembly - folder.
Running the WebService and trying the echo-method works fine. I may have some errors in the machine.config-file. Can this be of importance (several names with the same ID") Is there something I have forgot when I install the project?
What can be wrong?
Regards
Daniel
|
|
|
|
|
is it possible to wrap text in a cell of a datagrid?
if so .. is it possible to make the row height change depending on how much text is in that cell?
|
|
|
|
|
put a textbox inside.
the rowheight property changes all the rows
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
I'm finishing up development of a network file backup
application consisting of a C# Windows form app and a
windows service.
Both the form app and the windows service exist in
seperate solutions, and each one is built with its own
installer. Works fine.
I'd like to be able to deploy both components together in
a single installer, but I'm not sure about the best way
to go about it...
I was thinking about adding an installer project for the
service to the form project, or possibly combining the two
solutions somehow, but I'm really just shooting in the dark
at this point... I'm probably making this a lot harder than
it really is..
Would appreciate any suggestions or resources for
packaging both solutions into one installer...
thanks,
vince
..
.
|
|
|
|
|
Hi,
Can anyone tell me if a [VB.NET to C#] source code converter utility available on the internet.
clr.
|
|
|
|
|