|
|
have you tried to run Notepad like this
process.start("Notepad.exe");
does that work?
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
yes it works and also it works like this process.start("Notepad.exe","c:\\text.txt");
|
|
|
|
|
Hi Folks,
I Need to print a Binary TREE like so:
10
/ \
5 15
/ / \
2 14 17
I have the code to add to the tree and that all works ok and i have a method to print out the full tree starting at the root, then all the left nodes then the right nodes:
public void ShowTree(Node T)
{
if (T != null)
{
Console.Write(T.DATA+ "\n");
ShowTree(T.LEFT);
ShowTree(T.RIGHT);
}
}
I have tried something like this:
private static void ShowTree(Node tp, int spaces)
{
int i = 0;
if (tp != null)
{
ShowTree(tp.left, spaces + 3);
for (i = 0; i < spaces; i++)
{
Console.Write(" ");
}
Console.WriteLine(tp.data);
ShowTree(tp.right, spaces + 3);
}
}
And a few other approaches but i cannot get it to do as i want. Any suggestions on how i can do this?
|
|
|
|
|
The secret to drawing a binary tree is to start with the leaves.
A depth-first search will go through the leaves in order from left to right. Increment each leaf's X coordinate to allow space for the previous leaf. The Y coordinate comes from the depth of the leaf's level.
When the coordinates have been assigned to all of an interior node's sons, you can use them to position the interior node in the middle, above its sons.
When all nodes have coordinates, just cycle through them and draw them.
"Microsoft -- Adding unnecessary complexity to your work since 1987!"
|
|
|
|
|
Wow, couldn't have said it better myself!
Thanks Alan!
April
Comm100 - Leading Live Chat Software Provider
modified 27-May-14 8:38am.
|
|
|
|
|
I created a text file using StreamWriter in a Form Application.
I can't put a code to show the lines from a text file in a listbox.
How to fix this problem.
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;
using System.IO;
namespace AplikacioniStudentet
{
public partial class FormaStudentet : Form
{
public FormaStudentet()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBoxID_TextChanged(object sender, EventArgs e)
{
string pathi = "Studentet.txt";
using (FileStream fs = new FileStream(pathi, FileMode.Create))
{
using (StreamWriter sw = new StreamWriter(fs))
{
foreach (string line in textBoxID.Lines)
sw.Write(line + sw.NewLine);
sw.Close();
}
}
}
private void button1_Click(object sender, EventArgs e)
{
string pathi = "Studentet.txt";
using (FileStream fs = new FileStream(pathi, FileMode.Create))
{
using (StreamWriter sw = new StreamWriter(fs))
{
sw.WriteLine(textBoxID.Text + " " + textBoxEmri.Text + " " + textBoxMbiemri.Text + " ");
sw.Flush();
sw.Close();
}
}
}
private void textBoxEmri_TextChanged(object sender, EventArgs e)
{
string pathi = "Studentet.txt";
using (FileStream fs = new FileStream(pathi, FileMode.Create))
{
using (StreamWriter sw = new StreamWriter(fs))
{
foreach (string line in textBoxEmri.Lines)
sw.Write(line + sw.NewLine);
sw.Close();
}
}
}
private void textBoxMbiemri_TextChanged(object sender, EventArgs e)
{
string pathi = "Studentet.txt";
using (FileStream fs = new FileStream(pathi, FileMode.Create))
{
using (StreamWriter sw = new StreamWriter(fs))
{
foreach (string line in textBoxMbiemri.Lines)
sw.Write(line + sw.NewLine);
sw.Close();
}
}
}
private void listBoxStudentat_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox lb = new ListBox();
System.IO.StreamReader sr = new System.IO.StreamReader("Studentet.txt");
while (!sr.EndOfStream)
{
lb.Items.Add(sr.ReadLine());
}
sr.Close();
}
}
}
|
|
|
|
|
You have created a new ListBox in the listBoxStudentat_SelectedIndexChanged method, but at the end of the routine you have let it get lost. You need to create a ListBox on your form and add the items to that. Are you sure you want to add items just at the point that the ListBox selection changes?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Yes, I want that my listbox has to show every line from text file, and also, I don't want that to get lost.
|
|
|
|
|
Then you need to initialise it at the beginning of your program, not in the event handler for selection change. Just read the file and add each item from the file into the listbox that is on your form, don't create a new one that is not connected to anything.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
So you are saying that I nedd to create a text file only once, and after that i can manipulate with file details in my form calling them.
Am I right or...
|
|
|
|
|
dr_iton wrote: So you are saying that I nedd to create a text file only once, No, I did not discuss creating a file, I was explaining how to fill your ListBox .
dr_iton wrote: and after that i can manipulate with file details in my form calling them. Sorry, I have no idea what that is referring to.
Your application should be something like:
- During initialisation read your text file and build the
ListBox from its contents. - As information is added or changed in the application you may make changes to the
ListBox . - At program termination you should save the items from the
ListBox if it has been modified. - Other processing as required.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I got the point now.
If I can not post a solution tonight because I'll be busy, tomorrow I'll tell you if I solved my problem.
Once again thank you for your reply.
Cheers.
|
|
|
|
|
Hi everyone
could you explain about GetProcessesByName,I saw MSDN but I could'nt understand
is it true? GetProcessesByName same with GetProcessById ? GetProcessById needs to a PID and return a process but GetProcessesByName needs to process name(its really process name or application name?) and return arrays of processes
|
|
|
|
|
The MSDN text is pretty clear - you feed it the name of the executable file, and it returns al the processes that are currently running from that file:
Process[] procs = Process.GetProcessesByName("chrome");
Will give you a list of all the processes
running the Chrome browser.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
What are the most likely culprits to this error ?
The semaphore timeout period has expired.
The port in question is a simple BlueTooth USB plug-in thing, which Win'7 sees properly and everything.
This is a "sometimes" error. It is not consistent, and I have not found it documented on MSDN or other sites.
This is the dozen line method I'm using...
public static void Open_ActivePortWeWillUse(String Drone_StringNameFromUser)
{
SerialPort TempSerialPort = new SerialPort(Drone_StringNameFromUser, (int) SerialPortSpeed);
ThePorts.ActivePort1 = TempSerialPort;
ThePorts.ActivePort1.DataBits = 8;
ThePorts.ActivePort1.Parity = Parity.None;
ThePorts.ActivePort1.StopBits = StopBits.One;
ThePorts.ActivePort1.DataReceived += new SerialDataReceivedEventHandler(OurBackGroundSerialPortReceiver);
ThePorts.ActivePort1.Open();
}
modified 22-Dec-12 22:07pm.
|
|
|
|
|
I tried the same sample in VS2012 and the code works but the problem is VoiceChat doesnt work proper. Voice conference ports are not open thus the list of clients for voice conference are not added. No voice conference????
Thread: Voice and Text Conferencing Library[^]
|
|
|
|
|
Don't post this here - if you got the code from an article, then there is a "new message" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them.
Posting this here relies on them "dropping by" and realising it is for them.
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
I have added a login in screen to my program which works great except if the user just closes the login window it bypasses the the screen and loads the program. Is there a way to prevent this? Here is a sample of the code:
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
private void Button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void Button1_Click(object sender, EventArgs e)
{
if ((textBox1.Text == "puppy") && (textBox2.Text == "password"))
{
MessageBox.Show("Welcome Puppy", "Success",
MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Dispose();
}
else
{
MessageBox.Show("Wrong username or password","Invalid Input",
MessageBoxButtons.OK,MessageBoxIcon.Error);
}
|
|
|
|
|
Easiest way is to have a LoggedIn property in your form. Default it to false, then set it to true when he logs in correctly.
When you get back to the main form, check it, and behave appropriately.
BTW: Don't Dispose your form from inside - use Close instead. You can't dispose it until you have finished and the there is still and instance reference in the main form!
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
There are many ways to protect this.
However if you want to go for simplicity you can use a global bool for this.
Example:
public bool LoginStatus;
Then an example of usage:
!LoginStatus means basically if false.
LoginStatus means true.
So you set this bool in your login part to true if login is ok.
By using:
LoginStatus = true;
public void YourLogin()
{
if(!LoginStatus)
{
}
else
{
}
}
As said above this is a very simple way to do it.
There are lots ways more to do this.
|
|
|
|
|
Never recommend public fields - always use properties. Remember that a lot of the questions (like this one) are from complete beginners, and it is best to get good habits ingrained as early as possible!
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
The way I've always done this is by using a DialogResult from the login form. In the login form's "Button1_Click" event handler, where you have verified that the login info is correct, instead of "this.Close();" use "this.DialogResult = DialogResult.OK;" And then to use it, go to the Program.cs file. In the Main method, remove "Application.Run(new MainForm());" and replace it with:
LoginForm login = new LoginForm();
if (login.ShowDialog() == DialogResult.OK)
{
Application.Run(new MainForm());
}
That is, unless you want the user to "log out" and see the login screen again. But in this case, if you don't need that functionality, this will show the main form ONLY if the dialog result is "OK". It eliminates the need for a property (global or otherwise). Do you see what I'm doing here or do you need more explanation?
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
This worked perfectly, thank you.
|
|
|
|
|
I am trying to do a preliminary evaluation of Parallel Tasking in C#. I ran this script on my local. Each time the count of files seems to be different.
http://msdn.microsoft.com/en-us/library/system.io.directory.getfiles(v=vs.71).aspx[^]
A few outputs are:
Processed 14062 files in 715 milleseconds
Processed 14092 files in 710 milleseconds
Processed 14080 files in 695 milleseconds
Processed 13908 files in 712 milleseconds
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep!
|
|
|
|