|
try
Console.WriteLine(String.Join('\n', dirs));
ORACLE One Real A$#h%le Called Lary Ellison
|
|
|
|
|
foreach(string x in Dirs)
{
labelPath.Text = labelPath.Text + x + "\n";
}
\\the "\n" is for newline! if you want a new line!
Leon v Wyk
|
|
|
|
|
Hi,
I'm looking for a (simple) way to write outlook plugins in c#. Unfortunatly I wasn't able to find any articles here on codeproject (even though I thought there was a competition in may/june).
Would be nice if someone could point me to the right direction!
TIA,
Daniel
--
SharpPrivacy - A free OpenPGP implementation in c#
http://www.sharpprivacy.net[^]
|
|
|
|
|
|
Can I send data through the parallel port in C#?
/\ |_ E X E GG
|
|
|
|
|
Hi there,
I would like to notify my app if a socketconnection is broken.
I tried to use a self created event, with wich i want to notify an upper class in such a case.
The problem is i receive a unhandled exception of type 'System.MissingMethodException'...
Why? What Am i doing wrong and what means this error?
Thanks a lot,
stonee
internal delegate void ConnectionHandler(SocketException se);<br />
............<br />
<br />
public class Control<br />
{<br />
<br />
<br />
internal event ConnectionHandler OnConnectionProblem;<br />
<br />
................<br />
<br />
<br />
public Control() <br />
{<br />
OnConnectionProblem+=new ConnectionHandler(ESControl_OnConnectionProblem);<br />
....................<br />
<br />
<br />
catch(SocketException se)<br />
{<br />
/<br />
MessageBox.Show (se.Message );<br />
try<br />
{<br />
OnConnectionProblem(se);<br />
}<br />
catch(MissingMethodException mme)<br />
{<br />
MessageBox.Show(mme.Message+"::"+mme.InnerException);<br />
}
|
|
|
|
|
Here's the problem:
stonee74 wrote:
OnConnectionProblem+=new ConnectionHandler(ESControl_OnConnectionProblem);
There's no method ESControl_OnConnectionProblem
Here's how I would do it:
public delegate void ConnectionHandler(object sender, SocketException se);
public class ConnectionProblemEventArgs
{
private SocketException m_SocketException;
public ConnectionProblemEventArgs(SocketException se)
{
SocketException = se;
}
public SocketException SocketException
{
get
{ return m_SocketException; }
}
}
public class EsControl
{
public event ConnectionHandler ConnectionProblem;
public virtual void OnConnectionProblem(SocketException se)
{
if (ConnectionProblem != null)
ConnectionProblem (this, new ConnectionProblemEventArgs (se));
}
private DoSomethingWithSocket()
{
try
{
...
}
catch(SocketException se)
{
OnConnectionProblem (se);
}
}
}
public class EventListner
{
public EventListner(EsControl esControl)
{
EsControl.ConnectionProblem += new ConnectionHandler (ESControl_ConnectionProblem);
}
private void ESControl_ConnectionProblem(object sender, ConnectionProblemEventArgs e)
{
}
}
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
thanks,
I'm sure this will work.
I have in my original class a method definition.
I still cannot understand the errormessage..
private void ESControl_OnConnectionProblem()<br />
{<br />
<br />
}
thanks for all inputs.
regards,
stonee
|
|
|
|
|
In Visual Basic, I can add multiple forms in a project and have a button (or other form controls) from one form bring up another form just by using the name of the form that I want to load followed by the Show method. For example,
formName.Show, secondForm.Show, or anotherForm.Show
Now is there a way to do something like this in C#?
|
|
|
|
|
FDL wrote:
Now is there a way to do something like this in C#?
You have to create an instance of the object you want to 'show'. Here is an example, About is the name of the form, ab is the name of the instance of About .
About ab = new About();
ab.Show();
-Nick Parker
|
|
|
|
|
Nick,
Thank you very much for your reply.
This is strange because I was doing something like what you did but it didn't work. Oh well, it works now. I must've just typed something wrong.
I really appreciate your help.
|
|
|
|
|
Nick pointed you in the right direction for C# but I want to comment on the VB side of things.
While VB allows you to do that, it isn't a very good idea to do it! The problem becomes evident when you have forms that become intertwined. In one application I made there was a relationship between clients and dealerships.
Using the formName.Show method worked fine until you opened up a client, then opened up the dealership from the client, and finally tried to open another client. You would get an error!
Instead, the proper way to do it is very similar to the C# way of doing it.
(Its been a few years since I've done VB6 so pardon any typos )
Dim myForm As New formName
myForm.Show
James
"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him
|
|
|
|
|
James,
Thanks for the advice. It is something that I'll definitely keep in mind and in my notes.
Francis
|
|
|
|
|
I'm having a problem making a User Control display upon a form in C#.
My form starts off with a single UC on it. Its called UCInit. UCInit contains some text and a couple of buttons. When one of the buttons is clicked, I want UCInit to remove itself from the form, and a second User Control, called UCCreate, to appear.
I can get rid of the first UserControl, but UCCreate never appears. This is my code so far for when the button in UCInit is clicks:
private void btnCreate_Click(object sender, System.EventArgs e)
{
this.Hide();
UCCreate newPanel = new UCCreate();
newPanel.Location = new Point (376, 8);
newPanel.Show();
}
UCInit removes itself but the instance of UCCreate never shows itself. What am I doing wrong?
|
|
|
|
|
You also need to do:
newPanel.Size=[whatever-the-size-is];
this.Controls.Add(newPanel);
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Still no love. This is my amended code:
private void btnCreate_Click(object sender, System.EventArgs e)
{
this.Hide();
UCCreate newPanel = new UCCreate();
newPanel.Location = new Point(376, 8);
newPanel.Size = new Size (280, 140);
this.Controls.Add(newPanel);
newPanel.Show();
}
|
|
|
|
|
You're adding UCCreate to the control you are hiding, you need to add it to the controls collection of the form instead.
this.Parent.Controls.Add(newPanel); should give you what you want.
James
"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him
|
|
|
|
|
So once I add that code into the constructor of my form, how does the first user control know about it? That is, how do I let other Controls know that newPanel exists?
Thanks for the tip! 
|
|
|
|
|
I have a folder called 'Shares' in my wwwroot. inside of that are about 12 or so folders with the names of a Husband & Wife in my family... e.g. "Ben.Anna", "Heidi.Scott", "Carylon.Roy" etc...
now, on my asp.net c# page I need the it to list the files in the "Shares" folder.... How would I do this?
/\ |_ E X E GG
|
|
|
|
|
Use the System.IO.Directory.GetFiles and System.IO.Directory.GetDirectories methods, passing in the directory you want to retreive the files/directories from.
Use the Page objects MapPath method to go from the server's directory structure to one that can be used on a web page.
James
"I despise the city and much prefer being where a traffic jam means a line-up at McDonald's"
Me when telling a friend why I wouldn't want to live with him
|
|
|
|
|
I'm pretty confused... could you code an example or something..?
just display the folders inside the folder "Shares" in a label...
example...
here's the folder Shares
and inside it are the folders: Ben.Anna, Alex.David, & Heidi.Scott
then on a aspx c# page you have a label...
now what is the code to make the label look like this...
Ben.Anna
Alex.David
Heidi.Scott
and have it update when ever a folder get's added to Shares or deleted from it...
please help.. i'm in a desperate rush...
/\ |_ E X E GG
|
|
|
|
|
The following code capable of doing what you need :
<br />
DirectoryInfo di = new DirectoryInfo("c:\\");<br />
<br />
DirectoryInfo[] diArr = di.GetDirectories();<br />
<br />
foreach (DirectoryInfo dri in diArr)<br />
{<br />
Console.WriteLine(dri.Name);<br />
}<br />
if this doesnt make any sense please feel free to ask
|
|
|
|
|
this has to be a aspx webpage....
/\ |_ E X E GG
|
|
|
|
|
Ok, I got it to work in aspx... i went...
labelPath.Text=dri.Name; // where "lablePath" is my label....
but anyways... when I run it, it only displays the last file in the folder, according to alpabetical order... so if there are 3 folders: Alex Ben & Carly.... only the highest letter will show up... Carly...
it does this in every folder.... what's wrong?
here's my full code...
private void Page_Load(object sender, System.EventArgs e)
{
DirectoryInfo di = new DirectoryInfo("C:\\program files\\");
DirectoryInfo[] diArr = di.GetDirectories();
foreach (DirectoryInfo dri in diArr)
{
labelPath.Text=dri.name;
}
}
|
|
|
|
|
My bad (ish)
The reason that only the last value from dri.name is allocated is a simple one, but rather weird to explain in words so bear with me on this :
Your foreach cycles through each value on diArr, on each cycle is allocates the value of dri.name to labelPath.Text. Problem is on each cycle it will overwrite what was in there previously which is why when the page is rendered it only display the last value in dri (which is order alphabetically by default)
There are a myriad of ways of getting around this but the simplest is to do the following :
<br />
string strLabelText = string.Empty;<br />
foreach (DirectoryInfo dri in diArr)<br />
{<br />
strLabelText += dri.Name + "[BR]";
}<br />
<br />
labelPath.Text = strLabelText;<br />
This takes all the values from dri.Name and places them into a string with (see not below) between each value (to place them all on a different line) - this string is then allocated to labelPath.Text.
Or
<br />
foreach (DirectoryInfo dri in diArr)<br />
{<br />
labelPath.Text += dri.Name + "[BR]";
}<br />
Note : I had to put the br tags in square brackets ([) as the forum renders the code rather than displays it
|
|
|
|