|
Even better, I've found a whole site with 645000[^] pages about it.
Simon
|
|
|
|
|
I call the below code from the MouseClick event of a control. However, it doesnt seem a good idea to be constantly creating gfx objects every time the user clicks the mouse.
private void ClickedEdge(Point mousePoint)
{
_selectedEdge = null;
Graphics gfx = this.CreateGraphics();
Rectangle clickedRect = new Rectangle(mousePoint, new Size(1, 1));
foreach (EdgeObj edge in _edgeItems)
{
Rectangle edgeRect = Rectangle.Round(edge.Region.GetBounds(gfx));
if (clickedRect.IntersectsWith(edgeRect))
{
_selectedEdge = edge;
break;
}
}
}
So, does anyone know of a better way to find out if the mouse has clicked on a line which has been drawn onto the control?
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Save the extents of all the primitives drawn (lines, rects, polygons) in a List, for example
List<Primitive> primitivesDrawn = new List<Primitive>();
with Primitive being an abstract class like this (just an example, can be done different):
public abstract class Primitive
{
public IEnumerable<Point> Points { get; set; }
public abstract bool Intersects(Point pt);
public abstract bool Intersects(Rect pt);
}
and some primitives like:
public class Line : Primitive;
public class Triangle : Primitive;
public class Rectangle : Primitive;
This data structure can be used for both drawing it to the control as well as doing intersection testing and much more.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
This could be so much more simple. The equation of a line: Y = mX + C X and Y are abvious m is the gradient and C is an offset.
So, if you can get the equation of your lines then you could use something like this:
void ClickedEdge(Point mousePoint)
{
if(mousePoint.Y == ( lineM*mousePoint.X +lineC))
}
Although you might want to check that mousePoint.Y is +/- 1 from the calculated Y position because its gonna be almost imposible to click the line exactly (since you can't click between pixels)
float Y = lineM*mousePoint.X +lineC;
Y = Y - mousePoint.Y;
Y *= Y;
if(Y <= 1)
To get the equation for your line:
m = (endY - startY)/(endX - startX);<br />
c = m*startX - startY;
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
modified on Friday, June 13, 2008 1:20 PM
|
|
|
|
|
SK Genius,
What is lineX? Below is what i have done from your suggestion.
int lineM = (edge.EndPoint.Y - edge.StartPoint.Y) / (edge.EndPoint.X - edge.StartPoint.Y);
int lineC = lineM * edge.StartPoint.X - edge.StartPoint.Y;
int lineX = 0;
if (mousePoint.Y == (lineM * lineX + lineC))
Trace.WriteLine("hit");
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Oops, not sure what i was thinking, that should just be mousePoint.X
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
SK Genius,
It doesn't seem to be working. The cal of lineM * mousePoint.X + lineC is just giving me tons of numbers that dont even come close to mousePoint.Y.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
This little test worked out:
PointF start = new Point(0, 0);
PointF end = new Point(150, 150);
float m;
float c;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawLine(Pens.Black, start, end);
}
void Form1MouseClick(object sender, MouseEventArgs e)
{
m = (end.Y - start.Y)/(end.X - start.X);
c = start.Y - m*start.X;
Y = m*e.X + c;
Y -= e.Y;
Y *= Y;
if(Y <= 5)
MessageBox.Show("Shwam");
}
Clicking within one pixel was hard(ish) 5 seems pretty good though.
Damn, I just remebered, the gradient for a verticle line would be infinite. That means that this wouldn't work for completely verticle lines.
EDIT: Although
m = (end.Y - start.Y)/(end.X - start.X);
c = start.Y - m*start.X;
Y = m*e.X + c;
Y -= e.Y;
if(-3 < Y && Y lt; 2)
MessageBox.Show("Shwam");
if(float.IsInfinity(m)) {
float X = start.X - e.X;
if(-3 < X && X < 3)
MessageBox.Show("Shwam");
}
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
We have this program(.exe) on the web where it is being downloaded by people, in the program they set their preferences. It is a program similar to Paint
The problem is that when they download a new version of our program and install it, they loose their personal preferences set in the older version. This facility was always working, till we got the new version of the program on the net.( I did it)
For the personal settings we have a file Profile.xml where all the settings get saved(in the folder bin\release and bin\Debug. We also have two other files Profile.xml_backup and ProfileInstaller.xml in the same folders which I am not sure what they do.
So guys would anyone know what changes do i have to make, and where so that the personal changes save in the new version of the program insatlled
|
|
|
|
|
I dont think I get you. You wrote this program, but you do not know how it works?
|
|
|
|
|
OK I am sorry for not being very clear. I just made a few changes to the already existing code(Bug fixes) made a new version(exe) and uploaded it on the internet.
There is also a class UserProfile.cs which is responsible for the Profile.xml file.(If that helps)
|
|
|
|
|
Sounds to me like you download Profile.xml with the new version. Also, why have the debug version available?
humayunlalzad wrote: This facility was always working, till we got the new version of the program on the net.( I did it)
Did you write it or is it a 3rd party app you are installing?
humayunlalzad wrote: We also have two other files Profile.xml_backup and ProfileInstaller.xml in the same folders which I am not sure what they do.
Have a look in them and see what they contain - probably some default settings at a guess.
Personally I would back up the profile.xml file and restore it after the new version is installed - of course, if it's a 3rd party app it may need some settings in the new file.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
The code was written in-house, but by the coders before me. We keep upgrading things, debugging the present program and upload. It is not a 3rd party app.
So how do you restore the backup of the profile.xml file in the new version thats what I want to know. We are using VS2005
And Thanx for taking the trouble
|
|
|
|
|
humayunlalzad wrote:
This facility was always working, till we got the new version of the program on the net.( I did it)
......
So guys would anyone know what changes do i have to make, and where so that the personal changes save in the new version of the program insatlled
I sort of assumed you had put the copy of a 3rd party app on the network for others to install, particularly when you asked "So guys would anyone know what changes do i have to make.."
As it is written in house and you have the source code why would anyone else know what to change? Just because someone else wrote it is no excuse, I have spent about 90% of my coding life working with other people's code (as have most professional coders), and you just have to work out whats being done.
I suggested backing up the profile and restoring it as a work around when I was under the illusion it was a bought in app. I would just do it as part of the install.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
humayunlalzad wrote: So how do you restore the backup of the profile.xml file in the new version thats what I want to know. We are using VS2005
Learn to read and understand code, or embarrass yourself by asking your boss or manager.
Just think for a bit, just HTF must we know how to fix your application???
|
|
|
|
|
This is a small start up company and I am student volunteering for this company. The only coder has gone on a vacation of Europe for 15 days and we cant contact him. The boss does not know anything.
I know Csharp code but not the installer stuff.
|
|
|
|
|
So how do expect us to know? What you described is a bespoke solution and not something I heard of, so get in touch with the holiday maker, or better, dont make releases till he is back.
|
|
|
|
|
Hi,
I have one table which contains a list of items, displayed on a datagrid in a windows form. When i double clicked to select a particular item, the details of that item will be shown in a new form. I can change the details of that item, say quantity and color. Or i can also add in a new item to the item list. My question is how to merge back this table to the previous table so that the item list can show both updated item and newly added item on the datagrid?
Thank you.
Keen
modified on Friday, June 13, 2008 10:22 AM
|
|
|
|
|
DataSet.Merge() not working?
Maybe loop through the rows and overwrite with the other.
|
|
|
|
|
Hi friends.
I have a XML file like this :
<node name="browser"><br>
<BookMark name="Mozilla1" Href="http://..../"/><br>
<BookMark name="Mozilla2" Href="http://..../"/><br>
<BookMark name="Mozilla3" Href="http://..../"/><br>
</node></br></br></br></br>
I want read the node with "Mozilla2" attribute , but I don't know how I can ?
Can you help me ?
Sorry for my English. I'm a freshman .
|
|
|
|
|
Read about XPath, I cant give you exactly what you need, but that is what you want to use
|
|
|
|
|
Thanks leppie. Can you write sample code or reference ?
Sorry for my English. I'm a freshman .
|
|
|
|
|
|
Hi,
I am developing an app using C#, asp.net and vs2008, i want to replace the current doctype
[!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ]
with a different version
[!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"]
when specific pages are displayed, so im just wondering if this is possible and if so what i need to be searching for?
Thanks in advance
Tim
|
|
|
|
|
You want to change this at runtime?
Maybe a placeholder or a literal maybe?
|
|
|
|