|
I am using a NET VS2003 Listview control in detail mode with icons. I set the .Enabled property to false and am geting weird display results. Only part of the control background becomes disabled gray, and the icons do not take on the disabled look- they are full color.
Is this normal behavior? Or am i doing something wrong? I was able to correct the background color problem by setting the listview .BackgroundColor to the same color as a disabled control. But the icons still show in full color.
Do i have to create my own listview control to get normal disabled behavior?
|
|
|
|
|
Since this listview is not anticipated to hold more than a few dozen items, i simply made a function that took each item icon, converted it to disable, and then put it back. Performance is very satisfactory. Below is my code. Since i had another routine that gets the icons, i did not code the conversion of disabled ==> enabled. For the in-place image converting i used code gotten from a code project article.
private void WinListEnabled(bool enabled)
{
// winlist listview
// normal disable does not color background properly
// and images maintain full color and do not gray;
// so workaround must be used;
if (enabled == true)
{
this.lvwWindowList.Enabled = true;
this.lvwWindowList.BackColor = SystemColors.Window;
this.lvwWindowList.ForeColor = SystemColors.WindowText;
LoadWinList();
}
else
{
this.lvwWindowList.Enabled = false;
this.lvwWindowList.BackColor = SystemColors.ControlLight;
this.lvwWindowList.ForeColor = SystemColors.GrayText;
for (int i = 0; i < this.lvwWindowList.Items.Count; i++)
{
// get item icon
ListViewItem listItem = this.lvwWindowList.Items[i];
Image itemIcon = this.imlWinIcons.Images[listItem.ImageIndex];
// create disabled image
Bitmap active = new Bitmap(itemIcon);
Bitmap disable = new Bitmap(active.Width, active.Height);
Graphics g = Graphics.FromImage(disable);
g.DrawImage(active, 0, 0);
ControlPaint.DrawImageDisabled(g, active, 0, 0, Color.Empty);
g.Dispose();
// replace listview image
this.imlWinIcons.Images[listItem.ImageIndex] = disable;
}
}
}
|
|
|
|
|
I have a ContextMenu and an item called Change Background, which will change the image on a PictureBox.
Here is the code:
{<br />
if (openFileDialog1.FileName.ShowDialog()==DialogResult.OK )<br />
{<br />
if (openFileDialog1.FileName != string.Empty) {<br />
this.pictureBox1.Image = new<br />
Bitmap(openFileDialog1.FileName);<br />
} }
This code was implimented on a button. I want to modify it to work on a context menu item. How would you do this? It has something to do with the DialogResult.OK code, its not a button so it wont work only crash the application.
In the end we're all just the same
|
|
|
|
|
The code would be exactly the same on a button as it would on a contect menuitem. I see no problem with the use of DialogResult , as long as you have using System.Windows.Forms; in your header.
|
|
|
|
|
The code above can't work, since the first if-line is bogus.
If you write if (openFileDialog1.ShowDialog() == DialogResult.OK) then the code will work, no matter if it's called from a button event handler or a (context)menu item handler.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
Hi,
I want to Sum data from a DataTable...
I found the code samle below, which is fine but I want to Sum a calculation if possible. Something like this:
myTable.Compute("Sum(Quantity * Price)", "EmpID = 5");
Is it possible to Sum a calculation on two columns or just Sum one column?
Thanks,
Ron
private void ComputeBySalesSalesID(DataSet myDataSet){
// Presumes a DataTable named "Orders" that has a column named "Total."
DataTable myTable;
myTable = myDataSet.Tables["Orders"];
// Declare an object variable.
object objSum;
objSum = myTable.Compute("Sum(Price)", "EmpID = 5");
}
|
|
|
|
|
Hi,
Using .net 2.0
Not sure why I do not get the .BeginEdit in the intellisense for the row
This is what I have at present
DataRow row = oDS._TRCLNT01.Rows[rowNum];
row.
Thanks
|
|
|
|
|
Hi howzit?
I have a panel which displays many different controls after certain user events...i.e. the controls are instantiated and displayed in runmode.
How do I know when one of these controls has focus? i.e. how can I create a Enter Event which relates to any control in this panel's collection, so that when a user clicks any of these run time controls, i can run code and get location and size information from this particular control?
Regards,
|
|
|
|
|
I have to determine what is control x and y global position in screen, not local position, to show up dialog on top of the control - is there normal known way to do that?
|
|
|
|
|
hi oskars!
you can use the PointToScreen method to convert the Location value into a screen coordinate value.
hope that helps!
microsoc
|
|
|
|
|
I have a tray Icon that doesn't disappear at the time of application closing.
How do I get it to disappear?
|
|
|
|
|
Normally an app icon remains when an application terminates improperly. This happens often in the VS IDE when you Stop Debugging during the program execution. If this is the case, there is no real fix. To remove "dead" icons, simply move the mouse cursor over the icons in the sys tray and Windows will update itself.
If this is not the case, you should look at whether your application is terminating properly.
|
|
|
|
|
I want to protect my class specially some methods. I have do some steps:
1. Create a library project using C# named "protected"
2. Use sn.exe to create new strong name. Named key.snk
3. Use sn -p key.snk key.publickey to get the public key and token hexcode.
4. Use sn -tp key.publickey to view the public key of snk file.
5. Create class and method that will be protected. The code are :
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Permissions;
using System.Security;
using System.Reflection;
namespace Protecting
{
[StrongNameIdentityPermissionAttribute(SecurityAction.Deny, PublicKey = "00240000048000009400000006020000002400005253413100040000010001004B1C3C045DC354" +
"E3284168F3664C5447649A3F2969AFC60D52F9C65BA6DC95A5F3A5EC673F47999D99F6EE7B632CB9" +
"B7DA1E56FF6DFB3944A267D6E7D4F2E4BDAF294EEDC960CD9A4C22D358922FF5E92838C3439A0F83" +
"40C003F6E4D43AD1FAEF5E6A80D31D02C50EAB3D845F384E7CE8CBE5FDA4E9154223A4FF50424F7D" +
"B5")]
public class Class1 // <-This is protected class.
{
[StrongNameIdentityPermissionAttribute(SecurityAction.Deny, PublicKey = "00240000048000009400000006020000002400005253413100040000010001004B1C3C045DC354" +
"E3284168F3664C5447649A3F2969AFC60D52F9C65BA6DC95A5F3A5EC673F47999D99F6EE7B632CB9" +
"B7DA1E56FF6DFB3944A267D6E7D4F2E4BDAF294EEDC960CD9A4C22D358922FF5E92838C3439A0F83" +
"40C003F6E4D43AD1FAEF5E6A80D31D02C50EAB3D845F384E7CE8CBE5FDA4E9154223A4FF50424F7D" +
"B5")]
public void WhoSaid(string Name) // <- This is protected method.
{
Console.WriteLine(Name + " say Hello World");
}
}
}
6. I also add the snk file to the project propertied at signing tab.
7. Build the library.
8. View the library using secutil to check if assembly have been signed. And the result is same.
By the code we can know the theory that any application that want to access this class even have been signed with the same key will not grant access to use this class and method.
For testing I use console application, with steps:
1. Create a console project using C#.
2. Reference to the "protected.dll" that been created.
3. Write code that execute protected method on protected.dll
using System;
using System.Collections.Generic;
using System.Text;
namespace Call_protected
{
class Program
{
static void Main(string[] args)
{
Protecting.Class1 a = new Protecting.Class1();
a.WhoSaid("Ariston");
Console.ReadKey();
}
}
}
4. Build the application.
5. Run it.
6. Whoala it still can execute the protected methods on library. The console will display:
Ariston say Hello World
I use VS 2005 to build both and use Framework 2.0. So what wrong with my code, I don't have any ways to resolve this problem.
PS: The tester console application is not signed by any strong name key.
Thanks.
Simple mind programmers, I don't need a complicated mind.
-- modified at 21:16 Sunday 26th February, 2006
|
|
|
|
|
Hi!
I think you should not use SecurityAction.Deny for your class and method but SecurityAction.LinkDemand .
That way, only the direct caller has to satisfy the strong name identity with the given public key, but callers further up the line don't have to.
If you use SecurityAction.Demand , then you'll always get a SecurityException because mscorlib (which is the top-most caller in the end) doesn't have the required strong name identity.
Hope this helps...
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
Well I have change the SecurityAction into SecurityAction.LinkDemand but still the console application that I use to test can access the class and the method. At application console I didn't set any Strong Name Key. So the theory is that the console application doesn't have any Strong Name Key (not the same key too) will caught an exception while access the library class that have been set a public key. Its that right or not. Because I want to protect my library that contains class and methods so that only I can use the class not the other people that want to reference my assembly.
Do you know how to solve this ?
PS: Can do this at Debug Mode for building the library ?
Thanks.
Simple mind programmers, I don't need a complicated mind.
|
|
|
|
|
I created a test solution with VS2003/.NET 1.1 to experiment with the attributes and get exactly the same behavior with an Windows Forms application and a console application.
When I specify LinkDemand as action, then every caller that's not signed or does not expose the given public key will throw a security exception when trying to access the protected class.
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
Well it seem that everyone that use VS 2003 and FW 1.1 always success. But I don't close the conversation only for VS 2003.
Well if you have any solution or links to protect the assembly over FW 2.0 please tell me. I don't want to go back into VS 2003 because many of my jobs writen over VS 2005.
Thanks for you support.
Happy coding, ya..
Simple mind programmers, I don't need a complicated mind.
|
|
|
|
|
Ok, it seems to be an issue with .NET 2.0 indeed.
I've converted the VS 2003 test solution to VS 2005 and tried again. I could reproduce the failure to check the StringNameIdentityPermissionAttribute with .NET 2.0 - the very same application that threw a SecurityException with 1.1 ran without problems in 2.0!
I think it's time to contact MS...
Regards,
mav
--
Black holes are the places where god divided by 0...
-- modified at 12:57 Tuesday 28th February, 2006
I just found some additional information that might be of interest:
In the microsoft.public.dotnet.security newsgroup I found a statement that in .NET 2.0 fully trusted code will automatically bypass all identity permission demands.
Heaven knows why this decision has been made, but this seems to explain the behaviour.
-- modified at 13:12 Tuesday 28th February, 2006
And another piece of wisdom from Eugene Bobukh:
http://blogs.msdn.com/eugene_bobukh/archive/2005/05/06/415217.aspx[^]
|
|
|
|
|
I'm writing some C++ code that I'd like to prepare for simple interop. To make things as easy as possible on the .NET side of things, how should I declare a C++ function that:
1. takes an array as a parameter? Is int* ok?
2. returns a UTF8 string. Is LPSTR ok? Should I use an output parameter instead of a return value?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Connor's Christmas Spectacular!
Judah Himango
|
|
|
|
|
How do you intend to interop it, managed C++ or COM ? If managed C++, you'll end up writing methods that take .NET types anyhow.
I guess there is also pinvoke.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Yeah I was planning PInvoke simply because there is an existing codebase (I'm trying to port some Java JNI code into the .NET world). I considered using C++/CLI to make it simpler, and may end up going that way, but for now I've just declared the methods as described in my first post.
So any thoughts on how to define a C method that takes an int[] and returns a string so that it can be used easily from a .NET language?
|
|
|
|
|
Judah Himango wrote: 1. takes an array as a parameter? Is int* ok?
Yes.
Judah Himango wrote: 2. returns a UTF8 string. Is LPSTR ok? Should I use an output parameter instead of a return value?
It is ok, as long as the calling application doesn't have to free or delete the memory.
I don't see dead pixels anymore...
Yes, even I am blogging now!
|
|
|
|
|
Thanks Daniel. The calling app would have to free the memory, so I think what I'll do instead is have the method take a 2nd LPSTR parameter which will be the output. That way I can feed in a StringBuilder and have it work without issue.
|
|
|
|
|
Will an event be raised when all the controls in a form has been drawn?
I have a form with many buttons with BGpics in it. Can I set the form to invisible, let it load all the pic, and then show it instead of it showing it and loading the pic at the same time (this makes it look really laggy)
|
|
|
|
|
If a control is not visible, and its background image is changed, will the image actually change? or will it only change only when it becomes visible?
|
|
|
|