|
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
|
|
|
|
|
jdunlap wrote:
But I'm wanting to use GDI+ objects without converting them to Windows GDI objects.
Ahhh, that could be a problem. During last year's screen saver competition I cursed at MS enough about not being able to mix .NET GDI+ objects and C++ GDI+ objects, even though it does this internally (as seen through Anakrino).
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
I've decided to implement DSS_MONO and DSS_DISABLED by making a region excluding the transparent areas and light areas, and then filling the resulting region with the brush passed in. (The brush can be any brush, including semi-transparent and gradient brushes. ).
If you have better ideas, let me know.
"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
|
|
|
|
|
Mission accomplished!
"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
|
|
|
|
|
Well, beforehand I need to say I must be doing something fundamentally wrong, but I simply cannot see it. Maybe it’s something on machine.config, or web.config, but I was not able to find it anywhere else.
The problem is: my webservices are being handled in a single thread on the server. I compiled release, disabled debugging, tried almost everything. And my webservice seems to be handled only on a single thread.
A simple code that shows this is:
[WebMethod]
public int MyWait(int Waittime)
{
DateTime dt = DateTime.Now.AddSeconds(Waittime);
while (DateTime.Now < dt)
;
return Waittime;
}
As you can see, if you start the webservice and quickly call it twice (I’m testing with IE and the quick test page), passing 20s as the time, you should have both answers in 20s, if there were two threads. The problem is:the second request returns after 40s.
I know that changing this loop for Sleep() solves the problem, but my real code is much more complicated, and has to process several requests simultaneously.
I simply cannot believe that ASP.NET webservices are single threaded.
My latest article: GBVB - Converting VB.NET code to C#
|
|
|
|
|
Setting your Webservice to run at a lower priority mite work...
<a TITLE="See my user info" href=http:
|
|
|
|
|
IIRC ASP.NET makes heavy use of the CLR ThreadPool, one of the down sides to the threadpool is that it won't create a new thread (or queue a new worker item) if the CPU is at 100%*, which your sample code does [edit]by looping until the time has elapsed[/edit].
That is also why changing the loop to a call to Thread.Sleep will allow it to work properly, the thread is suspended (or whatever it really is) until the the time elapses rather than spinning, using up all excess processor time.
*The logical reason is that if you are using up all of the processor, it doesn't make sense to try to get it to do more work. The downside is that you can see longer than usual request times in ASP.NET if the processor is pegged.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Hi,
how can i pass data from byte[] variable into struct. In C/C++ I use memmove. But isnt something like this...
Thank
Wiizi
|
|
|
|
|
Try something like:
using System.Runtime.InteropServices;
...
public static object ByteArrayToStructure(byte[] buffer, int index, Type tStructure)
{
if (null == buffer || 0 == buffer.Length)
throw new ArgumentNullException("buffer");
if (0 > index || buffer.Length <= index)
throw new ArgumentOutOfRangeException("index");
if (null == tStructure)
throw new ArgumentNullException("tStructure");
int size = Marshal.SizeOf(tStructure);
if (index + buffer.Length < size)
throw new ArgumentException("Insufficient data passed", "buffer");
IntPtr pStructure = Marshal.AllocHGlobal(size);
try
{
Marshal.Copy(buffer, index, pStructure, size);
return Marshal.PtrToStructure(pStructure, tStructure);
}
finally
{
Marshal.FreeHGlobal(pStructure);
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
Hey All,
Im doing a simple GUI prototype, and Im using alot of data screen shots from the old application to represent data in the new prototype. Following that thinking I have alot of forms what simply contain picture controls, and I set these bitmaps of the old app to those picture or image control, whatever the new one is called. Anyways, when I set the sizemode property to stretch, the image control doesnt stretch the picture. Any ideas?
Thanks,
Ryan
|
|
|
|
|
Ryan@SalamanderTechnologies wrote:
Anyways, when I set the sizemode property to stretch, the image control doesnt stretch the picture. Any ideas?
I think those names are confusing, try the autosize one.
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
|
Look at the WebClient class in the System.Net namespace.
Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
|
|
|
|
|
Thanks for the info leppie.
I was looking for something that I could possibly tie into some sort of progress control to show the progress of the download [URLDownloadToFile uses a Callback]. Any ideas?
Regards,
Brian Dela
|
|
|
|