|
Read my article on how to use google ?
http://www.google.com.au/search?sourceid=navclient&ie=UTF-8&rlz=1T4ADBS_enAU225AU226&q=C%23+Excel[^] is bursting with info.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
Then you can't possibly want to do what you seem to be saying.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I have this comma delimited file sent to me. I can open it in excel straightaway by downloading. But I am trying to understand how I can access it using my C# program codes. I have managed to open it quiet well in a textbox. Now since it already a comma delimited file I am trying to find a way of getting to it through my c# program and reading it as an excel thing using my c# program.
|
|
|
|
|
You wish to load the CSV file into your application with a grid view like in excel?
If so you need to read the CSV data into a dataset and then point that dataset to a data grid view control and it'll display just fine. To make changes and save them you'd need to serialize and convert the dataset back into CSV.
If you want to just open it in excel (if installed) you can just do the following:
string csvFilePath = "C:\myFile.csv";
using (Process MSexcel = new Process())
{
MSexcel.StartInfo.FileName = csvFilePath;
MSexcel.Start();
}
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|
I have a data in a list, and l want to print to data form. How can l do this in C#. Thank you .
|
|
|
|
|
Is this an ASP.NET app ? I thought you were asking ASP.NET questions earlier ?
Use a datagrid. And buy a book, this is a very basic question.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks for your response.
|
|
|
|
|
MessageBox.Show("Hellow")
it will print the hellow message in the popup messagebox.
or try Sytem.Console.Writeln("hellow");
|
|
|
|
|
Hi,
I am builting a server\client chat aplication.
One problem as appear to me when transfering data between server and client. I m not only trying to transfer messages data but also settings data, like for exemple the list(edit a listbox) of clients logged in!!!
I solved it in a not very elegant way:
1) server sends string data (01hello jack!!!),(04Boris),(09Boris),(02Hello Diana!)
2) client reads it with the help of the substring funtion (01:Private Message),(04:Login),(09:Logout),(02:Global Message)
I use it because i only send strind data?
Here´s my way of solving the problem!!!
Does anyone uses a different way?
|
|
|
|
|
Not me, personally.
String Manipulation (.Substring, .Replace) ftw!
-= Reelix =-
|
|
|
|
|
I'm trying to create an application that rotates an image based on the an angle created by your mouse from a certain point on the form.
I create a form, 500x500, and specify the point to get my angle from at (500,250). From that, everytime the mouse is moved, I grab the current x and y position of the mouse, and then using trig, try to find the angle from the point specified on the form to the mouse. However, I'm not sure if I'm approaching this correctly. Whenever I test my application, the image does rotate, however, it's very "hit-and-miss", and coincidentally, is even quite dodgy in some areas (it wont rotate in certain areas on the form). To rotate the image, I'm using matrices and I haven't had a problem rotating the image using a counter for the angle within a timer; but when I try to use mouse move... well you can only understand where I'm coming from.
Note: I commented out another method I thought off in order to prevent large jumps in the angles, however, it seems to do worse then the other method
private void Form1_MouseMove(object sender, MouseEventArgs e)<br />
{<br />
try<br />
{<br />
<br />
rotationz = true;<br />
angle = (float)((Math.Atan((500 - e.Y) / (250 - e.X))) * (-180 / Math.PI));<br />
Invalidate();<br />
<br />
}<br />
catch (DivideByZeroException)<br />
{<br />
}<br />
}
I'm somewhat of a beginner, so if it is possible to keep it simplified/dumb downed so that it's easier for me to understand, it would be much appreciated! Thanks in advance
|
|
|
|
|
Does your paint code always rotate the original image, or does it rotate the already rotated image ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
it rotates the original image, not the rotated one, so i don't have to subtract the last angle from the current one. I got something working actually, but it's a bit ridiculous, perhaps anyone else could simplify my code?
try<br />
{<br />
<br />
if (e.X > 250 && e.X < lastx)<br />
{<br />
curangle = (int)((Math.Atan((500 - e.Y) / (250 - e.X))) * (-180 / Math.PI));<br />
}<br />
else if (e.X > 250 && e.X > lastx)<br />
{<br />
curangle = (int)((Math.Atan((500 - e.Y) / (250 - e.X))) * (180 / Math.PI));<br />
curangle = -180 - curangle;<br />
}<br />
if (e.X < 250 && e.X < lastx)<br />
{<br />
curangle = (int)((Math.Atan((500 - e.Y) / (250 - e.X))) * (180 / Math.PI));<br />
curangle = 180 - curangle;<br />
}<br />
else if (e.X < 250 && e.X > lastx)<br />
{<br />
curangle = (int)((Math.Atan((500 - e.Y) / (250 - e.X))) * (-180 / Math.PI));<br />
}<br />
<br />
}<br />
catch (DivideByZeroException)<br />
{
For some of those, you'll notice my curangle is touched upon once again within the if statements; I only did that in order to account for both positive and negative rotations left and right. It's kinda long though, so any suggestions would be great ! Thanks again for the help guys!
|
|
|
|
|
|
Hello,
I have a MDI parent form that has some children,application requires
that the child form appear only one time and if it is minimized it restores its position if there is any try to open a new instance of it.
I don't know how to let the child form to restore its position after being minimized?
Thanks.
Dad
|
|
|
|
|
First of all at child form try this code:
<br />
this.LocationChanged += new System.EventHandler(this.ChildFormLocationChanged);
and then write:
private void ChildFormLocationChanged(object sender, EventArgs e)<br />
{<br />
if (this.WindowState != FormWindowState.Minimized)<br />
{<br />
x = this.Location.X; <br />
y = this.Location.Y;<br />
}<br />
else <br />
{<br />
MessageBox.Show(x.ToString() + " " + y.ToString());<br />
}<br />
}
Hope, this might help you.
Njoy coding..
Anindya Chatterjee
|
|
|
|
|
Hi All,
Ive been doing alot of ready about backgroud workers and would like to learn how they work and get one into my small simple application i am building. The problem is that i am finding it hard to understand how to get it into my applciation and how they really work. I was wondering if someone could point me in the direction or even give me an example of it working in my code!
bear in mined that i am a beginner to programming, not just C# so any help would be very much appreciated!
My Port Scanner Application:
[Form1.cs]
using System;<br />
using System.Collections.Generic;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Net.Sockets;<br />
using System.IO;<br />
<br />
namespace GUI_Port_Scanner<br />
{<br />
public partial class Form1 : Form<br />
{<br />
string _ip;<br />
int _startPort;<br />
int _endPort;<br />
string fileName = "scan_results.txt";<br />
TcpClient TcpScan = new TcpClient();<br />
<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
_ip = "";<br />
_startPort = 0;<br />
_endPort = 0;<br />
}<br />
<br />
private void startScanBtt_Click(object sender, EventArgs e)<br />
{<br />
<br />
if (prevItems.Checked == true)<br />
{<br />
listBoxClosed.Items.Clear();<br />
listBoxOpen.Items.Clear();<br />
}<br />
<br />
_ip = hostTxt.Text;<br />
_startPort = Int32.Parse(startPortTxt.Text);<br />
_endPort = Int32.Parse(endPortTxt.Text);<br />
<br />
for (int _currentPort = _startPort; _currentPort <= _endPort; _currentPort++)<br />
{<br />
try<br />
{<br />
TcpScan.Connect(_ip, _currentPort);<br />
listBoxOpen.Items.Add(" => Port " + _currentPort + " is open.");<br />
}<br />
catch<br />
{<br />
listBoxClosed.Items.Add(" => Port " + _currentPort + " is closed.");<br />
}<br />
}<br />
<br />
toFileBtt.Enabled = true;<br />
}<br />
<br />
private void toFileBtt_Click(object sender, EventArgs e)<br />
{<br />
StreamWriter writeTo = new StreamWriter(fileName, true);<br />
if (listBoxOpen.Items.Count != 0)<br />
{<br />
writeTo.WriteLine();<br />
writeTo.WriteLine(" Open Ports:");<br />
writeTo.WriteLine("*-----------------------------*");<br />
}<br />
foreach (object item in listBoxOpen.Items)<br />
{<br />
writeTo.WriteLine(item.ToString());<br />
}<br />
if (listBoxClosed.Items.Count != 0)<br />
{<br />
writeTo.WriteLine();<br />
writeTo.WriteLine(" Closed Ports:");<br />
writeTo.WriteLine("*-----------------------------*");<br />
}<br />
foreach (object item in listBoxClosed.Items)<br />
{<br />
writeTo.WriteLine(item.ToString());<br />
}<br />
writeTo.Close();<br />
}<br />
}<br />
}
[Form1.Designer.cs]
namespace GUI_Port_Scanner<br />
{<br />
partial class Form1<br />
{<br />
private System.ComponentModel.IContainer components = null;<br />
<br />
protected override void Dispose(bool disposing)<br />
{<br />
if (disposing && (components != null))<br />
{<br />
components.Dispose();<br />
}<br />
base.Dispose(disposing);<br />
}<br />
<br />
#region Windows Form Designer generated code<br />
<br />
private void InitializeComponent()<br />
{<br />
this.hostTxt = new System.Windows.Forms.TextBox();<br />
this.startPortTxt = new System.Windows.Forms.TextBox();<br />
this.label1 = new System.Windows.Forms.Label();<br />
this.label2 = new System.Windows.Forms.Label();<br />
this.endPortTxt = new System.Windows.Forms.TextBox();<br />
this.label3 = new System.Windows.Forms.Label();<br />
this.startScanBtt = new System.Windows.Forms.Button();<br />
this.listBoxOpen = new System.Windows.Forms.ListBox();<br />
this.listBoxClosed = new System.Windows.Forms.ListBox();<br />
this.label4 = new System.Windows.Forms.Label();<br />
this.label5 = new System.Windows.Forms.Label();<br />
this.prevItems = new System.Windows.Forms.CheckBox();<br />
this.toFileBtt = new System.Windows.Forms.Button();<br />
this.SuspendLayout();<br />
this.hostTxt.Location = new System.Drawing.Point(72, 12);<br />
this.hostTxt.Name = "hostTxt";<br />
this.hostTxt.Size = new System.Drawing.Size(196, 20);<br />
this.hostTxt.TabIndex = 1;<br />
this.startPortTxt.Location = new System.Drawing.Point(72, 38);<br />
this.startPortTxt.Name = "startPortTxt";<br />
this.startPortTxt.Size = new System.Drawing.Size(65, 20);<br />
this.startPortTxt.TabIndex = 2;<br />
this.label1.AutoSize = true;<br />
this.label1.Location = new System.Drawing.Point(12, 15);<br />
this.label1.Name = "label1";<br />
this.label1.Size = new System.Drawing.Size(32, 13);<br />
this.label1.TabIndex = 3;<br />
this.label1.Text = "Host:";<br />
this.label2.AutoSize = true;<br />
this.label2.Location = new System.Drawing.Point(11, 41);<br />
this.label2.Name = "label2";<br />
this.label2.Size = new System.Drawing.Size(54, 13);<br />
this.label2.TabIndex = 4;<br />
this.label2.Text = "Start Port:";<br />
this.endPortTxt.Location = new System.Drawing.Point(203, 38);<br />
this.endPortTxt.Name = "endPortTxt";<br />
this.endPortTxt.Size = new System.Drawing.Size(65, 20);<br />
this.endPortTxt.TabIndex = 5;<br />
this.label3.AutoSize = true;<br />
this.label3.Location = new System.Drawing.Point(144, 42);<br />
this.label3.Name = "label3";<br />
this.label3.Size = new System.Drawing.Size(51, 13);<br />
this.label3.TabIndex = 6;<br />
this.label3.Text = "End Port:";<br />
this.startScanBtt.Location = new System.Drawing.Point(274, 12);<br />
this.startScanBtt.Name = "startScanBtt";<br />
this.startScanBtt.Size = new System.Drawing.Size(79, 46);<br />
this.startScanBtt.TabIndex = 7;<br />
this.startScanBtt.Text = "Scan";<br />
this.startScanBtt.UseVisualStyleBackColor = true;<br />
this.startScanBtt.Click += new System.EventHandler(this.startScanBtt_Click);<br />
this.listBoxOpen.BackColor = System.Drawing.SystemColors.MenuText;<br />
this.listBoxOpen.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));<br />
this.listBoxOpen.ForeColor = System.Drawing.Color.LimeGreen;<br />
this.listBoxOpen.FormattingEnabled = true;<br />
this.listBoxOpen.ItemHeight = 16;<br />
this.listBoxOpen.Location = new System.Drawing.Point(12, 104);<br />
this.listBoxOpen.Name = "listBoxOpen";<br />
this.listBoxOpen.Size = new System.Drawing.Size(168, 164);<br />
this.listBoxOpen.TabIndex = 8;<br />
this.listBoxClosed.BackColor = System.Drawing.SystemColors.MenuText;<br />
this.listBoxClosed.Font = new System.Drawing.Font("Arial", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));<br />
this.listBoxClosed.ForeColor = System.Drawing.Color.DarkRed;<br />
this.listBoxClosed.FormattingEnabled = true;<br />
this.listBoxClosed.ItemHeight = 16;<br />
this.listBoxClosed.Location = new System.Drawing.Point(186, 104);<br />
this.listBoxClosed.Name = "listBoxClosed";<br />
this.listBoxClosed.Size = new System.Drawing.Size(167, 164);<br />
this.listBoxClosed.TabIndex = 9;<br />
this.label4.AutoSize = true;<br />
this.label4.Location = new System.Drawing.Point(14, 88);<br />
this.label4.Name = "label4";<br />
this.label4.Size = new System.Drawing.Size(63, 13);<br />
this.label4.TabIndex = 10;<br />
this.label4.Text = "Open Ports:";<br />
this.label5.AutoSize = true;<br />
this.label5.Location = new System.Drawing.Point(188, 88);<br />
this.label5.Name = "label5";<br />
this.label5.Size = new System.Drawing.Size(69, 13);<br />
this.label5.TabIndex = 11;<br />
this.label5.Text = "Closed Ports:";<br />
this.prevItems.AutoSize = true;<br />
this.prevItems.Location = new System.Drawing.Point(73, 65);<br />
this.prevItems.Name = "prevItems";<br />
this.prevItems.Size = new System.Drawing.Size(122, 17);<br />
this.prevItems.TabIndex = 13;<br />
this.prevItems.Text = "Clear Previous Items";<br />
this.prevItems.UseVisualStyleBackColor = true;<br />
this.toFileBtt.Enabled = false;<br />
this.toFileBtt.Location = new System.Drawing.Point(274, 61);<br />
this.toFileBtt.Name = "toFileBtt";<br />
this.toFileBtt.Size = new System.Drawing.Size(79, 23);<br />
this.toFileBtt.TabIndex = 14;<br />
this.toFileBtt.Text = "Copy to File";<br />
this.toFileBtt.UseVisualStyleBackColor = true;<br />
this.toFileBtt.Click += new System.EventHandler(this.toFileBtt_Click);<br />
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);<br />
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;<br />
this.ClientSize = new System.Drawing.Size(365, 347);<br />
this.Controls.Add(this.toFileBtt);<br />
this.Controls.Add(this.prevItems);<br />
this.Controls.Add(this.label5);<br />
this.Controls.Add(this.label4);<br />
this.Controls.Add(this.listBoxClosed);<br />
this.Controls.Add(this.listBoxOpen);<br />
this.Controls.Add(this.startScanBtt);<br />
this.Controls.Add(this.label3);<br />
this.Controls.Add(this.endPortTxt);<br />
this.Controls.Add(this.label2);<br />
this.Controls.Add(this.label1);<br />
this.Controls.Add(this.startPortTxt);<br />
this.Controls.Add(this.hostTxt);<br />
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;<br />
this.Name = "Form1";<br />
this.Text = "Input | Output - Port Scanner";<br />
this.Load += new System.EventHandler(this.Form1_Load);<br />
this.ResumeLayout(false);<br />
this.PerformLayout();<br />
<br />
}<br />
<br />
#endregion<br />
<br />
private System.Windows.Forms.TextBox hostTxt;<br />
private System.Windows.Forms.TextBox startPortTxt;<br />
private System.Windows.Forms.Label label1;<br />
private System.Windows.Forms.Label label2;<br />
private System.Windows.Forms.TextBox endPortTxt;<br />
private System.Windows.Forms.Label label3;<br />
private System.Windows.Forms.Button startScanBtt;<br />
private System.Windows.Forms.ListBox listBoxOpen;<br />
private System.Windows.Forms.ListBox listBoxClosed;<br />
private System.Windows.Forms.Label label4;<br />
private System.Windows.Forms.Label label5;<br />
private System.Windows.Forms.CheckBox prevItems;<br />
private System.Windows.Forms.Button toFileBtt;<br />
}<br />
}<br />
Also any critisism on any other aspect of the program would be great, along with tips and tricks
Thank you very much!
Relentless.
|
|
|
|
|
Threading is a complex concept to handle early on.
Never post your designer.cs file, the IDE generates that.
I see no progress bar or threading code here. Use the BackgroundWorker class, it's really easy, and it has a report progress event you can use to run a progress bar.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks for the quick reply,
Noted about the designer.cs file and i have not put any background worker or progress bar in yet, i will do some more research then and get back to you.
Thanks again,
Relentless.
Knowledge is Power.
|
|
|
|
|
|
Here are a selection of links which helped me learn about threading.
What I would say is don't let what seems like a complex area put you off learning about threading(the basics are just that - basic).
Threading is a basic requirement for decent user interfaces - running processes in the background while allowing the user to still access a form.
Jump in and have fun:
Codeproject threading demonstration
Good General Tutorial on threading
Codeproject sync async threads
Regards
Guy
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
Thank you very muc for your quick replys,
So far i understand that i will need to create a function that will initialize the background worker, i will then need to put the code i want it to do in the background i.e:
for (int _currentPort = _startPort; _currentPort <= _endPort; _currentPort++)<br />
{<br />
try<br />
{<br />
TcpScan.Connect(_ip, _currentPort);<br />
listBoxOpen.Items.Add(" => Port " + _currentPort + " is open.");<br />
}<br />
catch<br />
{<br />
listBoxClosed.Items.Add(" => Port " + _currentPort + " is closed.");<br />
}<br />
}
That is as far as i have got thanks a lot for the resorces i will keep reading and playing around with the code. Still a bit confusing.
Relentless.
Knowledge is Power.
|
|
|
|
|
One important point - you can't manipulate UI stuff in the thread, you need instead to send messages to the Progress event, which runs on the main thread, and can update your UI.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
OK thanks again,
Will have to do a lot more reading thanks again.
Relentless.
Knowledge is Power.
|
|
|
|
|