|
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.
|
|
|
|
|
The best way to make the settings global to your application is by having a class that is visible to the whole app. Something like:
<br />
public class MySettings<br />
{<br />
public static string MyDbConnectionString;<br />
public static string SomeOtherSettings;<br />
}<br />
Notice the keyword static infront. This means that you do not need an instance of the class to reference those members. You would access them like:
MySettings.MyDbConnectionString = ...
So you just load your settings from a file at the start of your app, and then just set them again from the options dialog.
Hope this helps and gives you a start,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
Thank you for your help. that's exactly what i needed to know, and it works like i expected.
|
|
|
|
|
Glad that I could be of help
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
|
leppie wrote:
Its generally better to place things like your own SQL/Access connectiong string in the machine.config file.
I would advise against this for a couple reasons:
- Your app will break if you move to a new version of the framework, but forget to update the machine.config for that version of the framework. Or worse, another application does the same thing, but storing a different connection string.
- You are taking something that should be local, and making it global. You wouldn't want your connection strings entered into another application so you should keep them local to the apps that need it.
Instead you should store the read-only setting in the app.config file. If you expect to make more applications using the same connection string then you would be better off creating your own settings class and storing that in the user's application directory, or the common application directory if the settings should apply to everyone.
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 T. Johnson wrote:
You are taking something that should be local, and making it global. You wouldn't want your connection strings entered into another application so you should keep them local to the apps that need it.
I realise that! I was thinking more in a development enviroment, rather than production. Obviously on deployment, an app.config file is created to carry the setting. That makes sense doesnt it?
leppie::AllocCPArticle(Generic DFA State Machine for .NET);
|
|
|
|
|
You have probably noticed that if the text attributes are set to bold, larger size etc. on most of the controls the text itself is displaced to the left (usually). I'm talking here about the standard .NET controls (button, etc)
Can something be done? Are custom controls the only solution to this problem?
Also buttons with an image and text do not look very good.
|
|
|
|
|
|
Looking for C# game developers, I've already got the engine started, I just want more people to work on this with, it's coming pretty far and I want to collaberate with others that have some experience with these matters, anyways, all the information is at http://xed.kicks-ass.net/ypconquest[^]. Thanks
|
|
|
|