|
Can't you just do the following?
int indexToText = rtb.Find(text, RichTextBoxFinds.MatchCase);
if(indexToText >= 0) {
rtb.Select(indexToText, 0);
rtb.ScrollToCaret();
} Hope this helps,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Hi,
Thanks for the response, but when I try and search for the next word that matches the find it keeps repeating the same line within the RichTextBox. What am I doing wrong?
This is the code I'm trying...
if (this.activeRichEdit.Find(textBox1.Text, 0, activeRichEdit.Text.Length, options) != -1)
{
int endIndex = this.activeRichEdit.Text.Length;
int findIndex = this.activeRichEdit.Find(textBox1.Text, 0, endIndex, options);
this.activeRichEdit.SelectionColor = System.Drawing.Color.DarkRed;
activeRichEdit.Select(findIndex, 0);
activeRichEdit.ScrollToCaret();
}
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
int foundIdx = 0;
while ((foundIdx = rtb.Find(textBox1.Text, foundIdx, rtb.TextLength, options)) >= 0) {
rtb.Select(foundIdx, textBox1.TextLength);
rtb.SelectionColor = System.Drawing.Color.DarkRed;
foundIdx += textBox1.TextLength;
}
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
|
Hi
i think the richtextbox should do this automatically for you. if you call Find , it'll select the text that was found, and should ensure that the selection is visible.
if it does not ensure that it's visible you can do this by calling ScrollToCaret()
greets
m@u
|
|
|
|
|
Hi All,
I want to make a component,circular in shape, which inherits the property of button eg change the label, resize etc,also on which I will apply Bitmap using C# for my working project.
Pls help me.
Somit
|
|
|
|
|
Override the OnPaint method, draw a circle using the bitmap to fill. Override the OnMouseEnter, OnMouseLeave, and OnMouseDown events to set the style you want and to refresh the button's client area.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
How I can document my C# project?
What must be considered and what should be avoided?
I want to know the best approach. If some one has a sample document then please send me on sami@xpert-tech.com or samibaba.khan@gmail.com
Thank you in advance.
|
|
|
|
|
I like to use N-Doc for internal documentation (turns your three-backslash xml comments into html documentation). It is a free download, so just search online for it.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
NDoc only really works on .NET 1 and .NET 1.1. If you're using higher versions of the framework, you should look at using Sandcastle.
|
|
|
|
|
i have 2 forms called "A" and "b" .when the button in the form "A" clicks the form "b" loads and thorugh the form "b" i want to add a listitem to a listview in form "A". i made the listview public though can't access the listview without creating a new form.
How can i do this without creating new form object?? in my application i have a win.. form and
|
|
|
|
|
One of the better methods for doing this is to implement the Model View Controller (MVC) pattern. Have a read of this pattern and then see how it helps to solve this issue. (Alternatively, you could use an Observer pattern, but the MVC is probably going to be a bit easier for you to get your head round).
|
|
|
|
|
could you please tell me links where i can read about model view controls..
|
|
|
|
|
You could always read this[^] article from our very own Marc Clifton.
|
|
|
|
|
I agree with the other answer however I initially interpreted the question slightly different. (I probably read it wrong) So just to check as this is the way i initially read your query.
Were you saying:
1. you create an instance of FormB from FormA
2. FormB creates a list item that you want to add to form A.
3. However when FormB closes you no longer have a reference to formB so cannot add this item to formA's list view?
|
|
|
|
|
In the B form you need a reference to the instance of the A form. Send a reference to the A form in the constructor for the B form, and in the constructor put the reference in a variable declared in the B form.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
I think all these anwers depend on the actual question as Im not 100% clear on the situation. (apologies if its just me)
If formB just returns to formA eventually anyway, just expose a property on FormB to return the listViewItem like so... (+ with better naming conventions)
using (FormB b = new FormB())
{
if (b.DialogResult == DialogResult.OK)
{
AddItemToListView(b.ListViewItem);
}
}
Obviously the above assumes formB's role is to create a an object which will be displayed in formA's list view. As i said before i think the question was open to different interpretations as seen with the answers.
|
|
|
|
|
i tied this way . it works but the problem is in the form b i' m having severel selections and i want to make the cahnges as soon as the user did it .
|
|
|
|
|
I'd agree with implementing something like the MVC then if you want to add multiple items. Apologies for sending you down the wrong track then.
|
|
|
|
|
with out the .Net framework does c# have the garbage colllector and the built in data stuctures i9 the language itself..
|
|
|
|
|
No. They are part of the .NET framework which C# needs to run. If you don't have the framework somewhere in the equation, then you can't get C# to run. Hence, C# uses features of the .NET framework.
|
|
|
|
|
As Pete already mentioned...C# is simply the programming language; the .NET Framework is the actual runtime environment and implements the features (like garbage collection) and the data structures. You don't really have one without the other.
Scott.
—In just two days, tomorrow will be yesterday.
—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
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
Let's see if I can explain my small doubt. I can go around this, but as I was coding something, I got curious if something wasn't possible to do in c#.
In C++, you could have something like this:
<br />
class A<br />
{<br />
public virtual void method()<br />
{<br />
}<br />
}<br />
<br />
class AA : public A<br />
{<br />
public void method()<br />
{<br />
}<br />
}<br />
<br />
class AB : public B<br />
{<br />
public void method()<br />
{<br />
}<br />
}<br />
<br />
A *obj;<br />
<br />
if ( something )<br />
{<br />
obj = (A)( new AA() );<br />
}<br />
else<br />
{<br />
obj = (A)( new AB() );<br />
}<br />
<br />
obj->method();<br />
<br />
What happens here is that when you invoke the method function, you'll be executing the implementation from AA or from AB and not from A. Though, in C#, if I try to do something like this, you'll be executing the implementation from A. That fact to me, is a shame... I liked this behavior. And as pointers in C# only exist for values, I suppose this is not possible with C#.
Best regards
Gonçalo A.
|
|
|
|
|
Why dont you try it and see what happens?
using System;
using System.Collections.Generic;
using System.Text;
namespace VirtualMethods
{
class Program
{
static void Main(string[] args)
{
A a = new A();
A aa = new AA();
A ab = new AB();
A ac = new AC();
Console.WriteLine(a.GetValue());
Console.WriteLine(aa.GetValue());
Console.WriteLine(ab.GetValue());
Console.WriteLine(ac.GetValue());
Console.ReadLine();
}
}
}
class A
{
public virtual string GetValue()
{
return "A";
}
}
class AA : A
{
public override string GetValue()
{
return "AA";
}
}
class AB : A
{
public override string GetValue()
{
return "AB";
}
}
class AC : A
{
public override string GetValue()
{
return base.GetValue();
}
}
|
|
|
|
|
override.... right.
I feel like a newbie, but I guess these things happen when moving on to a new language :p
Thank you for the quick reply, you helped a lot.
Gonçalo A.
|
|
|
|