|
Hmmm, not sure why the behaviour would be like that. I never have to convert the byte array in a string. I just carry it around till I have to write it out. I am not sure what happens behind the scene when the byte array is converted to a string. Maybe some stuff does not convert. What if you create a byte array with simple text or numbers and try the same. If that works then maybe its something in the PDF that does not convert well to a string. Just guessing. Sorry could not be of more help.
|
|
|
|
|
Unicode is UTF-16, which may be slightly different from UTF-8.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
The interop part of marshaling the BSTR to a string was working ok. The problem was with the conversion from a Unicode array to a byte array. The correct converstion is:
<br />
byte[] pdfBytes = Encoding.Convert(Encoding.Unicode, Encoding.Default,<br />
Encoding.Unicode.GetBytes(pdfString));<br />
What I had been trying to convert to UTF-8, which was what was causing the problems. Converting to Default solved the problem.
Thanks for all the comments.
Dan
They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.
--Benjamin Franklin, 1759
|
|
|
|
|
Thanks for posting the solution. Am sure I will need it one day.
|
|
|
|
|
I'm currently converting some Java code to C# and
if have problems converting this:
Java:
public class MySuperClass {
String generateShowMe() {
return "ShowMe from MySuperClass";
}
public void ShowMe() {
System.out.println(generateShowMe());
}
}
public class MyChildClass extends MySuperClass {
String generateShowMe() {
return "ShowMe from MyChildClass";
}
public void ShowMe() {
super.ShowMe();
}
}
When i call MySuperClass.ShowMe() i get of course
"ShowMe from MySuperClass", but when i call
MyChildClass.ShowMe(), i get "ShowMe from MyChildClass".
-> although the child class calls the base (super) class to show the string, the super class calls generateShowMe() from the child class.
How can i to this in C#?
(i currently simulate this, by using a delegate to call generateShowMe())
thanks,
Carsten
|
|
|
|
|
I think you mean
base.ShowMe();
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
obsolete - don't won't to blame my self
see Richard Deeming post for a working sample.
(I'm not a friend of editing post after someone answered it, but i am to "embarrassed" about my post
Thanks to Philip Fitzsimons and Richard Deeming.
|
|
|
|
|
Could be something to do with the fact that MyChildClass.generateShowMe returns "ShowMe from MySuperClass" instead of "ShowMe from MyChildClass" .
cabo wrote:
public class MyChildClass : MyBaseClass {
protected override string generateShowMe() {
return "ShowMe from MySuperClass";}
public new void ShowMe() {
base.ShowMe();}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
lol
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
This should work:
C#:
public class MySuperClass
{
protected virtual string generateShowMe()
{
return "ShowMe from MySuperClass";
}
public virtual void ShowMe()
{
Console.WriteLine(generateShowMe());
}
}
public class MyChildClass : MySuperClass
{
protected override string generateShowMe()
{
return "ShowMe from MyChildClass";
}
public override void ShowMe()
{
base.ShowMe();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Thanks, i should know that this works...
But it was in a more complex code, with some unfinished API's, switched between C++/C#/Java and the weather was bad...
|
|
|
|
|
i noticed with a rtf box when i select a text that has diffrent size text to it and diffrent colors,and i change the fontstyle of the selected text...it changes the colors, and font of the entire selected string. and doesnt keep intact the individual styles of each char in the selected text.
The teacher at my school asked us to write a method that would take into account each individual char's size, font, color ect. I have been trying to iterate through the rtf.SelectedText collection and isolate each char but how do i get the font and color of a single char in a rtf box ? Does this question make any sense? if not let me know and ill try to rewrite it . anywho any ideas would help...
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
You need to go through your selection char by char (you can do a select(i,1) in a loop from start of select to end), and then for each char in selection, you can get the color by the oRTFBox.SelectionColor property.
I just had to do something very similar to this. If you get stuck email me (from link) and I can email a code example.
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|
|
i whipped something together...maybe you can help me work with it. it doesnt seem to work correctly because the Rtf.Select() requires a start index....how can i find the start index of a specific char in the selected text ? heres the code i just kinda through together.
<br />
char[] chars = GetMainFormData.MainTextArea.SelectedText.ToCharArray();<br />
Color[] cls= new Color[chars.Length];<br />
int count =0;<br />
int tmp = GetMainFormData.MainTextArea.SelectedText.Length;<br />
for(int i =0;i<tmp;i++)<br />
{ <br />
GetMainFormData.MainTextArea.Select(GetMainFormData.MainTextArea.SelectedText[i],1);<br />
Color tmp1 = GetMainFormData.MainTextArea.SelectionColor;<br />
cls[count] = tmp1;<br />
GetMainFormData.MainTextArea.SelectionFont = fd.Font;<br />
GetMainFormData.MainTextArea.SelectionColor = cls[count];<br />
count++;<br />
}<br />
Any ideas ?
The Code Project Is Your Friend...
|
|
|
|
|
Here is some code I used for my latest project where I had to do something similar.
----------------
<br />
int iIndex = 0;<br />
<br />
while ( iIndex < (oBox.TextLength) )<br />
{<br />
<br />
oBox.Select(iIndex,1);
<br />
if (null != oBox.SelectionFont)<br />
{<br />
iSelectedCharTextSize <br />
= getTextSizeFromFont(oBox.SelectionFont);<br />
}<br />
<br />
if (true != oBox.SelectionColor.IsEmpty)<br />
{<br />
strSelectedCharColor <br />
= getHexColorString(oBox.SelectionColor);<br />
}<br />
--------------
You see, though, I went through the whole box from the beginning...not just using what was selected. So you will probably have to find the beginning index based on what is selected. I wouldn't think it would be that hard.
good luck.
chris
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|
|
thanks for the code...ill have to work on it tonight =)...anywho...is getHexColorString , getTextSizeFromFont a function you wrote ? what do those functions do if so ?
thanks
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
Yes, getHexColorString and getTextSizeFromFont are my own methods. Sorry...had I realized I had left them in, I'd have taken them out so as not to confuse you.
getHexColorString() takes the current char, determines the color and returns the number representing the color as a hexadecimal string (e.g. black text would return "000000").
getTextSizeFromFont() gets the font size and determines which HTML text size most closely matches it.
As you may have guessed, what I'm writing is something similar (but not quite) like an RTF2HTML conversion program.
There are only 10 types of people in this world....those that understand binary, and those that do not.
|
|
|
|
|
Well i got the code to work perfectly...but perhaps you could help me optimize it ? it is incredibly unefficent....because it moves char by char...and each time it changes the font / color of that char it has to update the hole rtf box. if i could find away to do all this work in memory...the speed increase would be incredible. The following code seems to work good....but any ideas on how i can perform the same actions in memory?
int iIndex = 0;<br />
int SelSt = GetMainFormData.MainTextArea.SelectionStart;<br />
Color[] jr = new Color[GetMainFormData.MainTextArea.SelectedText.Length];<br />
Font[] fr = new Font[GetMainFormData.MainTextArea.SelectedText.Length];<br />
int tmp = GetMainFormData.MainTextArea.SelectionLength;<br />
GetMainFormData.MainTextArea.Visible = false;<br />
while ( iIndex < (tmp) )<br />
{<br />
GetMainFormData.MainTextArea.Select(SelSt,1);<br />
if (null != GetMainFormData.MainTextArea.SelectionFont)<br />
{ <br />
fr[iIndex] = GetMainFormData.MainTextArea.SelectionFont;<br />
Font tmpF = (Font)fr[iIndex];<br />
if(tmpF == fd.Font)<br />
{<br />
GetMainFormData.MainTextArea.SelectionFont = fd.Font;<br />
}<br />
else if(tmpF != fd.Font)<br />
{<br />
Font fonf = new Font(tmpF.FontFamily,fd.Font.Size,fd.Font.Style);<br />
<br />
GetMainFormData.MainTextArea.SelectionFont = fonf;<br />
}<br />
}<br />
if (true != GetMainFormData.MainTextArea.SelectionColor.IsEmpty)<br />
{<br />
jr[iIndex] = GetMainFormData.MainTextArea.SelectionColor;<br />
GetMainFormData.MainTextArea.SelectionColor = jr[iIndex];<br />
}<br />
SelSt++;<br />
iIndex++;<br />
}
Jesse M
|
|
|
|
|
What are the C# equivalents of the C/C++ HIWORD/LOWORD/HIBYTE/LOBYTE macros? In VB6 I had to write my own, but surely C# must have them.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
static int HiWord(int Number)
{
return (Number >> 16) & 0xffff;
}
static int LoWord(int Number)
{
return Number & 0xffff;
}
All I need is a roadmap and then I might be able to find a clue.
|
|
|
|
|
Thanks. That's what I ended up doing - just re-writing the C++ macros myself.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
I have a ActiveX control written in MFC, and I am now using it in .Net, however, I can not figure out how to use the EventHandler for this ActiveX control. For example, "DoubleClick" event is supposed to return back extra parameters from the ActiveX control, how do I get these information? using a derived EventArgs class? who will be creating these EventArgs instances?
Thanks.
|
|
|
|
|
Is there an equivalent of the DrawState() API in .NET? If not, I can write my own, but I didn't want to re-invent the wheel.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
jdunlap wrote:
Is there an equivalent of the DrawState() API in .NET?
Bits and pieces are implemented, see the System.Windows.Forms.ControlPaint class.
jdunlap wrote:
If not, I can write my own, but I didn't want to re-invent the wheel.
You could use P/Invoke to call the original API
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
James T. Johnson wrote:
Bits and pieces are implemented, see the System.Windows.Forms.ControlPaint class.
OK, I'll look at that.
James T. Johnson wrote:
You could use P/Invoke to call the original API
But I'm wanting to use GDI+ objects without converting them to Windows GDI objects.
Thanks for your time!
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|