|
Andrey_Mark wrote: But I can't find any method to set system time.
Probably because the designers of the .NET Framework didn't think it would be useful. Setting the System time is an Administrator function (if I remember correctly) and many people now syncronise their PCs with an atomic clock over the internet or it is set via a central server in the enterprise.
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
I use following solution in this case:
public struct SYSTEMTIME {<br />
public short wYear;<br />
public short wMonth;<br />
public short wDayOfWeek;<br />
public short wDay;<br />
public short wHour;<br />
public short wMinute;<br />
public short wSecond;<br />
public short wMilliseconds;<br />
};<br />
<br />
public sealed class SetSystemTimeUnsafe<br />
{<br />
<br />
[DllImport("kernel32", SetLastError = false)]<br />
private static extern unsafe bool SetSystemTime(SYSTEMTIME* st);<br />
<br />
public static void Set(DateTime dt)<br />
{<br />
unsafe<br />
{<br />
SYSTEMTIME st;<br />
st.wDay = (short)dt.Day;<br />
st.wDayOfWeek = 0;<br />
st.wHour = (short)dt.Hour;<br />
st.wMilliseconds = (short)dt.Millisecond;<br />
st.wMinute = (short)dt.Minute;<br />
st.wMonth = (short)dt.Month;<br />
st.wSecond = (short)dt.Second;<br />
st.wYear = (short)dt.Year;<br />
SetSystemTime(&st);<br />
}<br />
}<br />
<br />
}
- - -
|
|
|
|
|
Hello. Can you tell me how can I make my C# application interact with other C# or win32 applications. Thank you. I want for example to be able to get the data from a notepad or a cmd window. Thank you.
|
|
|
|
|
The other application has to be designed for such interaction. You can force interaction, but there is no consitent way to do that because you have to trick the application into interacting with your application.
There are ways of getting properties of windows (e.g. controls), for example, the Text property of the TextBox control that Notepad (I assume) is using. However, it has been a few years since I did any C++ and I don't enough to be able to work out how it might be done any more.
The Command window might be easier to deal with as the application is just interacting with StdIn, StdOut and StdErr and these can be redirected. See the System.Diagnostics.Process[^] class
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
I was thinking of something in Diagnostics.Process thanks
|
|
|
|
|
Hello,
I am stuck with an error: An object reference is required for the nonstatic field, method, or property
the code that is causing the problem:
-class Form1
private static DiscoveryProcess DPform;
public static bool DiscoveryProcessInstance = false;
public static void DiscoveryProcess()
{
if (DiscoveryProcessInstance == false)
{
DPform = new DiscoveryProcess();
DPform.Show();
DiscoveryProcessInstance = true;
-ERROR- toolStripStatusLabel1.Visible = true; // System.Windows.Forms.ToolStripStatusLabel
}
else
DPform.WindowState = FormWindowState.Normal;
}
situation:
Form1 is the mainform, from there I start a new Windows form, Form2. When the operation are done on that Form2, I call the following code to start another Windows form DPform
-class Form2
Form1.DiscoveryProcess(); //starts DPform
this.Close(); // closes Form2
Now what I want to accomplish with that is that i can close the form Form2 (I don't need it anymore) without closing DPform and that only one single window form can be created. But what i want to do is set a toolStripStatusLabel on Form1 to visible.
Can someone point me into a direction of how to manipulate the toolStripStatusLabel on another form? Or is my approach of calling new window forms from Form1 not correct?
Thanks in advance.
-- modified at 8:06 Sunday 18th December, 2005
|
|
|
|
|
Did you try running the code under a debugger? Assuming you're using VS .NET, hit F5 and then try the operation that caused the exception. The debugger should point you to the exact line that resulted in the problem.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Sorry, something missed out:
the error occures on this line:
toolStripStatusLabel1.Visible = true; // System.Windows.Forms.ToolStripStatusLabel
|
|
|
|
|
It simply means that toolStripStatusLabel1 is not static, while the function DiscoveryProcess is. You need to declare the Label also as a static member.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
How can I do that? Can you help me out with this?
Thanks
|
|
|
|
|
I guess you're new to C# programming? The static[^] keyword is used to indicate that a member variable belongs to the type itself, rather than to every instance of the type.
In your case, you'd need to change
Label toolStripStatusLabel1;
to
static Label toolStripStatusLabel1;
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
That is correct, but the problem that I have is this.
I make a new clean static ToolStripStatusLabel.
public static System.Windows.Forms.ToolStripStatusLabel testLabel;
This new ToolStripStatusLabel must be added to the
System.Windows.Forms.StatusStrip statusStrip1;
So I do
try
{
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { testLabel });
}
catch (Exception) // needed to catch the System.ArgumentNullException
{ }
Than when I change the section that gave the error to:
public static void DiscoveryProcess()
{
if (DiscoveryProcessInstance == false)
{
DPform = new DiscoveryProcess();
DPform.Show();
DiscoveryProcessInstance = true;
//statusDiscoveryProcess.Visible = true;
testLabel.Image = global::RDXstudio.Properties.Resources.Processor;
testLabel.Name = "statusDiscoveryProcess";
testLabel.Size = new System.Drawing.Size(161, 16);
testLabel.Text = "Discovery Process running...";
testLabel.Visible = true;
}
else
DPform.WindowState = FormWindowState.Normal;
}
It still causes the application to crash with a System.NullReferenceException
I think I am not able to do that.
Is there another way of calling my forms without the static?
Form1 calls Form2, Form2 calls DPform and Form2 close itself, DPform continue...
Thanks in advance.
|
|
|
|
|
You really need to pick up the basics of C# first. The statement
public static System.Windows.Forms.ToolStripStatusLabel testLabel;
does not create a ToolStripStatusLabel object. You have to do
public static System.Windows.Forms.ToolStripStatusLabel testLabel = new System.Windows.Forms.ToolStripStatusLabel();
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Great man!
I think that I am terrible confused out here. That did the trick.
|
|
|
|
|
He can't run the code, as it's a compiler error message.
---
b { font-weight: normal; }
|
|
|
|
|
You're right, , I read "object reference" and immediately decided the OP got a NullReferenceException.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
You can't access the controls of the form wihtout a reference to the form object.
---
b { font-weight: normal; }
|
|
|
|
|
Hi.
I want to make a setup for my application that automatically and in background installs .Net Framework 2 with my application.
Can you help me, please?
Best wishes
|
|
|
|
|
How i can convert user define structure into byte array,or tell me how can i send struct through socket?
|
|
|
|
|
Use Binary Serilazation.
The only trick here is that the "other side" needs to know the class\struct structure (both must use the same dll describing the class\struct).
there is a good example on the MSDN help.
Gilad.
|
|
|
|
|
Make your structures as Serializable.
[Serializable]
struct Person
{
public string name;
public int age;
};
Use binary serialization/deserialization to convert your structures to byte array and vise versa
DevIntelligence.com - My blog for .Net Developers
|
|
|
|
|
Hi,
Can someone simply explain the usage and benefit of delegate with a simple example please?
Thanks
|
|
|
|
|
|
My program is about image processing for vets. We added the ability to send email using the built in .NET stuff, and the biggest client complaint is that they don't know if it sent or not, as it's not in their outbox. What I want to do is send the mail, by whatever means I don't care, and then if Outlook is present on the machine, stuff the message into the outbox, if it's not present, look for Outlook Express and do the same. What I don't want is to be tied to any version of Outlook, I want it to work for any version, and not require any version to be installed. I've looked through MSDN, but found nothing of value. I appreciate any suggestions.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I guess it would be tough to do it from managed code, as you'd need the interop DLLs for interacting with the outlook COM objects and I don't know of interop DLLs for one version of Outlook will work with another.
How about writing a MC++ library that directly uses COM to do the job? That way, you can easily check for the CLSIDs and create the right COM objects.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|