|
You can't simply set StatusBar.BackColor (inheritted from Control ) like you would normally. It is not support and, hence, is hidden.
You instead must add one StatusBarPanel (you can use the designer to do this) that covers the entire StatusBar . Set the Style property to StatusBarPanelStyle.OwnerDraw and handle the StatusBar.DrawItem event.
In your event handler, you can use the StatusBarDrawItemEventArgs properties (like Graphics and Bounds properties) to fill the background.
If you read about the StatusBar.DrawItem event in the .NET Framework SDK (see http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindowsFormsStatusBarClassDrawItemTopic.asp[^]) you will find an example.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I'm facing troubles with SQLServerCE...
I've done a small application that looks like this :
- a GUI creates a thread that retrieves data from a (CAN) bus (using PInvoke etc.). This thread is written in C++ managed. Then, the thread calls static functions written in a C# project to create a database (using System.Data.SqlServerCE) and to store data into it (using datasets).
till this moment all of that works fine..
-but now my GUI has to retrieve and display data from the database that has been created by the thread..
Thus I use System.Data.SqlServerCE, make a connection like this :
SqlCeConnection connec = new SqlCeConnection("Data Source=\\Windows\\tyreDB.sdf");
then I type (the data retrieval is done in deconnected mode):
string Query = "SELECT * FROM tyreData";
SqlCeDataAdapter daCurrent = new SqlCeDataAdapter(Query, connec);
daCurrent.Fill(dsCurrent,"tyreD");
but in the last line ("Fill"), that actually does the connection, the application crashes and I get a
"Native Exception code=0xc0000005" (access violation I guess)
..I get the same thing when I try to connect to the database in the "connected mode" (i.e. when I type
connec.open() )
So what's going on? does it mean that SQLServerCE doesn't accept that 2 threads access to the same database???
please help me! Julien
|
|
|
|
|
FYI, a DataAdapter derivative like SqlCeDataAdapter will open the close the connection itself. Logically, there's no way to query for data unless it connects to the database. You should not open the connection yourself.
If you read the documentation for the SqlCeConnection class in the .NET Framework SDK, you might notice the following:Although SQL Server CE only supports one connection at a time, multiple commands can share the same connection. This means that it is possible to have multiple instances of SqlCeDataReader open on the same connection. This behavior differs from that of System.Data.SqlClient. Since you're using two assemblies, you do have the option of exposing the connection. Since both the MC++ and C# assemblies are .NET assemblies (both compiled to IL, although a mixed mode MC++ assembly may also contain native instructions), you can reference one from another. So perhaps you could expose the SqlCeConnection from the MC++ assembly and the C# assembly could use that. You could - through mutexes or some other locking mechanism - make sure that the SqlCeConnection in one assembly is closed and disposed (always call Dispose on IDisposable implementations when you're finished with them) before attempting to make another connection (perhaps using a broker or provider pattern).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
actually I've tried with only one connection but the problem is still the same.
My question is : does SQLServerCE support that 2 threads access the same database (with one shared connection) ??
|
|
|
|
|
You should read about it in the .NET Framework SDK, which is where that quote in my last reply came from (and there's more). It's very likely that it doesn't work on two separate threads but I honestly don't know off hand and in order for me to find out, I'd have to read the documentation anyway.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm trying to create a custom listbox that justifies to the bottom right of the box. Items add to the bottom list and move up but the most recent entry is always on the bottom and is always visible. I created a custom drawitemhandler that handles the right justification but setting the line.Alignment to "near" or "Far" does not have any effect on the control. Any ideas on creating a bottom aligned box or any existing code to create one?
Kam33mitch@hotmail.com
|
|
|
|
|
Use ListBox.Items.Insert(0, someObject); instead of Add , which will always add the object to the end of the collection.
Unfortunately, even if you were to extend ListBox and override CreateItemCollection , you would not be able to override Add . It is not virtual and since all references to Item refer to the actual ListBox+ObjectCollection type, your Add (if you were to hide (Shadow in VB.NET) the existing Add ) would not be called. Additionally, both ListBox+ObjectCollection.Add and ListBox+ObjectCollection.Insert call ListBox.NativeInsert , which is a private member you can't do anything about.
Perhaps not the best solution, but your only other option besides calling Insert(0, someObject) is to use another control - possibly a third-party control or one that you would write from scratch.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
OK, that makes sense if the box were already grounded to the bottom and naurally added items to the top. A regular listbox adds new items to the bottom of the control (which is good) but as the list grows larger than the control, the scroll goes top to bottom. You can scroll down to see the last entry but when you add a new one, it goes back to the top again. Picture a listbox three rows high aligned "far" to create a right alignment:
One
Two
Three
Adding a fourth item to the list should result in:
Two
Three
Four
With the ability to scroll up to see the first entry. This is what I'm trying to do. What's happening now is:
One
Two
Three
With Four below the control which requires scrolling to be visible. I'm trying to create the first scene.
Any ideas on this? Do you know of a 3rd party control that could do this?
Kam Mitchell
|
|
|
|
|
Because i want to send a bitmap object from server to client but Socket.Send method just support byte array so
is there a way to conver bitmap object to byte array and versus ?
|
|
|
|
|
System.Drawing.Image (And System.Drawing.Bitmap) implement ISerializable.
Just serialize your image using a binary serializer.
Grim (aka Toby) MCDBA, MCSD, MCP+SB
SELECT * FROM user WHERE clue IS NOT NULL
GO
(0 row(s) affected)
|
|
|
|
|
You can either serialize or save the image to a MemoryStream . Either way results in the same behavior (ISerializable.GetObjectData saves to a MemoryStream and saves the byte array).
Just using Save does save a little coding, though:
MemoryStream ms = new MemoryStream();
image.Save(ms);
byte[] arr = ms.ToArray();
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi gurus,
Can any one show me how I can add a progress bar in a status bar panel?
Best regards.
Thanks.
There is no spoon.
|
|
|
|
|
The gist of it is that you set one of the StatusBarPanel 's BorderStyle property to StatusBarPanelBorderStyle.None , its Style property to StatusBarPanelStyle.OwnerDraw , and handle the StatusBar.DrawItem event to "draw" that StatusBarPanel . What you actually end up doing is using the StatusBarDrawItemEventArgs passed to you to site (position) a ProgressBar in the area of the StatusBarPanel that you're "drawing".
A quick search on "statusbar progressbar" here on CodeProject yielded a couple good results:
http://www.codeproject.com/info/search.asp?cats=3&cats=5&cats=6&searchkw=statusbar+progressbar[^]
They're in VB.NET, but contain mostly use the BCL (for which the calls are the same for almost any managed language, and the classes/properties/methods/etc. are always the same for any managed language).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
it is not possible to put a standard progress bar in a status panel?
There is no spoon.
|
|
|
|
|
That's exactly what Gary and I told you how to do. You're siting the ProgressBar into a StatusBarPanel . There's really not a lot of difference than throwing a button on a form or something. The only real difference is that the form is the parent of the button and can (if the button sends them) receive window messages from its children. The button is still sited relative to the forum, even in non-.NET frameworks/APIs.
In .NET 2.0, IIRC, there is a more highly advanced status bar being added with a progress bar panel option. Until then, you must either site the ProgressBar into a StatusBar or handle the drawing for a particular StatusBarPanel and draw the progress yourself (it's really quite easily and involves simple math and drawing routines).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
ok, Thanks,
it works the way you said.
I added the ProgressBar in the controls collection of the StatusBar, added a dummy panel to have the progress control in second position.
There is no spoon.
|
|
|
|
|
this is one of many examples here on code project
http://www.codeproject.com/cs/miscctrl/statusbarprogresspanel.asp
Gary
"I invented the internet".
- Al Gore, former U.S. Vice President
|
|
|
|
|
it is not possible to put a standard progress bar in a status panel?
There is no spoon.
|
|
|
|
|
Try this one
Article Link[^]
Gary
"I invented the internet".
- Al Gore, former U.S. Vice President
|
|
|
|
|
i use the class symmetricalgorithm to encrypt, when use the automatically generated key and IV to encrypt the file and stored it in file and later read it from the file to construct a new symmetricalgorithm to decrypt,everyting is ok.when i use a password to generate key and later use the same password to decyrpt,althouge
the key and IV are the same ,i can't decrypt correctly ,what's worse ,an exception throwed,it's CryptographicException with a message of
System.Security.Cryptography.CryptographicException: incorrect data
at System.Security.Cryptography.CryptoAPITransform._DecryptData(IntPtr hKey,Byte[] rgb, Int32 ib, Int32 cb, Boolean fDone)
at System.Security.Cryptography.CryptoAPITransform.TransformFinalBlock(Byte[]
inputBuffer, Int32 inputOffset,Int32 inputCount)
|
|
|
|
|
It could be how you're storing data. A common error is to take the blob (a byte[] ) and write it to a text file. This won't work correctly, since text files store data differently and the bytes will be encoded incorrectly.
Either use an encoding (the common encoding is base64, for which you can use the ToBase64Transform and FromBase64Transform classes) and write the blob to a binary file (using a FileStream , as opposed to a StreamWriter or a StreamReader for example).
The exception you got is consistent with this type of problem. The cipher block or cipher text is not stored correctly and, therefore, will not decrypt when you read it in.
If this doesn't seem to be the case, please provide more information that may be helpful.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks for your help!
my encryption steps:
(1) create a symmetricalgothrim instance
(2)a.use automatically generated key and IV to encrypt data and then stored
the key and IV and cipher data(use binarywriter) to a file;
OR
b.use a password and salt value (byte[])to generate key (use PasswordDeriveBytes),and then stored the IV and salt and cipher data in file.
(3) encoding all data with base64
my decryption steps:
(1) decodeing all data with base64
(2) a.read the key and IV to decrypt
OR
b.use the same password&salt to generate the key(the key and IV are same with the previous) to decrypt
but the exception throwed when "b" is executed and everything is ok when a is executed
|
|
|
|
|
First of all, you should not store the key and cipherdata together. Where's the security in that? If nothing else, store them in a separate file (binary file if you keep the blob (byte[] array), or base64-encode it for a text file).
Second, off-hand I don't see anything wrong with your approach. Have you actually done a binary comparison of the generated key from the password and salt to see if they're the same?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
once i use the password derived key ,the exception will be throwed,the code listed below:
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); rng.GetBytes(salt); PasswordDeriveBytes pdb = new PasswordDeriveBytes(password,salt);
byte[] key = pdb.GetBytes(crypter.KeySize/8); crypter.Key = key;
i found that if commented the last sentence,
the program will be ok,but if i use the password derived bytes ,the exception will be throwed ,it is so strange that i don't understand at all~~
|
|
|
|
|
Hi,
Is it possible to make the windows application distributed using IIS. Please sewnd me some info. about the same.
Ravindra
|
|
|
|