|
Guffa wrote: Methods are always constant, you can never change the definition of a method at runtime.
AFAIK C++ const methods are, by definition, methods that can't change the state of the object they belongs.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
or a way to create a string-indexed array of int (sort of the reverse of what most arrays are)... thanks!
|
|
|
|
|
Dictionary is a map. In .NET 2.0, generics means you can specify the type of the two arguments.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Talking about the designers of C# making something complicated or what!
I have built a LogViewer application and my objective is to terminate the application if it determines there are no log files to display or if the logfile is in use by another application.
I run the application from Main as follows:
Application.Run(new MainForm());
In MainForm, it first does InitializeComponent, then it Populates the LogSelector with some user choices and then it adds logging info to the appropriate control if a log file is available (DisplayLogInfo).
If DisplayLogInfo detects that no logfile is available or the logfile is being used by another app, I want LogViewer to not show any form and to terminate.
I have tried this.Hide(). I have tried Application.Exit(). I have tried to make the form invisible by setting this.Visible to false. I have tried this.Dispose(), but then I get an unhandled exception and would rather not handle the exception by ignoring it.
Regardless, the form always displays and I have to close the app via closing the Window by the Close button.
Can anyone suggest a way to get this to work.
I would rather not rewrite the app. so that it checks for the logfile before running InitializeComponent as I believe there must be a way to accomplish the task as I have written it and I would like to learn how it can be done.
Comments?
|
|
|
|
|
Add a handler for MainForm's Load event, and execute this.Close() inside that handler. E.g.:
private void MainForm_Load(object sender, System.EventArgs e)
{
if (LogFileIsNotAvailable)
{
this.Close();
}
}
|
|
|
|
|
I see that your suggestion should work; however, I am still a little puzzled.
Can you tell me the reason why the "this.Hide()" or "this.Close()" did not work when implemented within the MainForm constructor?
|
|
|
|
|
First, I gave you bad (or at least incomplete) advice. I meant to say to use the Application.Idle event rather than the Load event. Calling Close from the Load event can cause a memory leak. You could do something like:
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent(); <br> <br>
if (ShouldClose)
{
Application.Idle += new EventHandler(Application_Idle);
}
} <br> <br>
void Application_Idle(object sender, EventArgs e)
{
this.close();
}
}
The Hide and Close methods don't work in the constructor because the Form is still being constructed. And in any case you don't want to close the form at this point, assuming the calling code looks something like:
Application.Run(new MainForm());
If MainForm is closed and disposed before it is constructed, then Application.Run will throw an ObjectDisposedException.
|
|
|
|
|
Hi!
I want to disable a windows close button.
Instead when the user presses the close button i want the window to hide (and not close) and the tray icon to appear.
The window hiding and the creation of the tray icon part is OK and works. (I tested this by calling those thing when I press a user button inside the form.)
Using FormClosed (occurs after the form is closed not good) and FormClosing(occurs before the form is closed) events doesn't seem to work. Can anyone give a suggestion.
Thanx
|
|
|
|
|
Hi,
Setting e.Cancel=true inside the Closing event handler did it for me (it cancels the
Close action that starts with a Closing event and, if not cancelled, ends with a Closed event.
Luc Pattyn
|
|
|
|
|
Thanx LUC
|
|
|
|
|
Hello!
How to create a application, that is stucked to the desktop? Is there any opposite of "always on top" like "always on bottom"?
Maybe you can help creating apps stucked on the desktop!
Thank you very much.
Metty
|
|
|
|
|
noemailz wrote: Is there any opposite of "always on top" like "always on bottom"?
Yes. You can use P/Invoke to call SetWindowPos()[^] with HWND_BOTTOM .
/ravi
|
|
|
|
|
Using SetWindowPos with the HWND_BOTTOM will just put the window behind all others but it is not the opposite of the HWND_TOPMOST flag as it isn't "sticky".
Steve
|
|
|
|
|
True. SetWindowPos() will need to be called repeatedly (eg: in a timer handler).
/ravi
|
|
|
|
|
I have this Windows app.
When the user clicks on a button (any button), after the event handler is done, the form is supposed to have focus returned (like if there's a MessageBox involved).
However, I've noticed that the user is forced to click once on the form to regain focus.
To illustrate (and this sounds weirder)...
The user hits a button, a MessageBox appears saying "are you sure?", and the user hits "no".
The messagebox disappears. But the button still has focus (understandable). If the user clicks on a different button, that same button still has focus and Windows thinks the user just clicked it instead of the other button that they clicked. The user has to click once on the form (even though the form visually seems to have focus, with the title bar dark blue and everything) before clicking on any other button.
Any ideas? This one really has me stumped.
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
Wouldn't you know it, almost right after I post this, I found it. I had the button's Validated event also pointing to the Click event handler. Now it works fine. Thanks anyway!
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
I have a method which is run as a thread and at the end of it I have:
XtraForm2 form2 = new XtraForm2();
form2.Show();
and the thing is that the windows just flashes - opens and imidiately closes
how can I solve it??
|
|
|
|
|
Keep the thread alive while the form is shown. Easiest way to do this is probably use form.ShowDialog() rather than form.Show().
p.s. make sure this background thread is STA, or you will run into all kinds of odd problems.
|
|
|
|
|
hmm... I've tried ShowDialog() but the result is the same
I can't really get the idea of STA
I have a method
public void GetData(Object o)
{
...
}
which I'm starting from a button as a thread:
Thread wat = new Thread(new ParameterizedThreadStart(GetData));
wat.Start();
where the STA should be put?
|
|
|
|
|
STA indicates that the COM threading model for an application is single-threaded apartment.
Apply this attribute to the entry point method (i.e. the Main() method). It has no effect on other methods!
SkyWalker
|
|
|
|
|
a did somethling like this in my XtraForm1.cs
[STAThread]
public void GetData(Object o)
{
...
...
form2.ShowDialog();
}
but again it closes itself :/
I also have in the Program.cs file:
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new XtraForm1());
}
|
|
|
|
|
Try this:
Thread wat = new Thread(GetData);
wat.SetApartmentState(System.Threading.ApartmentState.STA);
wat.IsBackground = false;
wat.Start();
...
void GetData()
{
form.ShowDialog();
}
Let me ask you a question, though: why are you creating a new thread to create the form? You're creating lots of extra work for yourself by creating a new thread to launch the form. If you keep all the UI controls created on the same thread, things will be much easier for you.
Thus, I recommend you create all your UI controls on the same thread.
|
|
|
|
|
you solution works just perfect thanks
the application looks like this:
I start it, and there is a button which is pressed and then the method GetData is started as a thread and after it processes all the data a second window pops up with a report, so I don't make a new thread for the second window
|
|
|
|
|
greetings for all, I am very instered in learn how work with sound in c#...
for instance load a music file, see the frequency of that, if any one have any idea or better have a project as example, please tell my,
regards
my;)
|
|
|
|
|
I believe in .NET 2.0 their is a System.Media namespace that has classes to handle wav sound files. If you are using .NET 1.1 or before (or if the classes in the System.Media namespace can't help you with your specific file format) then you might try using activeX controls. I know Windows Media Player has a control for video, but I am not sure whether they have a control for audio.
Now that I think of it, I remember somewhere on this site their is an article on audio output using Windows Media Player. Try searching.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|