|
You've found the correct way of doing it! Nothing to worry about there...
|
|
|
|
|
The solution you reached in the end, calling the base's method is the correct way.
protected override void OnEnabledChanged(EventArgs e)
{
if (this.Enabled)
this.ColorScheme = EnmColorScheme.Purple;
else
this.ColorScheme = EnmColorScheme.Green;
base.OnEnabledChanged(e);
}
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Just a quick addition...
If your code is really that simple, you can drop the if/else and do a one liner:
ColorScheme = Enabled ? EnmColorScheme.Purple : EnmColorScheme.Green;
base.OnEnabledChanged(e);
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Ive got the webbrowser control navigating in a foreach loop which doesn't contain any IO yet i get the following exception
Exception:Thrown: "Could not find file 'C:\Users\Raymond\Desktop\TestProgram\bin\Debug\TestProgram.vshost.exe.config'." (System.IO.FileNotFoundException)
A System.IO.FileNotFoundException was thrown: "Could not find file 'C:\Users\Raymond\Desktop\TestProgram\bin\Debug\TestProgram.vshost.exe.config'."
foreach (string ValueName in Regkey.GetValueNames())
{
Browser.Navigate("http://www.google.com");
System.DateTime ThisMoment = System.DateTime.Now;
System.TimeSpan duration = new System.TimeSpan(0, 0, 0, 0, 10000);
System.DateTime AfterWards = ThisMoment.Add(duration);
while (Loaded != true || AfterWards >= ThisMoment)
{
Application.DoEvents();
Thread.Sleep(50);
}
}
with Browser.document completed set to the function below
private void BrowserCallback(object sender, WebBrowserDocumentCompletedEventArgs e)
{
Loaded = true;
}
No IO is taking place and the path in the exception is correct it even happens whenh im not debuging
Is there any way to fix this or get the foreach loop to wait until Browser.documentcompleted is fired without using a delay ?
|
|
|
|
|
You may not be doing any IO, but the debugging process is. The file that is missing is the config file for the debug process. While you're debugging, the executable that runs is called "myprogram.vshost.exe" and the config file it uses is called "myprogram.vshost.exe.config."
Does your project contain a configuration file? I don't know the details, but it appears to be looking for some kind of configuration information for the application, and it's not finding it. If you use Google on the file name, it returns several links that describe the missing file, and ways to suppress its creation. But you may already have a setting in VS that is stopping it from being created, and your app really needs it. From my reading, by the way, it appears that these files are created even when you build a Release version, but there's no need to actually deploy them.
Not a complete answer, I know, but at least it narrows the search some. Good luck!
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Strange but adding a app.config file solved the problem
modified on Sunday, June 27, 2010 12:47 PM
|
|
|
|
|
I thought it might take something like that, but I've had apps with no app.config file that worked fine. Some do, some don't, and I don't yet know why. Glad it solved the problem!
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
|
I'm working on a program that needs to run in the foreground (so it can hold up a script running until it's done) for the first part of the application, then switch to running in the background for the remainder of its life.
I have tried putting commands before the Application.Run() line, but that didn't work. I also tried changing it to a Command Line application in Visual Studio, but then it didn't go into the background at all.
Is there an easy way of doing this?
|
|
|
|
|
Not sure what you mean..........
Do you mean you want the GUI to move to behind all the other windows?
or
Do you want the thread priority to be reduced from normal to lower?
or
Do you mean something else?
|
|
|
|
|
Sorry, I'll be more descriptive.
When a windows forms application is run in the command prompt, you hit enter and you instantly see another standard command prompt line because the application has opened in the background (or at least it has been opened and told the command prompt that it's not needed any more).
What I want is for my application to not instantly ignore the command prompt but to do a few things and output a few lines to it before going off and being a windows forms application.
I think that's still worded badly, but hopefully you can figure out what I mean.
|
|
|
|
|
There are two parts - the application and the form that application displays.
Normally all the applicaiton does is display the form but you can do ther work before that.
Does this make it clearer?
|
|
|
|
|
Mmm... slightly. How do I do work before the form is displayed? I put my lines of code right at the beginning of the main() method and that doesn't work. Unless there's somewhere else I should be adding the code?
|
|
|
|
|
In an application i am working on there is program.cs with the following code:
namespace StreamTest
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
As you can see the Application.Run method is what triggers the UI so put your code before that. You can change the form definition to pass parameters if you want, I have done that before.
|
|
|
|
|
WubbleU wrote: I put my lines of code right at the beginning of the main() method and that doesn't work.
Yes, but what exactly are you trying to do and what is the result?
Your program should look something like
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new RotaForm());
}
You should be able to perform any other functionality before the three lines above to achieve the result you are after. However, it is somewhat difficult to understand exactly what you are trying to do, maybe if you post some of your code it will become clearer.
It's time for a new signature.
|
|
|
|
|
As far as I can tell, you want the project to be a Console project.
Perform your "before" stuff.
(Maybe wait for the user to press RETURN.)
Then call FreeConsole to remove the console window.
Then Run the Form.
[
System.Runtime.InteropServices.DllImportAttribute
(
"Kernel32"
,
SetLastError=true
,
EntryPoint="FreeConsole"
)
]
private static extern bool
API_FreeConsole() ;
/**
<summary>
Uses pinvoke to call the Windows FreeConsole method
</summary>
<returns>
The result of FreeConsole
</returns>
*/
public static bool
FreeConsole
(
)
{
return ( API_FreeConsole() ) ;
}
|
|
|
|
|
Hi, that's exactly what I needed! Thanks!
The problem I have now is that the form isn't closing when I hit the X button. Any ideas?
Thanks again!
|
|
|
|
|
Should I be running the form differently? Instead of Application.Run(..) ?
|
|
|
|
|
Hi,
On using data type StringBuilder, I find that sufficient instances of data type string is also getting
allocated!
I saw this information when I used VSTS profiler to understand memory allocation.
Isn't StringBuilder and string totally different data types or is it that
internally stringbuilder is nothing but of the type string?
My code is very straightforward
StringBuilder str = new StringBuilder;
for (int i =0; i < 10; i++)
{
str.Append("Net");
}
Regards,
NetQuestions
modified on Sunday, June 27, 2010 4:41 AM
|
|
|
|
|
StringBuilder is a totally diferrent type to string . It is there for efficiency purposes when building a string up from multiple parts (as per your loop). You need to decide when it is efficient to perform your string concatenation directly or through a StringBuilder . Many people suggest always using a StringBuilder , but I disagree. See this excellent article, by John Skeet, who really knows what he is doing http://www.yoda.arachsys.com/csharp/stringbuilder.html[^]
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
A StringBuilder is a mutable version of a string: when you keep appending, you are exhausting the space allocated for the StringBuilder, so it allocates another, bigger one. This happens repeatedly. Try allocating sufficient space to start with:
StringBuilder str = new StringBuilder(40);
The default is 16 bytes, so you will go over that quite soon!
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
StringBuilder is different, but it is also a "build-in" type, not just a List<char> or something like that.
See here for in-depth information: Strings UNDOCUMENTED[^]
|
|
|
|
|
That article is wrong, there's nothing magic about StringBuilder. It just uses unsafe code to write to the built-in string data type. Your code could do that, too!
|
|
|
|
|
Interesting, I just assumed that the article would be right..
Now I looked with the Reflector of course and it appears that you are right instead. It just calls String.AppendInPlace which just uses some unsafe code.
|
|
|
|
|
"You can't observe a system without affecting it." -- Heisenberg's Uncertainty Principle
|
|
|
|