|
Ok, it works fine
It's not the same order as the web tab, but it's better than doing no sort.
Thanks.
There is no spoon.
|
|
|
|
|
If you want the same sort as the Web tab why not create your own dictionary and enum.
The colors will be stored in the dictionary in whatever order you want and because an enum member is really an int you can use that to get the actual Color from the dictionary.
public enum WebColors
{
Transparent, Black, White,
DimGray, Gray, DarkGray, Silver, LightGray, Gainsboro, WhiteSmoke,
Maroon, DarkRed, Red
}
public class WebColorDictionary : Dictionary<int, Color>
{
public WebColorDictionary()
{
Initialize();
}
private void Initialize()
{
this.Add(0, Color.Transparent);
this.Add(1, Color.Black);
this.Add(2, Color.White);
this.Add(3, Color.DimGray);
this.Add(4, Color.Gray);
this.Add(5, Color.DarkGray);
this.Add(6, Color.Silver);
this.Add(7, Color.LightGray);
this.Add(8, Color.Gainsboro);
this.Add(9, Color.WhiteSmoke);
this.Add(10, Color.Maroon);
this.Add(11, Color.DarkRed);
this.Add(12, Color.Red);
}
}
You can now do something like this:
foreach (string s in Enum.GetNames(typeof(WebColors)))
Console.WriteLine(s);
and:
WebColorDictionary myColors = new WebColorDictionary();
BackColor = myColors[(int)WebColors.Silver];
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
This raises the question how they (i.e. Microsoft) actually sort the colours in the web tab of their colour picker. Do they just sort by RGB value? It doesn't look like it: black and white would not both be at the beginning then. Maybe it's something hard coded indeed, so if you want to exactly reproduce it you just have to hard code a list like theirs.
Or is it actually that you want the next "similar" colour? This would raise the question how to exactly define "similarity". Something like (R1-R2) + (G1-G2) + (B1-B2)? Or maybe a sqare sum?
I really don't know what the graphics experts would do there, or what the human eye regards as similar.
|
|
|
|
|
Yes, really good question. My algorithm described above, is working but the colors are not sorted the right way.
There is no spoon.
|
|
|
|
|
Hi All,
I want to know if it is possible to specify on your class properties the display width that a control must used when the property is assigned to a control or a column in the grid.
Basically I have created a custom class.
Then get data back into a List<customclass>.
This List gets assigned to a grid.
Know I would like to assign some basic display values to the property in the class and
not have to go to the grid to specify display values like width of column.
Data Example:
var query = from c in Clients
select new Client
{
Name = c.Name,
Email = c.Email
}.ToList<client>();
public class Client
{
public string Name {get; set;}
public string Email {get; set;}
}
Any ideas will be welcome!
|
|
|
|
|
you should assign a value to your properties.
private int myVar = 200;
[DefaultValue(200)]
public int MyProperty
{
get { return myVar; }
set { myVar = value; }
}
|
|
|
|
|
Thanks for the reply!
This does not help. I don't want to set a default value to the property.
I want to set the display width of the column that is assign to my property.
Or I want to set the Description that must be shown in a grid for this property
via property attributes.
Regards
|
|
|
|
|
|
Hi,
The best solution for you depends on many things such as which controls are you using, are you building your own controls, shold the display values depend on the data etc.
Few possibilities you could consider:
1. You could add properties to your class which tell the preferred size of a control that display the property. For example:
public class Client {
public string Name { get; set;}
public string Email { get; set;}
public System.Drawing.Size PreferredSizeForName {
get {
return new System.Drawing.Size(35, 13);
}
}
}
After that you can bind the size of a control to that property using advanced bindings or code
2. Use custom attributes. Derive your own attribute from System.Attribute and use reflection in your code to see what is the preferred size and then adjust your own control by that value. For example:
[System.AttributeUsage(AttributeTargets.Property)]
public class PreferredSizeAttribute : System.Attribute {
private int _width;
private int _height;
public PreferredSizeAttribute(int width, int height) {
this._width = width;
this._height = height;
}
public int Width {
get {
return this._width;
}
set {
this._width = value;
}
}
public int Height {
get {
return this._height;
}
set {
this._height = value;
}
}
public System.Drawing.Size Size {
get {
return new System.Drawing.Size(this.Width, this.Height);
}
}
}
and then usage:
public class Client {
private string name;
[PreferredSize(35, 13)]
public string Name {
get {
return name;
}
set {
name = value;
}
}
public string Email { get; set;}
}
Refer to documentation how to check the existence of an attribute and get it's values.
Hope this helps,
Mika
|
|
|
|
|
Thanks for the reply!
Just what I needed.
|
|
|
|
|
You're welcome
Mika
|
|
|
|
|
Hello,
I'm interested in writing a managed Direct3D 9/10 wrapper on my own for learning purpose.
I pretty much aware about existing MDX (which is deprecate) and XNA (which is multiplatform, but less performant). While searching for something already existing, I found a MDX 9/10/10.1 wrapper written by Ralf Kornmann http://www.codeplex.com/MD3D10[^]
This wrapper uses Managed C++ to wrap the D3D Api, but a lot of other OpenGL wrappers, uses a standard C# InterOp syntax, decorating and Marshalling.
I have concern about performance issues so my main question is: what is actually faster, wrap Direct3D with Managed C++ or in C# using standard C# InterOp ? Is there some performance issues?
What do you think?
What I mean by C# Style wrapper:
public static class DirectX
{
[DllImport("d3d9.dll", EntryPoint = "Direct3DCreate9", CallingConvention = CallingConvention.Winapi), SuppressUnmanagedCodeSecurity]
[return: MarshalAs(UnmanagedType.Interface)]
public static extern IDirect3D9 Direct3DCreate9(UInt32 SDKVersion);
}
[ComVisible(true), ComImport]
[Guid("81BDCBCA-64D4-426d-AE8D-AD0147F4275C"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IDirect3D9
{
[PreserveSig]
UInt32 GetAdapterCount();
[PreserveSig]
int GetAdapterDisplayMode(UInt32 Adapter, [In, Out] D3DDISPLAYMODE pMode);
...
}
-- Everything is possible, even the impossible! ^_^
|
|
|
|
|
Kel_ wrote: what is actually faster, wrap Direct3D with Managed C++ or in C# using standard C#
In theory, both compile to IL so there is no difference.
In practise, the compilers may produce slightly differing output.
The only way to know for certain would be to run some tests. I suspect there is no best answer for all cases, one way will be better in some circumstances, the other in different circumstances.
Simon
|
|
|
|
|
The .NET devs said that the speed difference between native DirectX and Managed DirectX was about 6%, so I suspect the difference between a managed wrapper in C++/CLI and C# won't be very large.
But as Simon said, only tests will show. But this can be a tedious task, since you have to create two wrappers with the same functionality.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thank you for the answers.
Yeah, so basically I think I'm just going to wrap the whole DirectX in C# and then test it against the managed C++ implementation.
Think it will worth a good codeproject article
-- Everything is possible, even the impossible! ^_^
|
|
|
|
|
You may also want to take a look at SlimDX - an open source wrapper intended as a replacement for Managed DirectX.
While C# is capable enough with unsafe code and interop, I'd suggest using C++/CLI if you are comfortable with it. Downside is of course more complexity.
|
|
|
|
|
Thanks again.
So basically I started the C# Wrapper to be able to compare it, after a few days and going to battle vs COM objets and performant InterOp, I finally managed to wrap a part of it.
For now I'm doing just the D3DDevice creation and a simple window clear.
I compared the exactly same function calls with Managed DirectX 1.1 ones (actually everything is the same, I compared every method parameter and call with PIX debugger).
So creating D3D factory, creating a device and showing.
(Just a first draft)
DirectX.Device.Clear(0, null, ClearFlags.D3DCLEAR_TARGET | ClearFlags.D3DCLEAR_ZBUFFER, 0, 1, 0);
DirectX.Device.BeginScene();
DirectX.Device.EndScene();
DirectX.Device.Present(null, null, IntPtr.Zero, null);
And guess what, the performance are almost exactly the same between MDX and my C# Wrapper.
I'm getting around 2180 FPS with both of them.
I still would like to check IL code generated for both.
-- Everything is possible, even the impossible! ^_^
|
|
|
|
|
hi, i m new to crystal reports.
can any one tell that
is it possible to diplay data in crystal reports on the basis of checkbox selection?
columns which i want to display in report should be displayed if that column name is checked in checkbox.Even displaying data from more than one table.
i m working in WinForms based application
|
|
|
|
|
Hi,
My win form application is using the following code to get the version number which is retrieved from the clickonce version.
This seems to work only when the application is installed on users machines.
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed) //is this a clickonce application
{
//get he publish version...
_strVersion = System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
this.Text = this.Text + " - " + _strVersion;
}
Question:
Do you know why I do not get the version number using the above code when this is used on my Dev machine where I am developing the application?
Thanks
|
|
|
|
|
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
|
Hi Friends,
I am working on access card . Its working fine. It reading when i am clicking on button. I have written the code in the button click only. I dont know in which event it reads automatically. Please tell me that in which event it will read when i touch the access card to the controller.
I want the event only. Please let me know asap.
Its RS232 micro controller.
Thanks in advance,
Vinod gupta
modified on Wednesday, July 30, 2008 8:34 AM
|
|
|
|
|
Which interface do you use ?
I was working in a barcode scanner using RS232, it's using SerialPort Class.
In that class, I can use event "DataReceived" to detect a new barcode.
|
|
|
|
|
Thanks alot for replying.
Ya its RS232 micro controller. I am not getting that in which event it will read the data when i touch the access card to the microcontroller.
Please help me out.
Thanks...
|
|
|
|
|
If you're using the SerialPort then remember to set the ReceivedBytesThreshold low enough to generate the event.
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|