|
|
I'm creating a program in C# that do not allow intersecting lines. How will I modify my code? Thank you.
I've already uploaded the whole source code of my program HERE (http://www.mediafire.com/?2g52fiqanma3hkx[^]) for you to check the other class I've included.But here's the code for the drawing process:
<pre lang="c#">
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form3 : Form
{
private Boolean _calculateDouglasPeuckerReduction = false;
private List<WindowsFormsApplication2.PointEnhanced> _amerenPoints = new List<WindowsFormsApplication2.PointEnhanced>();
public Form3()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
List<System.Drawing.Point> drawingPoints = new List<System.Drawing.Point>();
foreach (WindowsFormsApplication2.PointEnhanced point in _amerenPoints)
{
drawingPoints.Add(new System.Drawing.Point(Convert.ToInt32(point.X), Convert.ToInt32(point.Y)));
}
if (drawingPoints.Count > 2)
{
e.Graphics.DrawLines(new Pen(Brushes.Black, 2), drawingPoints.ToArray());
lblOriginal2.Text = drawingPoints.Count.ToString();
if (_calculateDouglasPeuckerReduction)
{
List<WindowsFormsApplication2.PointEnhanced> points = Utility2.DouglasPeuckerReduction(_amerenPoints, Convert.ToDouble(nudTolerance2.Value));
drawingPoints = new List<System.Drawing.Point>();
foreach (WindowsFormsApplication2.PointEnhanced point in points)
{
drawingPoints.Add(new System.Drawing.Point(Convert.ToInt32(point.X), Convert.ToInt32(point.Y)));
}
e.Graphics.DrawLines(new Pen(Brushes.Red, 2), drawingPoints.ToArray());
lblSimplified2.Text = drawingPoints.Count.ToString();
}
}
base.OnPaint(e);
}
private void Form3_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_amerenPoints.Add(new WindowsFormsApplication2.PointEnhanced(e.X, e.Y));
this.Invalidate();
}
}
private void Form3_MouseUp(object sender, MouseEventArgs e)
{
_calculateDouglasPeuckerReduction = true;
this.Invalidate();
}
private void Form3_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_amerenPoints.Clear();
_calculateDouglasPeuckerReduction = false;
}
}
private void nudTolerance2_ValueChanged(object sender, EventArgs e)
{
this.Invalidate();
}
private void Form3_Load(object sender, EventArgs e)
{
}
}
}
|
|
|
|
|
Please give more detail about what problem you are trying to solve, and why your code does not work.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
You need to find a solution for two equations with two unknown variables.
here's a sample[^].
If it has a solution, they intersect, if not they don't.
Hope this helps.
V.
|
|
|
|
|
One negative sentence does not constitute a program specification, so I can't help you out; please explain what your program is supposed to do, and how it deviates from your expectations.
BTW: you should keep Paint handlers as simple as possible, since it probably will be called a large number of times when some window activity occurs on your system. Whatever needs to be calculated, should be calculated in advance. And memory allocations in there should be minimal too, example: don't call ToArray() in a Paint handler. Finally, objects that offer a public Dispose() method should be disposed of, which you don't in e.Graphics.DrawLines(new Pen... ; it is much better to create such small objects once, and keep them around as class members (say "blackPen2" and "redPen2").
|
|
|
|
|
hello word of Codeproject!
i have windows app (C#) with sql server 2008 and wanna to convert it to android so i can use my program on my htc.
what is the solution ?
thanks!
|
|
|
|
|
Two simple steps:
1. Learn Android
2. Convert the program
Done!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
do we have some app that can convert it to android (monodroid)?
|
|
|
|
|
No there isn't. A touch based app is a lot different to a desktop app. You'll have to rewrite, especially as you are using SQL Server.
|
|
|
|
|
+5
|
|
|
|
|
No, there is no tool to do the conversion for you.
You'll have to rewrite the entire app from scratch, by hand.
|
|
|
|
|
I would suspect a potential redesign as well since if the Android phone can access the database then so can any internet based app and exposing a database directly to the internet is not something that one should do casually.
|
|
|
|
|
Probably the easiest way is create a Web GUI for the existing application and use the HTC to browse to that webapp. (if that is an option)
V.
|
|
|
|
|
Hi,
This has baffled me for hours ...
I wrote an addin for an existing program, and when I launch it, it steals focus away from the parent program, even when it is minimized, which I don't want.
I would prefer for it to not steal focus, so that I can click on menu items of the parent program regardless, or for it to at least release focus when I minimize it. Is this possible?
Thanks for reading.
|
|
|
|
|
What do you mean by an addin for an existing program?
turbosupramk3 wrote: when I launch it, it steals focus away from the parent program
That's the way Windows is designed to work, why would you not expect it?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
It's not that I don't expect it, it's that I don't want it or I at least want it to release focus if I minimize the window
|
|
|
|
|
turbosupramk3 wrote: I at least want it to release focus if I minimize the window
Then you need to capture that action and somehow pass the focus back to the parent. However, you still have not explained how all this fits together so I cannot offer much more than that.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I used Form.Show() instead of Form.ShowDialog() after I found out one was for a modal form and one for a non-modal form. This seems to have fixed that issue.
Thank you for your help.
|
|
|
|
|
It very difficult to decipher what question you are really asking but for what it's worth here is my interpretation.
1) By "addin" you mean an assembly containing the definition of a form.
2) By "launch" you mean display the form.
3) By "steal focus" you mean that the main form of the application is inaccessible until the addin's form is closed.
Based on (3) the addin's form has been displayed via ShowDialog and what you observe is the expected behaviour.
One part of the solution to your problem will be to display the addin form non-modally via the Show method.
However giving the user the ability to access both the addin and main forms will present new problems and you will need to decide what actions are allowable when the addin form is open. For example, will it be reasonable to let the user terminate the application?
Alan.
|
|
|
|
|
Hi Alan,
Thank you for the reply. I did us Form.Show(); instead of Form.ShowDialog(); and ironically enough I now have the exact opposite of my problem. My form is now non-modal, which is what I want, but I would like for it to be brought to the foreground.
1) It is an addin DLL that has a configuration form inside of it. The form configures some of the DLL settings, for when it is ran inside of the parent application.
2) Yes
3) Yes because of ShowDialog();
It is reasonable for the user to terminate the form and dialog, I would just like it to be brought to the foreground now when the form is displayed.
I just tried this code, and it seems to be working ... what do you think?
this.TopMost = true;
this.Focus();
this.BringToFront();
this.TopMost = false;
|
|
|
|
|
Yes, the TopMost trick would be a fix it but it's interesting to consider why it is needed.
Your observation of the configuration form behind the main form suggests that the main form is the last one to be shown. The desired order can probably be restored by deferring creation of the config form to the main form's Shown event.
An alternative would be to set the main form as the the owner of the config form, but then it would not be possible to bring the main form to the front, which may not be what you want.
Alan.
|
|
|
|
|
Hi Alan,
Thanks for the reply. I'm willing to give that a try, how do I set the main form as owner?
|
|
|
|
|
I figured out why the main form loaded last, and have corrected it. It works like it should now, thank you.
|
|
|
|
|
I just did some tests by starting notepad from a c# windows form, and yes notepad retains activated status. You can get round this by doing the
following;
(The test form has a textbox and a button)
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process p;
p = System.Diagnostics.Process.Start("notepad.exe");
p.WaitForInputIdle();
this.Activate();
textBox1.Focus();
}
Your form will now retain Activated status, and notepad will not be the current active window.
|
|
|
|
|
Thank you Dave, I will play around with that now.
|
|
|
|