|
This looks like a good approach. I am really new to C# (after 10 years away), do you have a coded example?
|
|
|
|
|
Its basic maths buddy..
Let me try to write a simple app for you.
Distance between points (5,5) and the origin (0,0) should be:
public CalculateDistance()
{
double D;
int x1=5;
int x2=0;
int y1=5;
int y2=0;
D=Math.Abs(((x1-x2)^2)+((y1-y2)^2))^(1/2);
Console.WriteLine(D);
Console.ReadKey();
}
The above should do good.
-Anurag
|
|
|
|
|
Your question states that what you want is the size of the distance between two x co-ordinates, and the size of the distance between two y co-ordinates, but your code suggests that what you really want is the length of a line between the two points: which is the hypotenuse of a right triangle.
Assuming it's obvious to you how to get the distances on x, and y, and since you already know how to calculate a hypotenuse, then the answer to your question is: no, C# does not contain a built-in function to calculate a hypotenuse. Yes, you have to code it.
And, the real answer to your question is that you need to focus on mastery of the basic mathematics operators in C#, and you need to examine the functions available in the Math library, and get familiar with what it offers, and what it does not offer.
A small effort on your part now to learn the basic mathematics operators, and commonly used functions in the Math library, will enable you to express any equation.
It's a good idea to think carefully about what you are asking, before you post a question.
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
I am new to C#. I am not sure whether I am approaching my classes in the right way. I want my main class to act as a stem that activates other classes that performs various tasks like retrieving information or writing to file or performing calculation. I am not sure how to interrelate the classes. I know that some classes have to be public etc.
I was thinking that this stem class would take on the form:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Stem
{
static void Main(string[] args)
{
}
}
}
Firstly I want to know if I am approaching the problem in the right way.
Secondly I would like bits of code that would help me build this stem (if poss).
I would appreciate any help given.
|
|
|
|
|
Hmmm, I think you need to step back here as it sounds like you're trying to run before you understand the basics of building C# applications. Before you try building your own application, I'd recommend downloading and reading .NET Book Zero[^] by Charles Petzold. It's free, and the samples should help to teach you what you need to know.
|
|
|
|
|
I can see that I need to modify my approach. What approach to this would you take? Would you suggest that all the tasks that are on the list act as super-classes of the class that takes the main argument?
|
|
|
|
|
You're asking for a design when the problem isn't clear. That's why I suggest you start by reading the book.
|
|
|
|
|
I'm really short of time on this task.
The task is to take a csv file.
Process a list of x,y specified coordinate points.
Work out the distance between all these coordinate points.
Print results to file
|
|
|
|
|
Then, realistically speaking, you're stuffed. Without a basic understanding of the language, you aren't going to be able to write something that fulfils the criteria you laid out. Theoretically, you could do all of this procedurally in the Main method, but as that violates what I'm assuming the test is about, you would fail. At a high level, I would expect that they are looking at using an architecture similar to this:
A class that encapsulates a point (perhaps you could call it Point).
A class that, given a CSV file, would read it in and return a list of these points
Where it gets more subjective is, do you put the calculation of the distance into the point class, or is it in the class that contains the points? I'll leave you to decide that one.
What I wouldn't be worrying about here is superclass x or subclass y. That's irrelevant for a task like this.
|
|
|
|
|
This is similar to a programming test Sage used to do, just more maths than word based.
My guess is he's in the middle of an interview, given how he is short of time on this task....
|
|
|
|
|
How about this for a plan?
nested classes
class Z
class Y
class X
class V
class U
|
|
|
|
|
listViewNV_KeyPress function it does not run ? I am using C # 2005, I checked the KeyPress event that it does not run listViewNV_KeyPress function, the function is similar: KeyDown and KeyUp run normally
private void listViewNV_KeyPress (object sender, KeyPressEventArgs e)
{
...
}
|
|
|
|
|
|
Hi friends :
I want to know that how can I access to a column contents?
because "Gridcol" just returns columns header and in "Finaldgv" just columns header will be added. Actually I need each columns header text with its contents. here ,I indicated the main line which copy "Gridcol" into "Finaldgv" by "****"
this is my code :
private static DataGridView Firstdgv;
private static DataGridView Finaldgv = new DataGridView();
private static List<string> SelectedColumns = new List<string>();
private static List<string> AvailableColumns = new List<string>();
public void Print_DataGridView(DataGridView dgv1)
{
PrintPreviewDialog ppvw;
try
{
Firstdgv = dgv1;
AvailableColumns.Clear();
foreach (DataGridViewColumn c in Firstdgv.Columns)
{
if (!c.Visible) continue;
AvailableColumns.Add(c.HeaderText);
}
FrmPrintOptions dlg = new FrmPrintOptions(AvailableColumns);
if (dlg.ShowDialog() != DialogResult.OK) return;
PrintTitle = dlg.PrintTitle;
PrintAllRows = dlg.PrintAllRows;
FitToPageWidth = dlg.FitToPageWidth;
SelectedColumns = dlg.GetSelectedColumns();
ppvw = new PrintPreviewDialog();
Finaldgv.AutoGenerateColumns = false;
foreach (DataGridViewColumn GridCol in Firstdgv.Columns)
{
if (!GridCol.Visible) continue;
if (!SelectedColumns.Contains(GridCol.HeaderText)) continue;
Finaldgv.Columns.Add((DataGridViewColumn)GridCol.Clone()); ****
}
DGVPrinter obj = new DGVPrinter();
obj.PrintPreviewDataGridView(Finaldgv);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
|
|
|
|
|
If you are looking for the values within the DataGridView fro a particular column, you don't access them via the Column directly: they are all organised by Row, then by column within the row.
So if you want the column header and all the values it contains, you can pick up the header from the Column as you are doing, but you then need to loop through the Rows property to collect the values from the DataGridViewRow.Cells collection - each entry in which contains the appropriate Column value.
This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre.
Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.
|
|
|
|
|
can you explain more in details? because I am beginner how can I apply your solution in my code? can you write it for me?
thank you so much.
|
|
|
|
|
You really shouldn't need more details, but...
Lets just look at your questions in reverse order:
babak14 wrote: can you write it for me?
Yes, I could. But then I'd have to send you a pro-forma invoice first, and I don't think you want to pay my rates...
babak14 wrote: how can I apply your solution in my code?
That's really down to you: I don't have an exact idea what you are trying to do, so I can't be very specific.
babak14 wrote: can you explain more in details? because I am beginner
This is the main reason I'm not giving you code: we don't don't do homework, and it isn't good for you to just be given a solution. You learn more by doing it yourself!
But... this might help:
Data organisation in a DataGridView (DGV for short)
Property: DataGridView.Columns
Contains a collection of DataGridViewColumn objects, each of which describes the column - the header, the column data source and so on. This does not contain any actual values displayed in the DGV.
Property: DataGridView.Rows
Contains a collection of DataGridViewRow objects, each of which holds a collection of cells, each of which corresponds to the value for that row within a column.
Property: DataGridViewRow.Cells
Contains a collection of DataGridViewCell objects, each of which holds a value for the column.
So to get all the values you loop through each row, then access the cells for that row:
(this code won't help you much in practice - it's not something we would actually do in the real world but it should demo what I mean:
foreach (DataGridViewRow row in myDataGridView.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
Console.Write("{0} ", cell.Value);
}
Console.WriteLine();
}
Run the code, and you should get the idea.
This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre.
Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.
|
|
|
|
|
thank you.
you helped me a lot
|
|
|
|
|
You're welcome!
This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre.
Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.
|
|
|
|
|
Hi,
I would like to know how can I speed up the load of the SplashScreen and then display the loading processes on it or at least display a percentage which shows the status of loading until the application is loaded.
Technology News @ www.JassimRahma.com
|
|
|
|
|
A better solution that your users would appreciate more is to actually speed up the loading of your application rather then pointing out how slow it is to start up . This is typically accomplished by:
1) lazy load / load on demand
2) background loading
3) determine what is causing the long delays and fixing it
Typically one major issue is trying to load an entire datebase into memory. Yeah, easier to code, but you don't really need an entire database at start up. Switch to stored procs and retrieve only the data you need.
|
|
|
|
|
I typically load only the master tables (those required by comboboxes throughout the app) as these are invariable quite small. I also load these asynchronously.
Rather than trying to use a progress bar (so 90s) I use a busy indicator.
Then each View/form/page loads only the content required. As Sledge pointed out this is called lazy loading (I suspect he also load the mater table as required)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I studied many questions in this forum that related to this problem.but I couldn't solve my problem.can you help me?the error happens in the line which was indicated by "****"
private static DataGridView Firstdgv;
private static DataGridView Finaldgv = new DataGridView();
private static List<string> SelectedColumns = new List<string>();
private static List<string> AvailableColumns = new List<string>();
public void Print_DataGridView(DataGridView dgv1)
{
PrintPreviewDialog ppvw;
try
{
Firstdgv = dgv1;
AvailableColumns.Clear();
foreach (DataGridViewColumn c in Firstdgv.Columns)
{
if (!c.Visible) continue;
AvailableColumns.Add(c.HeaderText);
}
FrmPrintOptions dlg = new FrmPrintOptions(AvailableColumns);
if (dlg.ShowDialog() != DialogResult.OK) return;
PrintTitle = dlg.PrintTitle;
PrintAllRows = dlg.PrintAllRows;
FitToPageWidth = dlg.FitToPageWidth;
SelectedColumns = dlg.GetSelectedColumns();
ppvw = new PrintPreviewDialog();
Finaldgv.AutoGenerateColumns = false;
foreach (DataGridViewColumn GridCol in Firstdgv.Columns)
{
if (!GridCol.Visible) continue;
if (!SelectedColumns.Contains(GridCol.HeaderText)) continue;
Finaldgv.Columns.Add(GridCol); ****
}
DGVPrinter obj = new DGVPrinter();
obj.PrintPreviewDataGridView(Finaldgv);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
|
|
|
|
|
Try:
Finaldgv.Columns.Add((DataGridViewColumn)GridCol.Clone());
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
thank you
It works
|
|
|
|