|
Hi,
I have a [System.Control.RichTextBox][1] (not System.Form.RichTextBox), and I would like look for a specific word, and apply certain decoration on the found phrase. so far, I got
this, but it's not working properly. I am looking for **a list of words**, but the TextPointer are not pointing to the right location.Therefore, all my ranges are incorrect. Any idea to do it better?
thanks,
I do run this in a loop of my words:
startPos = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd).Text.IndexOf(word);
leftPtr = textPointer.GetPositionAtOffset(startPos+1, LogicalDirection.Forward);
Rect leftSelectedRect= textPointer.GetCharacterRect(LogicalDirection.Forward);
rightPtr = textPointer.GetPositionAtOffset((startPos+Word.Length), LogicalDirection.Backward);
Rect rightSelectedRect = textPointer.GetCharacterRect(LogicalDirection.Forward);
TextRange myRange = new TextRange(leftPtr, rightPtr);
[1]: http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx
|
|
|
|
|
If you need to clarify something in your original post, then edit your original post, or reply to your original post.
If your problem is so urgent that you feel the need to 'bump' it, then get your wallet out and visit rentacoder.com.
Bumping posts is rude!!!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
You're right, but I didn't know this way I am going to bump it.
|
|
|
|
|
When I want to draw something on a picture box in a Window Form, i use Graphic
Graphics G = pic_Main.CreateGraphics();
G.DrawElipes ...
so on ..
But every thing was cleared when this Form was hidden by another Form or Window .
Any body know how to make it didnt happen .
Thanks !
|
|
|
|
|
magicii wrote: Any body know how to make it didnt happen .
Yes.
1) Don't use a PictureBox. Everyone thinks it is the control to use, because of its name. Only use it for static images (ones that won't change).
2) You can do drawing on the surface of practically any .NET control, including the Form, by handling the Paint event.
Something like:
private void UpdateTableDataForm_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawEllipse(new Pen(this.ForeColor), this.ClientRectangle);
}
This is from a Form.Paint event handler, but you could use a Panel or UserControl , or whatever.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Actually the PictureBox was not a bad choice and in fact if you are going to do a simple animation it is a decent choice. You can draw some background image save it. Load it in the Picture box draw on top of your static image. The real problem, like any other control, is that you drawing on what is essential temporary surface. Every time the control refreshes and redraws itself and your stuff is lost. That is why you hook in to the paint event to redraw your stuff on every refresh but if it is static save the image after you draw it and reload it and it is a null issue. You might have to hook the resize event and redraw it to avoid you image being distorted but it pretty simple too. Hell, I did in VB6 with excellent results.
ARon
|
|
|
|
|
I disagree - a picture box shows static images. If you're doing something more complex, you get more control by handling your own paint event. The real issue is that the OP is using CreateGraphics, instead of handling his paint event. Calling CreateGraphics on a PictureBox ( or handling it's paint event ) is a waste of time, the control never actually is given a picture to show.
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
|
|
|
|
|
Christian Graus wrote: you get more control by handling your own paint event.
Agreed. In fact I think I say you have to hook the paint event.
I just say it was not a bad choice.
My previous project, I had a background image with a rail network superimposed drawn from user data which is static during the animation. I drew it in a Picturebox. Used a Picturebox method to save a temp copy of the static train network. I then loaded the image and animated little train traversing the network. All I had to do was update the trains. I got a good framerate with GDI and since I hooked the resize event to redraw the network it always look right. Why does it have to show only static images? Really, if you want to draw stuff, no control is that great. That why there is DirectX and OpenGL.
So what are you disagreeing with? I just saying, there are some case where it might be appropriate. You can treat it like a control for layout purposes, use its native methods, etc...
Like you said.
Henry Minute wrote: You can do drawing on the surface of practically any .NET control
Sorry, Wrong Person.
And yes VB sucks...
Regards,
ARon
|
|
|
|
|
ARon_ wrote: So what are you disagreeing with? I just saying, there are some case where it might be appropriate. You can treat it like a control for layout purposes, use its native methods, etc...
Yeah, that is true. I am just accustomed to seeing people use a picturebox to try to be something it's plainly not. And, I would still animate by drawing directly to the form. Perhaps it's just my MFC days talking, tho.
Christian Graus
Driven to the arms of OSX by Vista.
Please read this[ ^] if you don't like the answer I gave to your question.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
|
|
|
|
|
|
You can't use more than one instance of a SoundPlayer and have them all playing at the same time. You'll have to use the MediaPlayer component to play the background sound and use the SoundPlayer to play your button click sounds.
|
|
|
|
|
I believe (from previous research a while ago) it can be done with DirectX. I've never attempted it so I can't offer any working samples/articles but adding that into your search terms may yield some useful results.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
You can use:
1) DirectX 9 Managed Wrapper which I understand to be obsolete
using Microsoft.DirectX.AudioVideoPlayback;
...
BackgroundMusic = new Audio(fileName, false);
BackgroundMusic.Play();
and
using Microsoft.DirectX.DirectSound;
...
public class Sound : IDisposable
{
private static Device SoundDevice;
private SecondaryBuffer MyBuffer;
...
public static void Initialize()
{
SoundDevice = new Microsoft.DirectX.DirectSound.Device();
SoundDevice.SetCooperativeLevel(Form.Handle, CooperativeLevel.Priority);
}
...
public Sound(string AudioFileName)
{
BufferDescription desc = new BufferDescription();
desc.Flags = BufferDescriptionFlags.ControlPan | BufferDescriptionFlags.ControlVolume |
BufferDescriptionFlags.ControlFrequency;
MyBuffer = new SecondaryBuffer(AudioFileName, desc, SoundDevice);
}
...
MyBuffer.Play();
Go to DigiPen Webcast[^] Puc The Pirate - Hour 11
2) OpenAL, I don't have an example but there are example in the Toa Framework[^]
ARon
|
|
|
|
|
Hi,
I am trying to set/get the text of my RichTextBox, but Text is not among list of its properties when I want to get test.Text...
I am using code behind in C# (.net framework 3.5 SP1)
RichTextBox test = new RichTextBox();
cannot have test.Text(?)
Do you know how come it can be possible ?
thanks,
|
|
|
|
|
RichTextBox [^] dont have Text property?!
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
There was a confusion between RichTextBox in System.Windows.Forms and in System.Windows.Control
I am using the one in the Control as I am using WPF. In there, there is no Text property, and in order to get a text, I should have used this line:
string myText = new TextRange(transcriberArea.Document.ContentStart, transcriberArea.Document.ContentEnd).Text;
thanks
|
|
|
|
|
WHY DOEST THIS WORK?
RegistryKey RegKeyWrite = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SystemRestore");
RegKeyWrite.OpenSubKey("DiskPercent");
RegKeyWrite.("DiskPercent",0);
RegKeyWrite.Close();
|
|
|
|
|
Maybe you don't have permission to edit the registry?
What is the exception being thrown?
|
|
|
|
|
Thank you for your Reply,
No exception is being thrown just trying to set a value to the registry
Guess I'll have to figure out how to give my program permission to set values in the registry
Regards
Rick
|
|
|
|
|
rick0557 wrote: WHY DOEST THIS DIDN'T WORK?
Open regedit.exe
and check if the following reg key exist !
HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SystemRestore\\
and if it's not , then replace
OpenSubKey with
CreateSubKey
P.S
Always use
CreateSubKey it's try to open the key and if it's not exist then create it .
I know nothing , I know nothing ...
|
|
|
|
|
rick0557 wrote: RegKeyWrite.("DiskPercent",0);
You've not specified a method. SetValue may be relevant
rick0557 wrote: RegKeyWrite.OpenSubKey("DiskPercent");
You should be assigning the result of this invocation to RegKeyWrite
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Registry KEYS are the folders you see in RegEdit.
Registry VALUES are the named items in the folders (Keys).
I think you're looking for something more like:
RegistryKey RegKeyWrite = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SystemRestore");
RegKeyWrite.SetValue("DiskPercent",0);
RegKeyWrite.Close();
|
|
|
|
|
Thank You for your answer
Tried it but that did change anything either.
Guess I'll have to give my program permission to set values in the registry
Regards
Rick
|
|
|
|
|
You don't give your "program" permissions to the registry. Your application runs as YOU, or the person or ID that launched it. If you don't have permissions to change that value, you have to use a higher level user account, like an Admin account.
If you're running the code under a normal user account, just about the entire HKEY_LOCAL_MACHINE hive is off-limits. If you're code is not just swallowing the exceptions, your code should have thrown an Access Denied error, or something very similar.
|
|
|
|
|
Thank You for your reply,
Got it figured out. just one of those rookie mistakes.
your origional solution was right on the mark.
worked just fine once I got my head around it.
Regards
Rick
|
|
|
|