|
|
Hi...
so what is it this time
This time I really would like someone, to explain how I store (and retrieve) bitmaps in a resource file....
Also: If I have a funktion to wich I want to send parameters, then how can I make a list appear, with the few diferant parameters I expect...
F.x.
call SomeMethod(Jump)// So when I want to send the paramet a list shows up with 5 differant options
private void SomeMethod(xxx usrAktion)
switch (usrAktion)
case Jump: etc;
case Walk: etc;
Please help, I will be greatful (honest)....
|
|
|
|
|
I'll help with the 2nd question:
If the parameter is of different types you can overload the method, just declare the same method with all the different paramaters.
If thats not really what you want your best bet is to use an enumerated type like so:
public enum UsrActions
{
Walk,
Run,
Jump,
Skip
}
And your method
private void SomeMethod(UsrActions usrAction)
{
switch(usrAction)
{
case UsrActions.Jump:...
case UsrActions.Walk:...
...
}
}
Then when using the method if you're in Visual Studio you get to this point
someObject.SomeMethod(
Intellisense will pop-up with letting you know its expecting a type UsrAction, just type UsrAction. and up pops the list of UsrAction s to choose from.
|
|
|
|
|
Well thanks.... I was guessing it was something like that...
Well once more: Thanks...
Also I would like to say sorry for the long response time.... My internet has been down >
|
|
|
|
|
I have created a simple client/server remoting interface that basically allows the client to get a byte array from the server. I am wanting to develop something that will allow the main thread on the server to initialize a byte array and allow the client to access this byte array from the interface. Does anyone have experience doing such a thing? Below is an example of what I want to do; but, don't know how to make it work. Look for initialization and How do I do this within the code comments.
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using RemoteInterfacecls; //Code not proviced at this time
using System.Runtime.Serialization;
namespace RemotingInterfaceServer
{
public class dataStuff
{
public byte [] mystuff;
}
public class EntryPoint
{
public static void Main(string[] args)
{
dataStuff dS = new dataStuff();
//Here is the initializaton
ds.mystuff = System.Text.Encoding.ASCII.GetBytes("This is a test");
TcpServerChannel channel = new TcpServerChannel(2566);
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(RemoteExample),
"RemoteExample", WellKnownObjectMode.SingleCall);
System.Console.WriteLine("Hit Key to Exit");
System.Console.ReadLine();
}
}
public class RemoteExample : MarshalByRefObject, IRemoteExample
{
public RemotingExample()
{
Console.WriteLine("Constructor Called ");
}
public IByteArray GetByteArray()
{
ByteArray byteArray;
//This is the from the main initialization
// How do I do this ???????????
byteArray.bytesRead = mystuff;
return (IByteArray)byteArray;
}
}
[Serializable]
public class ByteArray : MarshalByRefObject, IByteArray
{
public byte [] bytesRead;
}
Tom McDaniel
|
|
|
|
|
After many hours of banging my head, I finally realized that the interface should of belonged to the class Entry point. Once I did this, I was able to do what I wanted. Here is a tidbit of the code I used.
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using RemoteInterfacecls; //Code not proviced at this time
using System.Runtime.Serialization;
namespace RemotingInterfaceServer
{
public class dataStuff
{
public byte [] mystuff;
}
public class EntryPoint
{
dataStuff dS = new dataStuff();
public static void Main(string[] args)
{
//Here is the initializaton
ds.mystuff = System.Text.Encoding.ASCII.GetBytes("This is a test");
TcpServerChannel channel = new TcpServerChannel(2566);
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(RemoteExample),
"RemoteExample", WellKnownObjectMode.SingleCall);
System.Console.WriteLine("Hit Key to Exit");
System.Console.ReadLine();
}
public class RemoteExample : MarshalByRefObject, IRemoteExample
{
public RemotingExample()
{
Console.WriteLine("Constructor Called ");
}
public IByteArray GetByteArray()
{
ByteArray byteArray;
byteArray.bytesRead = dS.mystuff;
return (IByteArray)byteArray;
}
}
[Serializable]
public class ByteArray : MarshalByRefObject, IByteArray
{
public byte [] bytesRead;
}
}
}
Tom McDaniel
|
|
|
|
|
Hello everyone , I'm in the process of writing a webservice for a small application im making, I lack a database so what im doing it making a folder on the server for each person that registers. I have a serperate folder in which when I am done will contain a text file for each member containing their password. I have completed the part of the webservice that creates a folder with the name they enter but when I went to make the part that makes the text file for their password I get an error: "Cannot create an instance of the abstract class or interface 'System.IO.TextWriter'. For the life of me I cannot figure what is wrong. Can anyone give me a hand in finding the error? I figure it is a very obvious mistake, heres my method:
[WebMethod]
public void RegisterAccount(string Name, string Password)
{
string path = @"G:\ArtAccounts\"+Name;
System.IO.Directory.CreateDirectory(path);
TextWriter PassWriter = new TextWriter(@"G:\ArtAccountsPasswords\"+@"Name.txt");
PassWriter.WriteLine(Password);
PassWriter.Close();
}
|
|
|
|
|
TextWriter is an abstract base class use StreamWriter
[WebMethod]
public void RegisterAccount(string Name, string Password)
{
string path = @"G:\ArtAccounts\"+Name;
System.IO.Directory.CreateDirectory(path);
StreamWriter PassWriter = new StreamWriter(@"G:\ArtAccountsPasswords\"+@"Name.txt");
PassWriter.WriteLine(Password);
PassWriter.Close();
}
I have never wasted time worrying about such insignificant things. Keep your eye upon the donut and NOT upon the hole. - Bill Sergio about posting in the right forum. The Lounge - June 23, 2002
|
|
|
|
|
Haha I knew it was somthing obvious, Thank you!
|
|
|
|
|
I'm creating an undo feature here and having a slight amount of problem with copying from one point of memory to another.
I've got a stack that will stores a 'before' and 'after' copy of the object that is currently residing in a ArrayList.
pUndoFeature.OldFeature = (BaseFeature) pBaseFeature.Clone( );
pUndoFeature.NewFeature = pBaseFeature;
Now when I click 'undo', I need to copy the contents of the object from the OldFeature to the NewFeature. Since many classes derive from 'BaseFeature', it is undesirable to do a member copy operation for each class.
Is there a C# way of performing a shallow copy of the object from one pointer to another without Cloning into a brand new object?
Thanks as always!
|
|
|
|
|
|
/nod.
I know about the MemberWiseClone function, but it creates a new copy of the class. Was just hoping to copy over the data from one class to another. Wishing for a function like
object MemberWiseCopy( object )
|
|
|
|
|
er, do you mean like
void MemberWiseCopy(object fromObject, object toObject);
The point being to use an already instanciated object instead of creating a brand new one inside the method?
|
|
|
|
|
Yes, that's exactly what I'm looking for.
Here's my save/undo feature. The function 'copy' is the one that I would like to replace with this 'mythical' function call.
public void Edited( BaseFeature pBaseFeature )
{
UndoFeature pUndoFeature = new UndoFeature( );
pUndoFeature.OldFeature = pBaseFeature.Clone( );
pUndoFeature.NewFeature = pBaseFeature;
pUndoFeature.Action = Actions.Edited;
pUndoFeature.Group = Group;
UndoList.Push( pUndoFeature );
}
public void Undo( ArrayList pFeatures )
{
UndoFeature pUndoFeature = null;
do
{
...
pUndoFeature = (UndoFeature) UndoList.Pop( );
switch( pUndoFeature.Action )
{
...
case Actions.Edited:
pUndoFeature.OldFeature.Invalidate( );
pUndoFeature.NewFeature.Invalidate( );
pUndoFeature.NewFeature.Copy( pUndoFeature.OldFeature );
break;
}
} while( pUndoFeature.Group == true );
}
}
|
|
|
|
|
Hallo!!!
So once again I have a problem....
This time i'm having trouble passing a reference of a form to an object, on the load_form event.
But this just gives me a blank reference....
How can I go around this?
|
|
|
|
|
I'm having trouble understanding what you're trying to do. Please post some code. And by blank do you mean null reference or do you have a watched variable that is showing up blank?
|
|
|
|
|
Well basicly what i've been doing is:
private void Form1_Load(object sender, System.EventArgs e)
{
//initiating a class (declared earlier=
defaultCls = new defaultClass(pictureBox1, form1.aktiveform);
}
//(only an example)
public class default
//construktor
public default(pictureBox pB, form frm)
{
// trying to use the frm reference...
}
Error message:
An unhandled exception of type 'System.NullReferenceException' occurred in CopyImage.exe
Additional information: Object reference not set to an instance of an object.
Well this must mean that the Form1 reference isn't set at this time, musn't it???
It works fine if I do the same, on f.x. a keypress event....
What I really was wondering about is if theres an event, which occurs after load complete.
f.x. OnLoadComplete(), or something like that????
|
|
|
|
|
I re-created what you gave me the best I could and it worked. I could not get any null reference exceptions.
The only thing I don't get is why your passing ActiveForm (assuming thats what you mean by "aktiveform") which may or may not actually be the form you want to reference.
|
|
|
|
|
So you are able to send a reference to an object (done when the OnLoad event occurs), and then use it in the object...
To be more precise, I tried to get the window location by saying:
//the frm = reference of Form1.AktiveForm
frmX = frm.Location.X
But that just throws an exception...
Ok so the problem could be that I'm sending the Form1.AktiveForm, you say... Yes that sound very likely because noone says that the form is Aktive (or in focus) at this time....
Then you said that you can't se the logic in me sending Form1.AktiveForm.... What shoudl I be sending???
If I try just to send Form1, the debugger says soemthing about a variable was expected????
...... so any ideas??? >
|
|
|
|
|
Heh....ehh... ups.... all I had to do was send a "this" pointer instead.... dooh.
Well I'm still new at c#, so I have an excuse
Anyway, thanks!!!
|
|
|
|
|
Hi,
I have a main window which is a MdiParent and to which i pop up a couple of other windows (on some event) as mdiChild using the show() method. I want each child window to appear at a particular position for which i use DockStyle properties.
But the new window which opens up resizes itself to the height or width of the original window depending on the dockstyle. I want the size of the mdichild form to remain as it is. What property should i set for this.
Also, In case there are more than one window which pops up,when i change the control from one window to another the position of the window changes. How to avoid this??
Thanks
Sripriya
|
|
|
|
|
simply setting the Location property doesn't work?
:wq
|
|
|
|
|
1.Choose "Microsoft OLE DB Provider for ODBC Drivers"
2.Choose "Use data source name" and select a alias from drop list.( The alias has no password)
3.Click "OK" button, but it shows "The .Net Data OLE DB Provider(System.Data.OleDb) does not support the MSDASQL Provider, Microsoft OLE DB Provider for ODBC Drivers.".
Thank you for your help!
I'm amumu, and you?
|
|
|
|
|
You have three options:
- If you're connecting to SQL Server, you could use the SQLConnection and related objects in the System.Data.SqlClient namespace;
- If you really need an OLEDB connection, use the OLE DB Provider for SQL Server (SQLOLEDB.1), or the equivalent for your data source;
- If you absolutely must have an ODBC connection, you need to download the ODBC provider for .Net and use that instead;
|
|
|
|
|
Thank you.
But I think the oleDbConnection should work properly when I do the steps as above, why does it reports error?
I'm amumu, and you?
|
|
|
|