|
If you go to http://www.gotdotnet.com/team/csharp, you'll find my implementation of Spacewar!, which uses UDP over sockets.
The source is included; look on the information page.
|
|
|
|
|
How can I specify app.Path as I do in VB6? I am trying to point to a .txt file that I have included in the folder of the application. Any suggestions?
P.S. - While I am at it, is there any specific way to do a Debug.Print ? We used to have an immediate window in VB6 that allowed for this which was great for testing purposes. Thanks.
Nick Parker
|
|
|
|
|
System.Windows.Forms.Application.ExecutablePath tells you where the executable is located that started the application. You can also use the StartupPath property, they both appear to do the same thing.
System.Diagnostics.Debug class has lots of methods for you to use; there is also the System.Diagnostics.Trace class which I use more often for no justifiable reason .
James
Simplicity Rules!
|
|
|
|
|
Thanks James, that's exactly what I was looking for.
Nick Parker
|
|
|
|
|
Has anyone played with the Microsoft Messenger API in C#? For some reason I cannot get it to sink and event (assign a delegate).
Rocky Moore
|
|
|
|
|
I didn't even know that they had one. What all can it do? And where can I get it from?
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
|
Rocky Moore wrote:
It is COM but here is the link:
Thanks! I was hoping there was a fully .NET version
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Does Messenger have native support for .NET now?
The last time I looked it was still COM, or is this what you're having problems with?
Cheers,
Simon
"Every good work of software starts by scratching a developer's personal itch.", Eric S. Raymond
|
|
|
|
|
I Createed a WindowsApplication in c#. I Noticed all the Console.* functions still compile but of course no console appears. How can i make the console show up?Its usefull to print messeges to there for debug
thank you
|
|
|
|
|
why not write the debug info in a textbox?
|
|
|
|
|
You can log all messages to a file for debugging purposes
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
If you want, you can compile your application as a console application, and it will still work as a windows app (forms and all) but the console will always be displayed.
You can change the type from the Project's properties dialog.
James
Simplicity Rules!
|
|
|
|
|
James T. Johnson wrote:
If you want, you can compile your application as a console application
Blast! Why didn't I think of that
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Even better is to use the log4net framework. Allows you integrate logging into your application. See: http://sourceforge.net/projects/log4net/
This way you can enable logging for a particular part of your application without having to change any source or recompile. Just modify the configuration file.
Phil Bolduc
Vancouver, BC Canada
|
|
|
|
|
I am trying to overload this method on a form and capture the WM_LBUTTONDOWN message. I am fairly new to C# and could someone guide me how to do it.
Thanks
|
|
|
|
|
Handle the MouseDown event
create a function like this
public class MyForm : System.Windows.Forms.Form {
protected override void OnMouseDown(MouseEventArgs e) {
if (e.Button == MouseButtons.Left)
MessageBox.Show(this, "You clicked the left button");
else
MessageBox.Show(this, "You clicked some other button");
}
}
|
|
|
|
|
Hi All,
I am still stuck trying to get some Crystal Reports working.
From what I have found out all my code is correct and I must just be missing something else.
Now the thing is I have no idea what that something else is.
I have downloaded the samples from Crystal Decisions and used them and I get the same error message.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
CrystalDecisions.Web..get_7() +189
CrystalDecisions.Web.CrystalReportViewer.OnInit(EventArgs e) +352
System.Web.UI.Control.InitRecursive(Control namingContainer) +235
System.Web.UI.Control.InitRecursive(Control namingContainer) +179
System.Web.UI.Control.InitRecursive(Control namingContainer) +179
System.Web.UI.Page.ProcessRequestMain() +169
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.0.3705.0; ASP.NET Version:1.0.3705.0
Could someone please tell me what I am doing wrong here?
Thanks,
Gavin
|
|
|
|
|
Hello Friends,
I'm developing one MDI application.
In that I want to perform some task in ACtivated() event of each child.But whenever I'm activating MDIChild, activated() event of that child is not firing. Thats why I'm unable to perform my task.
Has anybody having any idea about this.
Thanks in advance.
Pranoti
|
|
|
|
|
Try using the MdiChildActivate instead for MDI child windows.
Rocky Moore
|
|
|
|
|
I'm new to C# and was looking for help on sending objects through sockets.
I have a program(which I got from this site) that sends bytes through a socket, it's a client/server chat program. I have written a class and made it Serializable and am trying to send instances of my class through the socket but haven't a clue how to actually serialize the object into bytes and send it through the socket.
Hope someone can help,
Paddy.
|
|
|
|
|
public byte[] GetObjectBytes(object o)
{
MemoryStream memstream = new MemoryStream();
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(memstream, o);
memstream.Close();
return memstream.GetBuffer();
}
public object GetObjectFromBytes(byte [] bytes)
{
MemoryStream memstream = new MemoryStream(bytes);
IFormatter formatter = new BinaryFormatter();
object o = formatter.Deserialize(memstream);
memstream.Close();
return o;
}
I'm not a network guy, but I assume you just call the Write method on the NetworkStream object representing your socket, to send the byte array, then call the Read method on the other side to read back the byte array.
GetObjectBytes() will serialize the object and return the byte array which you can pass to Write, GetObjectFromBytes() will deserialize the byte array from the Read method.
HTH,
James
Simplicity Rules!
|
|
|
|
|
I am having sort of the same problems as you are. Instead I am trying to make class variables equal to the bytes returned from the socket. I sort of understand what James T. Johnson is giving you advise on; but, I don't know how to make a custom object in C#. Since I am using class variables instead of objects, I am leaving you this test code to show you how I convert the byte types to the variables in a class. This example requires the knowledge of byte masking and the use of Reflection. I am hoping to get some feedback plus maybe show you something new dealing with Reflection.
using System;
using System.Reflection;
namespace ConvertTypes
{
///
/// Summary description for ConvertTypes.
///
///
class ConvertClass
{
public int x;
public int y;
public bool z;
public ConvertClass(int i, int j, bool k)
{
x = i;
y = j;
z = k;
}
// Set the converted value
public void SetConvertClass(int i, string sName)
{
if(sName == "x")
x = i;
else
y = i;
}
}
class clsConvertTypes
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
ConvertClass mCls = new ConvertClass(0,0,true);
//Declare 8 Bytes for 2 int's
byte [] bTest = new Byte[8];
// get a Type Object representing ConvertClass
Type t = typeof(ConvertClass);
// get the fields from the Type object (ie int x, int y)
FieldInfo [] fi = t.GetFields();
// Start at index 0 which represents the x field
int iIndex = 0;
//Build the x value as 500000 and the y value as 400000
bTest[0] = 0x00; // 0x0007A120 = 500000
bTest[1] = 0x07;
bTest[2] = 0xA1;
bTest[3] = 0x20;
bTest[4] = 0x00; // 0x00061A80 = 400000
bTest[5] = 0x06;
bTest[6] = 0x1A;
bTest[7] = 0x80;
foreach(FieldInfo FI in fi)
{
if(FI.FieldType == typeof(int))
{
// Declare a temporary integer variable
int iTemp;
// Mask the byte array into a single integer
iTemp = (int)((bTest[iIndex]<<24) | (bTest[iIndex+1] << 16) |
(bTest[iIndex+2] << 8) | bTest[iIndex+3]);
// increment the index by 4 bytes since it is a int
iIndex = iIndex + 4;
// Declare an object which will be used to pass
// parameters to the SetConvertClass method
object[] targs = new Object[2];
targs[0] = iTemp; //First argument
targs[1] = FI.Name; //Second argument (x or y)
// Get all methods associated with ConvertClass
MethodInfo[] mi = t.GetMethods();
foreach(MethodInfo m in mi)
{
//Compare to the name of the method
if(m.Name.CompareTo("SetConvertClass") == 0)
{
Console.WriteLine("Setting the {0} value to {1}",
FI.Name,iTemp);
//Invoke the method using Reflection
m.Invoke(mCls,targs);
}
}
}
else
Console.WriteLine ("Don't do anything with the {0} field",
FI.Name);
}
Console.WriteLine("x is {0} y is {1}",mCls.x,mCls.y);
}
}
}
The Long Way,
Tom McDaniel
|
|
|
|
|
That's pretty what the binary serializer does except it has type safety built in.
Using the methods I created you would do something like this.
private byte[] GetMyClassBytes(MyClass mc)
{
return GetObjectBytes(mc);
}
private MyClass GetMyClassFromBytes(byte[] bytes)
{
return (MyClass) GetObjectFromBytes(bytes);
} To go from object to a specifc class you just need to cast or use the as keyword if you don't want to throw an exception if it is the wrong type (return GetObjectFromBytes(bytes) as MyClass returns null if the object isn't of type MyClass).
James
Simplicity Rules!
|
|
|
|
|
Thanks for the help. I haven't got a chance to try it out yet but that should fix the problem. I'll give it a go later on.
I can't get my head around Tom's code though coz I'm only learning C# at the moment.
Thanks,
Paddy.
|
|
|
|