|
How can I obtain the local IP address in C#?
Thanks much to anyone that can help me!!
|
|
|
|
|
|
I am having problems getting a simple timer to work. I am very new to C#. When I go to compile the code below I get the following error:
An object reference is required for the nonstatic field, method, or property 'TimerTest.mStartTime'
Anyone got any ideas ?
using System;
using System.IO;
using System.Timers;
class TimerTest
{
public DateTime mStartTime;
public static void Main()
{
Timer tmr = new Timer();
tmr.Tick += new EventHandler(OnTimedEvent);
tmr.Interval= 1000;
DateTime mStartTime = DateTime.Now;
Console.WriteLine("Timer test running...");
tmr.Enabled = true;
while(true)
{
}
}
public static void OnTimedEvent(object source, EventArgs e)
{
String timestring;
DateTime now = DateTime.Now;
TimeSpan diff = now.Subtract(mStartTime);
timestring = (diff.Hours.ToString("d2" + ":" + diff.Minutes.ToString("d2") + ":" +
diff.Seconds.ToString("d2"));
Console.WriteLine("{0}",timestring);
}
}
|
|
|
|
|
B. Wood wrote:
public DateTime mStartTime;
public static DateTime mStartTime;
Since your methods are static, the data it accesses must be static, or have a reference to an instance of the class.
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
Thanks James, that did the trick.
|
|
|
|
|
Hi,
is there a possibility to call functions from a DLL written with C# from managed/unmanaged c++ code?
I know it is very simple to create a C#DLL and then use the function in a C# Project with adding a reference. This is really great and simple.
But...
I have a very big project written with VC++6.0. I solved all problems after converting it to VC++7.0. But now I want to use the big, great new features like ADO.NET to connect to a SQL-Server. So I thought to write some C#DLLs with all the functions I need and then call these functions from C++. How can I do this?
I tried several things.
1.) Is it possible to add a reference to a C#Dll from C++ ? I can't see a posibility...
2.) The old common way with LoadLibary is not possible, because I can't declare my function in the Dll as a dllexport function, and because of this GetProcAdress returns zero.
So how can I declare my function for external use ?
Any ideas??
Thanks for help.
|
|
|
|
|
The easiest thing to do would be to wrap your C# dll with COM (C# classes can be exposed as COM objects), then you can use COM to call into your C# dll...
In MC++ you might be able to #using your dll like you would the system dlls.
HTH,
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
The easiest way is to write an unmanaged C++ library that exports the functions you want. It then contains managed C++ that calls your C# classes directly. This gives you the best of both worlds, but requires two files. One for C++ and one cor C#.
|
|
|
|
|
ohhh! I forgot about that
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
Hello everybody,
Does anyone know how to trap the arrow keys in a class derived from usercontrol?
I noticed that the arrows keys don't fire a keyup, keydown or keypress event,
instead they move the focus to other controls on the form like the Tab key does.
I want the control itself to be able to process the arrows keys without having to add code to the form that is it in.
Thanks in advance
Paul
|
|
|
|
|
Look at the IsInputKey protected method on the usercontrol.
protected override bool IsInputKey(Keys keyData)
{
this control,
if (keyData == Keys.Left ||
keyData == Keys.Right ||
keyData == Keys.Up ||
keyData == Keys.Down)
return true;
else
return base.IsInputKey(keyData);
} Then I think the OnKey* events will fire for it, the docs aren't too clear on that aspect.
Your control will have to have the UIPermission.AllWindows security permission to run that code however.
HTH,
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
Hi everyone,
I have a web forms page, which contains a dropdownlist. The dropdownlist posts back to an event handler which adds a new button to the controls collection of a PlaceHolder. The text property of this button is set to the text of the DropDownList's selected item. My problem is that after the first time I select my dropdownlist, it changes the text of the existing button in the PlaceHolder, as apposed to adding a new Button to the placeholder.
How can I do that?
I very much appreciate any help I can get this on this.
Thanks.
|
|
|
|
|
Try searching the DOTNET mailing list archives; here is one post that might help a little bit, though I could have sworn I've seen more similar to what you're trying to find.
Sorry I can't be of more help,
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
I need implement a singleton in C#. I have tried making a static class but I seem to be getting members that go out of scope. What is the best was to do this? Thanks.
Steve
|
|
|
|
|
|
Here is a really good article on the Singleton Design Pattern.
Is show it in C++ and then the code convert as is to C# and then a better way of doing it in C# that takes advantage of the language. The C# way is easier. Take a look at the URL
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/singletondespatt.asp
Odis Wooten
odis@msn.com
|
|
|
|
|
Can anyone tell me how i get the controls on my C# form to display in an XP style, when the form is running on XP?
Any ideas welcome!
kenbloke
|
|
|
|
|
When you run your application on XP it display in XP style,even it is C#,VC or VB programs.Maybe you change your Appearence to classic style in control panel
Mazy
You can find a solution (even a foolish one) for all problems (even big ones)
|
|
|
|
|
To clarify. XP style in terms of displaying the controls in the updated XP style as defined by XP's Common Control library and XP's current theme setting.
I'm new to C# and does not appear to be obvious how to achieve this. Or have i missed something?
Kenbloke
|
|
|
|
|
I don't get what you really want(sorry for my poor english ),but according to my knowledge it is something refer to your windows not your programming language
Mazy
You can find a solution (even a foolish one) for all problems (even big ones)
|
|
|
|
|
In order to enable the XP Style controls you need to include a manifest either as a resource or as a separate file.
The manifest is nothing more than an xml document
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly
xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<assemblyIdentity
processorArchitecture="x86"
version="5.1.0.0"
type="win32"
name="myapp.exe"/>
<description>your application description</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
publicKeyToken="6595b64144ccf1df"
language="*"
processorArchitecture="x86"/>
</dependentAssembly>
</dependency>
</assembly>
(manifest taken from Colin's VMTU since I can't find mine here)
If the manifest is included as a separate file (the easiest way to do it), it should be named myapp.exe.manifest
I can't remember the steps off hand for putting the manifest in the resource, i think resgenx was the command that was used to generate the resource, then you include the resource with the compiler.
HTH,
James
Sonork ID: 100.11138 - Hasaki
<small>"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002</small>
|
|
|
|
|
And as Mazdak said, set the Appearance property to standard
James
Sonork ID: 100.11138 - Hasaki
"Not be to confused with 'The VD Project'. Which would be a very bad pr0n flick. " - Michael P Butler Jan. 18, 2002
|
|
|
|
|
Thanks for that info James and Mazdak!!! pointed me in the right direction.
Anyway for anyone who is still having problems displaying XP style controls. i found the following site on msdn useful.
http://msdn.microsoft.com/library/?url=/library/en-us/dv_vbvcstechart/html/vbtchUsingWindowsXPVisualStylesWithControlsOnWindowsForms.asp?frame=true
Kenbloke
|
|
|
|
|
hi,
I'm new to C#,I have this problem and would apriciate if someone would give me an idea .
I have a object initilazed in a Windows form and i wold like to use the same oject in some components and the way I was thinking was to get the address of this object. But since it's a managed object the compiler doesn't alow me to take it's address.
Please give me any ideas to overcome this,
thanks a lot for your time
Endri
|
|
|
|
|
Like this:
SomeObject obj = new SomeObject();
Component1.Prop1 = obj;
Component2.Prop2 = obj;
All objects are refered to through "object references". You can freely pass this object reference to any part of your system.
--
Peter Stephens
|
|
|
|