|
If your only purpose is to execute a piece of code and not to show any window, you can simply delete the form and put your code in Main method.
Open Program.cs file and under main function comment out line which shows the form, and put your code. Such as –
---------------------------------
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
MessageBox.Show("Test");
}
}
---------------------
I hope this helps.
-Dave.
--------------------------------
www.componentone.com
--------------------------------
------------------------------------
http://www.componentone.com
------------------------------------
|
|
|
|
|
You could set the forms opacity to 0
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
Hello gurus,
I have a problem to solve.
I'm using a set of standard named colors. When the user selects a given color lets say Red , I'd like to know how I can select programmatically the next colors to Red , that is Brown , FireBrick , etc.
The named colors are from the panel "Web" of the color selector.
I hope my question is clear enough.
Best regards.
Fred.
There is no spoon.
|
|
|
|
|
What do you mean be "next color to red"? What kind of structure do you use, an enumeration, a .NET defined enumeration?
Your question is a bit too vague.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
When you look at the color picker, you have 3 tabs, one contains the names of the colors ("Web" tab).
When the user selects Red, I'd like to programatically go to the next color, that is Brown, FireBrick etc.
Fred.
There is no spoon.
|
|
|
|
|
Enumerations are just numbers, so you can try cast to number (int/long whatever), increment it, then cast back. You should probably add some checking to see if the next number is indeed a valid enumeration name. There are other approaches too. Look at Enum.GetValues and Enum.GetNames .
|
|
|
|
|
I've had a look and it appears there is no emumeration available for the colours or tabs. The colours themselves (the names) are each public static read only properties that return a Color rather than an enum.
<EDIT>
System.Drawing.KnownColor is an enum of course!
</EDIT>
Using reflection I can loop through the properties and get the ones that are of type Color and exclude any that are SystemColor (WindowText etc...) but the list is alphabetical and not in the order you require (same as Web tab).
I think you'll have to hardcode your own list or enum and refer to the corresponding .Net colour from there.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Extending DaveyM69's advice, here's how you could go about getting the values you need:
PropertyInfo[] PropertyInfo = typeof(Color).GetProperties();
foreach (PropertyInfo propertyElement in PropertyInfo)
{
if (propertyElement.PropertyType == typeof(Color))
{
string colourName = propertyElement.Name;
Color c = Color.FromName(colourName );
}
}
Fernando Mendes
Senior .NET Developer, Architect
|
|
|
|
|
Ok, I have it.
Thanks guys
Fred.
There is no spoon.
|
|
|
|
|
You could sort all the colors in the enumeration by RGB value, then find Red's location then grab the next color from your sorted list.
"Make everything as simple as possible, but not simpler." - Albert Einstein Jason Henderson
|
|
|
|
|
And how can you do that?
I have used the following simple algorithm:
- I get KnownColor enum values names as a string array.
- I search for the text and get the index in the value names as a start point
- in the loop that draws my curves (using ZedGraph) I go to then next index of the string array by incrementing it if the index goes too far, I switch to 0 to go to the begining of the array, I get the name of the color, convert it to its Color value
Of course, KnownColor is not ordered the same way as the "web" tab in the color picker of Visual Studio, thus, I'd like to know how it is sorted. But the colors of the curves are changing.
There is no spoon.
|
|
|
|
|
Create a List<color> of KnownColors, then sort the list by RGB value.
This may not even be close, but it does move the redish to the front and the bluish to the end:
public partial class Form1 : Form
{
private List<color> colorList = new List<color>();
public Form1()
{
InitializeComponent();
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.FillRectangle(new SolidBrush(Color.White),
new Rectangle(pictureBox1.Location, pictureBox1.Size));
int x, y;
x = 0; y = 0;
foreach (Color c in colorList)
{
e.Graphics.FillRectangle(new SolidBrush(c),
new Rectangle(x, y, 25, 25));
x += 25;
if ((x + 25) > pictureBox1.Width)
{
x = 0;
y += 25;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (KnownColor c in Enum.GetValues(typeof(KnownColor)))
{
colorList.Add(Color.FromKnownColor(c));
}
colorList.Sort(
delegate(Color x, Color y)
{
return ColorTranslator.ToWin32(x).CompareTo(ColorTranslator.ToWin32(y));
});
}
}
</color></color>
"Make everything as simple as possible, but not simpler." - Albert Einstein Jason Henderson
|
|
|
|
|
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
|
|
|
|
|