|
Thanks for that. It will come in use later on in the project.
The FoZ
|
|
|
|
|
HarveySaayman wrote: posible to have more than one selected row in a dataGridView unless otherwise set up by you in design time
Yes. You can use datagridview1.MultiSelect=false for only allowing one. Brought this up to my students the other day in class.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi, as you might know from an older post (here) I'm working on a communication protocol driver in C#.
Protocol messages can be of two types (commands and responses) so I chose the following class structure:
public abstract class Message
{
protected byte[] CompileCommonPacketPart()
{
}
}
public abstract class Command : Message
{
protected byte[] CompileCommandPacketPart()
{
}
}
public abstract class Response : Message
{
protected byte[] CompileResponsePacketPart()
{
}
}
public class MyCommand : Command
{
public byte[] CompilePacket()
{
CompileCommonPacketPart();
CompileCommandPacketPart();
...
}
}
As you see, at the moment CompilePacket() explicitly includes calls to the base methods in order to compile the generic parts of the packet, and every time I define a new command I must manually insert these calls.
This could be error-prone (I have to deal with a lot of commands...) and I feel that there should be a way to factor out this common behaviour...
Is there any way to perform these calls automatically (not explicitly)?
Thanks in advance for your support!
Andrea
|
|
|
|
|
Yes, it can be error-prone, but there isn't a way to automatically call the base class methods. You could implement a virtual method on Command that handles this for you and then in the derived classes override that method instead. It would make your classes look like this:
public abstract class Command : Message
{
protected byte[] CompileCommandPacketPart()
{
}
public virtual byte[] CompilePacket()
{
CompileCommonPacketPart();
CompileCommandPacketPart();
}
}
public class MyCommand : Command
{
public override byte[] CompilePacket()
{
base.CompilePacket();
}
} This simplifies things a bit in that you only have to call base.CompilePacket() . Thinking about it a bit more, you might be able to do this:
public abstract class Command : Message
{
protected byte[] CompileCommandPacketPartInternal()
{
}
protected abstract byte[] CompileCommandPacketPart()
{
}
protected byte[] CompilePacket()
{
CompileCommonPacketPart();
CompileCommandPacketPartInternal();
CompileCommandPacketPart();
}
}
public class MyCommand : Command
{
public override byte[] CompileCommandPacketPart()
{
} This will work as long as the order of calls in Command.CompilePacket() will always be the same. In either case, you might want to make some of the protected methods internal or private instead.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
As Scott already said, there's no way to automatically call a base class method. One solution would be to use some kind of hierarchy, in case the methods are always called in the same order:
public abstract class Message
{
protected virtual byte[] CompilePacket()
{
}
}
public abstract class Command : Message
{
protected override byte[] CompilePacket()
{
base.CompilePacket();
}
}
public abstract class Response : Message
{
protected override byte[] CompilePacket()
{
base.CompilePacket();
}
}
public class MyCommand : Command
{
public byte[] CompileCustomPacket()
{
base.CompilePacket();
}
}
So you will only have to call base.CompilePacket() , everything else will be handled by the inheritance hierarchy.
regards
modified on Sunday, June 22, 2008 2:15 PM
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Would the "Template Method" design pattern work?
public abstract class Message
{
public byte[] CompilePacket()
{
CompileCommonPacketPart();
CompileCommandPacketPart();
CompilePacketInternal();
}
protected abstract byte[] CompilePacketInternal();
}
public class MyCommand : Command
{
protected override byte[] CompilePacketInternal() {}
}
|
|
|
|
|
Publicly expose the base method only. Have the base method call a protected [pure] virtual method. The derived classes now implement the latter method, not the first.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I'd like to thank everybody, now I have a whole bunch of new ideas to try out!
Best regards,
Andrea
|
|
|
|
|
HI,
I'm New To All System.Reflection Area
is there a Way To Get ClassInfo From a DLL
Where There Are Some Classes.
Have Fun
Never forget it
|
|
|
|
|
By using System.Reflection namespace, you can get various information about an assembly. You can;
- Get the class names in that assembly
- Get the function names in a class
- Get the Parameter info of a function
Here are some code samples to do the things above:
To load an assembly dynamically:
Assembly MyAssembly = Assembly.LoadFile(Application.StartupPath + "\\MyDll.dll");
To get the class names in an assembly:
Type[] myClasses;
myClasses = MyAssembly.GetTypes();
To get the function names in a class:
MethodInfo[] mi;
mi = myClasses[i].GetMethods();
To get the parameter information of a specific function in a class:
ParameterInfo[] pi;
pi = mi[i].GetParameters();
Regards
Zafer SAVAS
|
|
|
|
|
Just as a note, MyAssembly.GetTypes() does not just return classes, but also interfaces, enumerations, etc. If a Type represents a class, it will have the IsClass property set to true
|
|
|
|
|
|
Hi there.
Firefox browser saves site's icon into the base64 string in its bookmark HTML file.
Like this :
<A HREF="http://en-us.www.mozilla.com/en-US/"
ADD_DATE="1183006386" LAST_MODIFIED="1212431053"
ICON_URI="http://en-us.www.mozilla.com/favicon.ico" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/
9hAAABEUlEQVQ4jbWSsXEDMQwEL0CIWAWwBdTCFtgCU0Xs4bMPVAgL+GZUwTrg/
5uS7JECGwlnOLzF4UDpr6u1RkqJkIgIWmv03nkrvN/vRAQhsUks+1mkAZN+B63
rDTOj7MIicZUgxlkkUkq4+88AMzsB7J23GLCrxKYg50xKiUXiRdxaw8xYdgD67
nyAmOBlHgfA3cfsMR7NggN2ZHLcLftYp4Pn7jMgJNydnPOjkwgEnGtbJsH1CXh
sotZKiTjDlpnRe8fdT9E2Cee7I5daKwpRShkOzAx3f5l9k7hcLoREzplaK4uCC
LGuNx620Ht/sb5Ntt/+xFor8Zx87El/Ur13Yg9n7p5z/gwwg47w3H0E9Z/1BfA
kJDRE3FKkAAAAAElFTkSuQmCC" SHORTCUTURL="mozila"
LAST_CHARSET="UTF-8">Mozilla - Home</A>
Now, I want convert it to an image.
for this, first I omitted data:image/png;base64, and other needless strings , then I used this method :
private Image Base64StringToImage(string base64ImageString)
{
byte[] b;
b = Convert.FromBase64String(base64ImageString);
MemoryStream ms = new System.IO.MemoryStream(b);
Image img = System.Drawing.Image.FromStream(ms);
return img;
}
But this Exception occurred :
Invalid length for a Base-64 char array
Can you help me ?
Sorry for my English. I'm a freshman .
|
|
|
|
|
Works for me with the string given (it's a 16x16 icon with the red mozilla dragon head). Maybe you accidentally include some carriage returns or line feeds in the base64 string?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Wow, yes, you're right.
But I several times tested it. it didn't work.
But now it's working .
Sorry for my English. I'm a freshman .
|
|
|
|
|
HI,
I create some thread and i want to stop one of them.
I don't want to use Abort method.
Is there is some other way to terminate the tread ?
|
|
|
|
|
The best way is to tell the thread to stop itself. Put a volatile boolean varable in the class for the thread. Make the thread check the value of the boolean regularly, so that it can exit when the value changes.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Let take For Example :
private void OnClockStart()
{
while (ClockTick)
{
this.Invoke(clockHandler);
Thread.Sleep(1000);
}
clockThread.Abort();
}
ClockTick = Bool To Check & When u Want to Stop The Thread You Just Assgin False
the While Will break and The clockThread.Abort(); Method will Execute
Have Fun
Never forget it
|
|
|
|
|
I think in your example, clockThread.Abort(); is not needed as making "clockTick" false will end the method which will stop the thread. So no need to abort it explicitly.
|
|
|
|
|
You can use a volatile boolean variable, if it is set as false, exit the method. This is the safest way for cancellation. You can call Thread.CurrentThread.Abort() also, aborting from a known location is safe.
|
|
|
|
|
Rather than a boolean, I suggest looking at a ManualResetEvent(). Threads are often in wait states and this allows you to avoid a polling model.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
i am creating a shortcut for google using IWshRuntimeLibrary. My code is like this
shortcut1 = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(@"C:\Google.lnk");
shortcut1.TargetPath = "http://www.google.com";
shortcut1.Description = "Open Google";
shortcut1.IconLocation = "C:\\icon.ico";
it works quite good.
The problem that i have is when i copy it to another system the icon image is not displayed. I know the problem is
shortcut1.IconLocation = "C:\\icon.ico";
where i specify the icon path on the other system it does not exist. One solution is to copy the icon in C drive but i don't need this.
What i need is this there should be no need to copy icon.
Is there any way to do this that i dont have to copy icon just copy the shortcut.
One possibility is to use windows icons but i want to use my own image(icon).
|
|
|
|
|
A shortcut file can not contain an icon, so you have to have it in a separate file. You have to copy the icon file along with the shortcut.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I have some text box ( multi line ) and i need to add 4 lines.
I want to add them in some way that the structure will be same - i mean like this
Somestr123 info1
Somestr456789 info2
.
.
.
So, I want to format each line in some way that i could have same structure.
I know the maximum string Length of each string.
Thanks.
modified on Sunday, June 22, 2008 5:11 AM
|
|
|
|
|
Use tabs '\t' or fill the gaps with spaces and use a monospace font like Lucida Console or Courier New
regards
modified 12-Sep-18 21:01pm.
|
|
|
|