|
Im using C# .NET 1.1. Im scratching my head over getting the regular expression to replace only a single instance of my pattern:
searchResults = Regex.Replace(searchResults, @"(]*)>)", "$1", RegexOptions.IgnoreCase);
searchResults contains HTML tags possibly containing two or more tags. I would like to append a tag just after the first and thats it. My above regex will append the tag after every on the page. How do i get it to do only the first instance and stop?
|
|
|
|
|
Create a RegEx object so that you can specify the options using the Options property, then the number of replacements in the call:
RegEx addHidden = new Regex.Replace(@"(<form ([^>]*)>)");<br />
addHidden.Options = RegexOptions.IgnoreCase;<br />
searchResults = addHidden.Replace(searchResults, "$1<input type=hidden name='mID' value=" + this.ModuleID + ">", 1);
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
Hello; Which event do I want for the following:
I would like to have a user click and hold the mouse button (left) down, and while it is held, they move a picturebox (c) around at the mouses position. Once they release, the box stays where it is.
My question is, which event is this? I didn't understand the drag events... So if anyone could help, I'd be greatly appreciative. Thanks in advance.
The most knowledge doesn't mean the most wise...
|
|
|
|
|
You'll need to handle 3 events: MouseDown , MouseMove and MouseUp .
/ravi
|
|
|
|
|
Could you give me an example?
The most knowledge doesn't mean the most wise...
|
|
|
|
|
See this[^] article. Although it's written in VB, the principles directly apply to your task.
/ravi
|
|
|
|
|
private Point offset = new Point(0);
private bool mouseDown = false;
private Point pt = new Point(0);
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
mouseDown = true;
offset.X = e.X;
offset.Y = e.Y;
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
mouseDown = false;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (mouseDown)
{
pt.X += e.X - offset.X;
pt.Y += e.Y - offset.Y;
pictureBox1.Location = pt;
}
}
Good luck,
Mike
-- modified at 18:38 Saturday 20th October, 2007
Life is not measured by the number of breaths we take, but by the
moments that take our breath away. "George Carlin"
|
|
|
|
|
Why doesn't this make a line that starts at 0,0, and ends where he mouse is? It worked a bit earlier, but now it doesn't.
private void Form1_Paint(object sender, PaintEventArgs e)<br />
{<br />
int x1 = MousePosition.X;<br />
int y1 = MousePosition.Y;<br />
<br />
Graphics A = e.Graphics;<br />
Pen BluePen = new Pen(Color.Blue, 3);<br />
A.DrawLine(BluePen, 0, 0, x1, y1);<br />
<br />
A.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;<br />
}<br />
<br />
private void Animator_Tick(object sender, EventArgs e)<br />
{<br />
this.Invalidate();<br />
}
This only works works if I invalidate in Form1_Paint , but then I get a low-quality image. Thanks in advance.
The most knowledge doesn't mean the most wise...
|
|
|
|
|
MasterSharp wrote: but now it doesn't.
what does "it doesn't" mean?
|
|
|
|
|
It means, that the form doesn't Invalidate() as far as I can tell. If you try that code (with a timer named Animator) and copy and paste it, you'll know what I mean. I want there to be a line connected to the cursor from 0,0 (don't ask why).
The most knowledge doesn't mean the most wise...
|
|
|
|
|
Hi,
some remarks:
1. Are you sure your tick is executed at all? Maybe you did something wrong with the timer.
2. Invalidate() will fail when not executed by the thread that created its object (this).
Make sure you are using the right kind of timer.
3. It is a bad idea to have a Paint routine that uses volatile inputs such as MousePosition:
the Paint handler will be called when you call Invalidate(), but also when Windows decides
it is necessary (e.g. because you are dragging another window over it, at which time the
mouse position does not make sense to your Paint at all).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
|
Im writing a console application programme where the user has input 5 number which are loaded into an array list. Now after thios has happened the user selects one of 2 options. 1 is to sort them in an ascending order and 2; descending. can you help by showing me the code to sort the numbers in the array.
Thanx
Daniel
|
|
|
|
|
Hi Daniel,
This sounds like homework to me so best I don't just give you the answer, better if I teach you to fish eh?
Firstly, I'd say why are you using an arraylist if you know they are all going to be integers and you know how many there are? Best you use int[] and save the boxing and unboxing associated with an arraylist.
Once you have done that, Google how to sort an array of integers.
--
Cheers,
Gary
http://www.garyshort.org
|
|
|
|
|
ha, thats funny!
no its not homework, practising for an exam next week, so going through some examples actually!
but since u wanna teach me to fish...
i actually dont remember why i chose to use an arraylist?! oh yes, it was so that i can use the readline() method to add the users input into the list. if u suggest that i use int[], how do i then add the users inputs as there is no add method?
|
|
|
|
|
Get the user input first, then you know how big your array has to be then add the input in the normal way.
--
Cheers,
Gary
http://www.garyshort.org
|
|
|
|
|
ye the prob is i havent done programming in a couple months so ive forgotten basics, so im not even sure how do that anymore, thats why i was looking for code so i can refresh my memory. thanx all the same though. will press on!
Dan
|
|
|
|
|
Looks like you've got your work cut out if you are going to pass this exam. How long do you have to study for it?
--
Cheers,
Gary
http://www.garyshort.org
|
|
|
|
|
this weekend, they made a mistake with my exam timetable and i was meant to have until wednesday next week, but after enquiring today i found that it is on monday. so having to cram some work in. Look it's not a hard exam, but my memory is dry as i havent done it in a couple months and have been focusing on hardware as it is part of the course i'm doing, so im just outta things you know, so trying to get my logic and problem solving skills up and going so i can hurt this exam!
|
|
|
|
|
Ok, well if you can't remember how to assign variables to elements in an array I think you have a lot of work to do. Its going to be a long week-end for you.
--
Cheers,
Gary
http://www.garyshort.org
|
|
|
|
|
ye shot, got it working now, used the int[], its storing them and getting them. just need to sort them now, have the method in place, just assigning them now. so its almost done
Thanx
Dan
|
|
|
|
|
k all sorted now, sorting it perfectly. phew, that was stressful, wat a mission. cant believe it took me so long, im really rusty!
|
|
|
|
|
Glad to have been of help!
--
Cheers,
Gary
http://www.garyshort.org
|
|
|
|
|
what u people r doing i dont know..
this is a class room discusion or what..
sh*t...........
|
|
|
|
|
Daniel_Logan wrote: no its not homework, practising for an exam next week
Same thing, isn't it?
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|