|
Thanks for your response. but i want to save it ".evt" file.
cheers,
Abhijit
|
|
|
|
|
I don't believe the .NET Framework has native support for this, but you can try the following:
[DllImport("advapi32.dll")]
static extern IntPtr OpenEventLog(string lpUNCServerName, string lpSourceName);
[DllImport("advapi32.dll")]
static extern bool BackupEventLog(IntPtr hEventLog, string backupFile);
BackupEventLog(OpenEventLog("localhost", "Application"), @"C:\TEMP\EVENTLOG.EVT");
/F - .NET Developer
|
|
|
|
|
Thanks for your reply. I am trying to do it using WMI
cheers,
Abhijit
|
|
|
|
|
how do i set printer options? i would like to set these options
print from tray 1
pagesize 11x17
landscape
this is the code i am using
System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
pd.PrinterSettings = printDialog1.PrinterSettings;
pd.PrinterSettings.Duplex = System.Drawing.Printing.Duplex.Simplex;
pd.DocumentName = "JP Council (Title Page)";
pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.pd_PrintPage);
pd.Print();
i know it has to be something with the printersettings but just now sure how to do it
Thanks,
Chad Aiena
|
|
|
|
|
use
System.Drawing.Printing.PageSettings mySettings = new System.Drawing.Printing.PageSettings();
mySettings.PrinterSettings has everything you need.
Then apply mySettings to the System.Drawing.Printing.PrintDocument instance your using.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hi i given in my form opacity=0 and set the form shown taskbar=false...,
To avoid form visible to my enduser...,
Now the probs is,
After my form load all the operations happend the form have to auto close?,
Its possible?,
Thanks & Regards,
NeW OnE,
please don't forget to vote on the post
|
|
|
|
|
Close();
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Perhaps you don't want a Windows Application at all?
Have you considered a console application?
Either way, the user should have some indication that something happened.
|
|
|
|
|
Hi guys i created one windows application its contained only one form...,
In that form load event i said some operations have to run...,
Its working cool...,
But i dont like show the window form to enduser...,
It mean no minimize of the form also, just the form load operations have to run thats all
So i tried to hide that using this.hide(); methode in my form load event...,
But its not getting hide...,
how to hide my form window?
Thanks & Regards,
NeW OnE,
please don't forget to vote on the post
|
|
|
|
|
You can put your code in the constuctor instead of load so it runs before the loading takes place unless you need to access the form itself (or child controls) as it's handle won't be created yet so the object(s) will be unavailable.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
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.
|
|
|
|
|