|
if your PB is showing an image and holds the last reference to said image, you need to call Dispose() on that image (see the Image or Bitmap class in MSDN). So the right order is:
- get the image ref
- set PB.Image null
- dispose of Image
Your backward for loop is OK; forward would work also as long as you remove element zero all the time. What you forgot is the Controls collection gets adapted every time you add/remove something (that also was why foreach did not accept the removal). The best way to remove all is:
while (!collectionEmpty) { doWhatItTakesOnElementZero(); removeElementZero(); }
|
|
|
|
|
Thank you very much for the help.
I think I understand the problems I was having now.
Cheers
|
|
|
|
|
You're welcome.
PS: it is custom here to up-vote useful messages, that is how reputation gets built.
|
|
|
|
|
Sorry, was not aware.
But otherwise thank you.
|
|
|
|
|
No worries.
|
|
|
|
|
Hi all
I have a rather big GUI application in C# (.NET 2.0, VS2005), which takes some time when first started (its IinitializeComponent method, along with some other setup actions I am doing takes about 4-7 seconds).
I want to present the user an 'Opening screen' that will be presented while the application gets loaded, and once it finishes, this 'Openning screen' will be vanished.
I have tried to 'show' the 'Openning screen' form before starting my applic, but it fails to be drawn completely and fails to shut off when my app finished its setup (since the main thread can't reach its close statement as it stays on the message loop of my main app).
Here is some pseudo code:
[STAThread]
static void Main(
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
OpenScreenForm op = new OpenScreenForm();
op.show();
MainApp m = new mainaApp());
Application.Run(m);
op.Close();
}
I have tried using other thread to show the openning screen, and joins him (by the main thread), so that I could make sure that the form finished its showing stuff, but this also failed (openning screen gets shown for a glimpse and hides back..)
Here is some pseudo code:
[STAThread]
static void Main(
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Thread openThread = new Thread(new ThreadStart(CreateOpenningForm));
openThread.Start();
openThread.Join();
MainApp m = new mainaApp());
op.Close();
Application.Run(m);
}
...
static void CreateOpenningForm()
{
op = new OpenScreenForm();
op.Show();
}
Does any one has any idea how to accomplish that ?
Thanks in advance
|
|
|
|
|
What you want is known as a "splash screen"... Google that, and you'll be overwhelmed with the amount of material out there
|
|
|
|
|
most of which unfortunately isn't any good, either the splash lacking functionality, or being shown for a fixed amount of time, or it all being threaded the wrong way. There are dozens of CP articles on the subject, and I still feel an urge to add one.
|
|
|
|
|
|
The functionality seems fine, the threading seems all wrong though. Forms must be created and shown on the main thread, otherwise you'll get all kinds of trouble. See the most recent thread in that article's forum.
|
|
|
|
|
This splash screen functionality is even a killer for my current needs.
By saying that the threading seems wrong, you must be refering to the cross-thread oporation that this program will face, since creating the splashing form not in the main thread, but accessing to it with it any way...
Well that is well known problem (that can be bypassed, if you know what are you doing) but it cerenally lies in the killer aspects of this splash screen from my point of view so it won't bather me (as I am planning to eliminate it to begin with..)
Thanks all for your help and remarks
Shultz
|
|
|
|
|
|
You might want to investigate this tip/trick:
Multiple Subsequent Main Forms in C# Apps[^]
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi. I want to develop an application where initially i have just an empty form with no functionality. Then, later, i can develop separate modules and when i install them, they plug themselves into the form with their functionality. Something like add ins. How can i do that?
Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|
|
One very common approach in .NET is via reflection/functional interfaces that add-ins should implement. Here's an 8 year old article on the topic:
Using reflection to extend .NET programs[^]
The concepts remain similar even today.
|
|
|
|
|
|
Microsoft has produced the Managed Extensibility Framework[^] that might be appropriate. It doesn't do anything specific to making pluggable parts of forms, but it does the work of dealing with dependencies on plugins that may or may not be there, etc.
|
|
|
|
|
Ummm... with plugins?
and XML.
Wamuti wrote: they plug themselves into the form with their functionality
I hope they don't try to position themselves on the form.
I've used plugins for background (non-UI) stuff, to populate a TabControl, and to populate a menu, but not for actual controls on a form.
|
|
|
|
|
I would like to build a basic ping application. I've seen a few ping applications here that are well developed and a little complicated for me to dissect and figure out how they work at this point in my learning.
Does anyone have a console ping application that is bare bones, that I can build off of while I learn? Something that I can launch and hard code variables into, and break and the put back and see how it functions?
Thank you!
|
|
|
|
|
|
Hi,
I tried that and it fails, I then spent a few hours trying to figure out why and could not, so I came onto here for help looking for something as basic as a few lines, that maybe I would be able to understand.
Visual C# Express says out of range exception was unhandled for this line?
PingReply reply = pingSender.Send(args[0], timeout, buffer, options);
|
|
|
|
|
if you want help with some code, you'd better show some of it, I mean more than a single line.
if you look in MSDN, there is a full example on the Ping class; it is in fact a Console app, probably doing exactly what you want.
if you look at Ping.Send in MSDN, it explains all, and shows possible exceptions; it also gives a possible source for OutOfRangeException.
Now go and read!
|
|
|
|
|
Ok I see what I did wrong initially.
I have now defined a variable called host and then put it in place of the "args[0]" array and it will ping it one time and return some values.
I think I can build off of this, thank you very much!
|
|
|
|
|
Yes but have you worked out why args[0] caused a problem and host didn't?
What is args[0] ? What does it hold? Is it important? Do you limit or cripple your software if you remove it? Or is removal an improvement? You do need to understand this basic stuff before you dive into anything more complex for a first app. Honest.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Hi,
I believe it is because the array is empty or undefined. I doubt it is an improvement to remove it.
I'm not sure how to get it to work with the array, the only time I've used an array is with a for statement and that isn't really applicable for holding multiple host names.
I believe you can pass multiple values into the method with { } but I'm not sure on the syntax yet
|
|
|
|