|
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
|
|
|
|
|
Hi peoples. I have a quick question reguarding API usuage....im trying to create collision detection by grapping just the color of the pixel on the outer edge of my object. This works okay for me using the API call GetPixel
the problem lies in that i have to get the pointer to the GetPixel call for this i have been using GetDesktopWindow() another api call that returns the Handle for the graphics on the entire desktop. Now this worked.. the problem is that its the hole desktop i.e everything drawn on it....if im trying to get the color in ONLY my program and someone opens a window above mine the GetPixel will grap the pixel from the open window not my program. What im looking for is a way for the API to only look at my program. Is there a easy / way to do this ?
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
You should be able to call CreateGraphics on your top level form, then use the GetHdc /ReleaseHdc methods on the Graphics object to retreive the HDC which you can use with GetPixel .
The only thing I'm unsure of is if the HDC returned is clipped around the child controls.
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
|
|
|
|
|
Thanks for your help james. It turns out that it is clipped around the controls. and i need it for only the controls. I tryed passing the Handle to just the control i want (Ctrl.CreateGraphics().GetHdc) but i get a out of memory exception. But when i call the api call with another api call in it (GetDesktopWindow()-returns pointer to desktop) it works fine. Any ideas ?
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
Hi,
I am creating a MDI based allpications, and trying to handle the events for Enter and Leave in the MDi child, but when I create a new child, its Enter event handler is called 2 and Leave One in (Enter, Leave then enter) fashion. Why so ? I need to do some action in them, which is called twice? Is there an alternative to it. I do not have any compenets on the child also and using .net 2002.
Thanx
mayank Goyal
Mayank Goyal
|
|
|
|
|
I'm new to c# and programming altogether, so can you help me figure out the best way to do this?
i have a "Tools > Options" dialog box where a user can put in the db settings to connect to a database (IP, username, password, etc). once a user submits these settings, i want the whole application to reference these settings for the database connection.
i have about 5 forms on this small app that connect to a db, so i don't want to statically assign these settings per form.
can i (or should I) use a struct and define the users settings as constants? if so, how can i call the struct from each form?
Thanks for your help.
|
|
|
|
|
.gonad wrote:
i have a "Tools > Options" dialog box
You have or want?
.gonad wrote:
i want the whole application to reference these settings for the database connection.
Add a name/value to your config file. Then you can just get the value via dynamic properties.
leppie::AllocCPArticle(Generic DFA State Machine for .NET);
|
|
|
|
|
Hi.
actually, I already have a dialog box where the user will have to enter the db connection properties. basically, i wrote this because i use this app at home AND at the office, but my network settings are different, so this "tools > options" dialog box will be helpful for me to make the these changes easily.
I just don't know how to make those changes permanent throughout the execution of the app and how to call those settings from each of the forms.
Thanks for you help.
|
|
|
|