|
I tried this
string request = "\"Hello\" World";
Console.WriteLine(request);
request = request.Replace("\"", "\\\"");
Console.WriteLine(request);
string reply = "\\\"Hello World\\\"";
reply = reply.Replace("\\\"", "\"");
Console.WriteLine(reply);
And it worked fine. Of course, I hardcoded the strings. Are you sure the reply is coming back in the expected format?
Michael
CP Blog [^]
|
|
|
|
|
I'm sorry this question is so vague, but I'm not sure where to begin. I'm attempting to create a TrackBar from scratch. I'd like to implement rounded corners in both the borders of the TrackBar and the sliding user component of the control. Can anyone suggest where I can being researching how to create the rounded corners of the back ground ? I've started with a Panel control and created a rounded-corner rectangle bitmap as the Panel's background image. I think I'd have to use GDI to locate corners and set the color to Transparent or somthign like that, but again....I'm not sure. Any hints or idea on where I can start looking for the solution to my problem ?
|
|
|
|
|
|
OK, Great advice leppie, I've created the shape I need, but I'm having trouble figureing out how to "capture" the exterior region of the control shape (i.e. outside my rounded rectangle)
I want to set the color of these four regions (each corner) to Color.Transparent, but I don't know how to identify these regions...any ideas ?
|
|
|
|
|
I think I figured it out.
|
|
|
|
|
I have a control which inherits from textbox and when i set the
PropertyGrid.SelectedObject to my control the property grid shows all the public properties which are inherited, how can i hide these properties ?
like hiding all the behavior attributes.
(without overriding all of them and setting [Browsable(false)] to each one)
|
|
|
|
|
blankg wrote:
(without overriding all of them and setting [Browsable(false)] to each one)
I don't belive you can do this without applying the Browsable attribute.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hi I get an error when trying to serialize a derived class with XmlSerializer because it's base class implements an interface:
cannot serialize XXX because YYY is an Interface...
Any suggestions???
|
|
|
|
|
specify the implemetation type in the XmlElementAttribute, u should have an attribute for every class that will be deserialized.
top secret xacc-ide 0.0.1
|
|
|
|
|
I don't want to serialize the base class stuff,
only the current instances 'as is' -
is there a way I can let the serializer ignore the inheritance?
|
|
|
|
|
mgaerber wrote:
is there a way I can let the serializer ignore the inheritance?
You can ignore certian elements with attributes, but I suspect you havent done much reading on this, I suggest you do, unless u wanna write your own de/serializer. And no u can never instantiate an interface or an abstract class, so unless u wanna break .NET that will never succeed!
top secret xacc-ide 0.0.1
|
|
|
|
|
Alright,
the problem was in a class from which I inherited,
[XmlIgnore] did the trick...
Thanks for your hints!
|
|
|
|
|
And here I´m again...
I have problems to get a specified Array Length from an assembly file.
First here is a extract from the assembly file (source):
public class SEGMENT_FLATNESS
{
public int ID { get{ return 221; } }
// date as 8-digit integer in format yyyymmdd
public int DATE;
// time as 6-digit integer in format hhmmss
public int TIME;
// test
public float[] FLATNESS;
public SEGMENT_FLATNESS ()
{
FLATNESS = new float[35];
}
}
To get the array length I tried following:
first I have ceated an instance from the upper class, then I got the related Field and tried to get the Property 'Length' from it.
The second way was to invoke the Method GetLength from the array, but both didn´t work.
Here my last try:
using System;
using System.Reflection;
namespace DummyTest
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
Assembly testAss = System.Reflection.Assembly.LoadFrom("KorrektesFile");
Type testType = testAss.GetType("SEGMENT_FLATNESS");
object testInvoke = Activator.CreateInstance(testType);
FieldInfo testInfo = testType.GetField("FLATNESS");
Type fieldType = testInfo.FieldType; // weiß nicht ob das nötig ist
PropertyInfo p = fieldType.GetProperty("Length");
MethodInfo[] testMethodInfo = p.GetAccessors(false); //liefert nur die public get Methode für die Länge!!!
testMethodInfo[0].Invoke(testInvoke, null); // **************
string tmpString = testInfo.Name; //dummyZeile wg. debug (kein vorzeitiges Ende)
}
}
}
What did I wrong? And how can I get the array length?
Please help me...
Norman-Timo
|
|
|
|
|
Norman-Timo wrote:
testMethodInfo[0].Invoke(testInvoke, null);
if u want a value, u should assign it!
top secret xacc-ide 0.0.1
|
|
|
|
|
Norman-Timo wrote:
FieldInfo testInfo = testType.GetField("FLATNESS");
Type fieldType = testInfo.FieldType; // weiß nicht ob das nötig ist
PropertyInfo p = fieldType.GetProperty("Length");
MethodInfo[] testMethodInfo = p.GetAccessors(false); //liefert nur die public get Methode für die Länge!!!
testMethodInfo[0].Invoke(testInvoke, null); // **************
try this rather:
FieldInfo testInfo = testType.GetField("FLATNESS");
Type fieldType = testInfo.FieldType;
PropertyInfo p = fieldType.GetProperty("Length");
int length = (int)p.Invoke(testInvoke, new object[0]);
top secret xacc-ide 0.0.1
|
|
|
|
|
Thanx for the very fast help, but there are compiler errors in your hint.
p.Invoke... (-> 'System.Reflection.PropertyInfo' does not contain a definition for 'Invoke')
Are there framework differences? I use framework 1.1!
But I tried somithing similar and I only got Exceptions like that:
"An unhandled exception of type 'System.Reflection.TargetException' occurred in mscorlib.dll
Additional information: Object does not match target type.
"
the Exception is trown with following lines:
FieldInfo testInfo = testType.GetField("FLATNESS");
Type fieldType = testInfo.FieldType;
PropertyInfo p = fieldType.GetProperty("Length");
int iii = (int) p.GetValue(testInvoke, null); // -> ********** Exception!
Please help me (I can´t [under]stand this thing!)
Norman-Timo
|
|
|
|
|
|
I´m very sorry, but this is not working too! I really don´t understand the second parameter?
What sense does it make? I always found this method with second parameter is null!
Hey, but I found the solution at another forum:
int arrLength = (int) p.GetValue(testInfo.GetValue(testInvoke), null);
This is the soltion. My problem was the wrong object for the first parameter!
So now I can go on with my work.
Anyway thanx a lot for your help @leppie!
Norman-Timo
|
|
|
|
|
I am trying to develope a small RTF writer to generate project report at runtime, with a limited RTF writing capability. RTF is one page document only, untill we intentionally put page breaks in it and Project report consists of number of pages. Thus, on what criteria it should be decided to insert page break? How to keep track of page's empty area before inserting anything?
OR
The next issue to overcome is to determine how to page-break text that is too long for one page.
Is there some way to identify exactly how many characters I can print before I run out of room in the current rectangle that defines the output, and do to a new page.
RTF specification 1.6 to 1.8 doesn't give any example regarding this issue.
Please guide.
|
|
|
|
|
Hello, I posted a similar question a couple of days ago, got some advice but don't seem to be able
to make this one work anyway. Here is the problem: I have a custom class derived from treenode that I want to be able to perform drag'n'drop on to another instance of the same application. I want to serialize the treenode so I implement the ISerializable interface and add a constructor taking a SerializationInfo and a StreamingContext parameter
The class essentially looks like this:
<br />
[Serializable()]<br />
public class InheritedTreeNode : TreeNode, ISerializable<br />
{<br />
bool bool_property1, bool_property2, bool_property3;<br />
string string_property4;<br />
public InheritedTreeNode() : base() {}<br />
...<br />
}<br />
here's what the serialization code in the InheritedTreeNode does:
<br />
public void GetObjectData(SerializationInfo info, StreamingContext context)<br />
{<br />
info.AddValue("bool_property1", typeof(bool));<br />
info.AddValue("bool_property2", typeof(bool));<br />
info.AddValue("bool_property3", typeof(bool));<br />
info.AddValue("string_property4", typeof(string));<br />
<br />
ArrayList al = new ArrayList();<br />
foreach(InheritedTreeNode itn in this.Nodes)<br />
al.Add(mc2);<br />
info.AddValue("Nodes", typeof(ArrayList));<br />
}<br />
...and here is how it is Deserialized:
<br />
public InheritedTreeNode(SerializationInfo info, StreamingContext context) : base()<br />
{<br />
this.bool_property1 = info.GetBoolean("bool_property1");<br />
this.bool_property2 = info.GetBoolean("bool_property2");<br />
this.bool_property3 = info.GetBoolean("bool_property3");<br />
this.string_property4 = info.GetString("string_property4");<br />
<br />
ArrayList al = (ArrayList)info.GetValue( "Nodes", typeof(ArrayList) );<br />
foreach(MyTreeNode2 mc2 in al)<br />
Nodes.Add(mc2);<br />
}<br />
now for drag'n'drop i do this:
<br />
BinaryFormatter bf = new BinaryFormatter();<br />
MemoryStream ms = new MemoryStream();<br />
bf.serialize(ms, instance_of_a_tree_node);<br />
<br />
DataObject dObj = new DataObject("InheritedTreeNode", ms)<br />
theTreeView.DoDragDrop( dObj, DragDropEffects.All );<br />
and when dropping in the other tree view the code looks like:
<br />
<br />
IFormatter formatter = new BinaryFormatter();<br />
MemoryStream ms = (MemoryStream)e.Data.GetData( "InheritedTreeNode" );<br />
ms.Position = 0;<br />
InheritedTreeNode data = (InheritedTreeNode)formatter.Deserialize(ms);<br />
<br />
this will throw an exception in the deserialization constructor at the first info.getBoolean() call
saying that it is an invalid cast...
Is the problem that i put the memorystream object on the clipboard, because it's a reference? In that case, how do I put copy of the bytes contained in it onto the clipboard in global memory so that other instance can retrieve it?
the byte[] of the memory stream
|
|
|
|
|
Hi all. I know this may seem like a stupid question but hey I'm new @ this.
Please tell me how to add a global variable. I come from vb and it was easy to do it there but I've tried everything in c#, please help.
Thanx
:P
|
|
|
|
|
use static variable for this goal
|
|
|
|
|
hi,
you can use app.config file for accessing globel level variables in C#.
steps.
add an xml file to your solution. And give the value to your globel variable.
eg
<configuration>
<appSettings>
<add key="sourcename" value="DummyDb" />
<add key="DtFormat" value="MM-dd-yyyy" />
</appSettings>>
<
|
|
|
|
|
Hello,JayJ.
First of all,have you studied the cpp language?
Add a global variable there are many methods.
for instance:
1. Add a field into the mainclass which contains the main method.
Such as "public int G_variable = 0 ;".You can even add some modify words as static,readonly.Remember readonly field must be initiated in the constrcution method.
2.C# is completely oo,so everything is class.So more formal way to add a global variable is to write a public class and make the global variable be a field of the class.I suggest you use this way.
Enjoy it!Welcome to world of C#!
Never understand
ridical version!
|
|
|
|
|
ILoveCS wrote:
C# is completely oo
I would disagree with that statement. There are many things that are Object Oriented that C# does not have, such as multiple inheritance.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|