|
1) Control c = Control.FromHandle(myHwnd);
using(Graphics g = c.CreateGraphics())
{
g.Draw... what ever you want
}
NOTE: if you are going to many drawing on the control handle which is passed to your function or class which has this drawing function, better to create a Graphics instance "once" and use it over and over again instead of using a "using(Graphics g...)" where a new instance of graphics created and disposed after each drawing.
I would prefer capturing the handle in my Drawer/Painter class's constructor and create a Graphics object there immediately. (This way I suppose the size of the windows whose handle was captured does not change). Otherwise you should use "using(Graphics g = ...)" block
Hope this helps...
|
|
|
|
|
How can I clear out my deletedItem folder in outlook 2003 with c#?
|
|
|
|
|
How can I clear out my "deletedItem" folder when I shut down my outlook 2003 in c#?
|
|
|
|
|
Outlook 2003[^] might be a starting point for you. It has links to various things you can do in C# with Outlook.
|
|
|
|
|
Hi guys
can any body tell me how can i write into app.config file through c# code, when i try to write through configurationmanager so it throws an exception saying that
"configuration is read only" why is that?
how can i do that?
thanks in advance
hello
|
|
|
|
|
The app.config file is just where things start. When you compile your application it becomes Exename.exe.config. You have to use something like this:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
To access your app config file and make changes to it. If you try to write to it directly you get the readonly error since the application is using it.
Hope that helps.
Ben
|
|
|
|
|
1) You can write only to "yourApplication.exe.config"
OR
2) Create a separate config file and write into it with
a) System.Configuration namespace members,
b) EnterpriseLibrary April 2007 edition (FileConfigurationSource...)
c) Raw XML code ( don't prefer )
3) Create a separate ApplicationSettingsProvider which overrides the current one and uses a file as a storage which implements SettingsProvider abstract class ( for example, LocalFileSettingsProvider )
Hope this helps...
|
|
|
|
|
Hi,
I'm building an app which has panels in both right and left side. For this i'm using splitcontainers.
The document of that app is then opened inside one panel of one of the splitcontainers. I open that form in a maximized form. But if i move the splitters (the one from the left, or the one from the right), the form doesnt get maximized.
What can i do to make it adapt automaticly to the new conditions?
Thx,
Nuno
|
|
|
|
|
Is the control that shows the document (fully) docked in the panel?
|
|
|
|
|
Yes.
In the form that will be the MDI i have the option WindowState = Maximized
Thx,
Nuno
|
|
|
|
|
Yes, but is the control docked in the panel?
|
|
|
|
|
I am writing automated tests for my project. As part of this I bring up a FolderBrowserDialog and need to close it programatically. But since the dialog is not derived from Windows.Forms and it is modal, I cant capture and close it.
Is there a way to do this?
|
|
|
|
|
Try P/Invoking.. FindWindow() and then do SendMessage()..
Cheers,
Suresh
|
|
|
|
|
I used the FindWindow and SendMessage combo and it worked.
Thanks a lot!!
|
|
|
|
|
Launch it from a thread and Abort the thread?
|
|
|
|
|
The following have either returned null or returned the Windows\System32 directory:
System.Windows.Forms.Application.ExecutablePath;
System.Reflection.GetExecutingAssembly();
System.Reflection.GetExecutingAssembly().CodePath;
Environment.CurrentDirectory;
Does anyone know anything that actually works?
|
|
|
|
|
I used AppDomain.CurrentDomain.BaseDirectory
|
|
|
|
|
System.Windows.Forms.Application.ExecutablePath; works for me.
Two other methods that may work:
System.Reflection.Assembly.GetCallingAssembly().Location <br />
System.Reflection.Assembly.GetExecutingAssembly().Location
|
|
|
|
|
Does it work for you when running a service??? Running a service is a unique situation because of how it is started and the context that it runs. I also listed all the ways that I succeed in getting null which includes your "other two methods".
|
|
|
|
|
Yes, I write services too, and I tested these within a service.
Actually two different services.
One is simple, with all the code in one executable.
The other is much more complex, with pieces in various DLLs, the actual service code is in a DLL that gets loaded dynamically through System.Reflection.Assembly.LoadFrom .
I don't know how much more complex yours could be.
|
|
|
|
|
Hi,
I wanted to catch two different types of exceptions in custom log file code. When the second instance of log file is trying to write while the first instance is still writing some message, C# is throwing IOException when the file is opened in Append and Share None mode.
When I try to access a folder which does not exists, in that case also compiler is throwing the same exception.
I tried with the following code:
try
{
FileStream fileWriter = File.Open(@"C:\Test\Test.log", FileMode.Append, FileAccess.Write, FileShare.None);
FileStream fileWriter1 = File.Open(@"C:\Test\Test.log", FileMode.Append, FileAccess.Write, FileShare.None);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Is there any way to catch those two scenarios with some unique identity?
Please advise in email to rajesh_a_kumar@dell.com
Thanks,
Rajesh
rajesh_a_kumar@dell.com
|
|
|
|
|
rajesh_kumar_24 wrote: When I try to access a folder which does not exists, in that case also compiler is throwing the same exception.
Why not check if the folder exists [System.IO.Directory.Exists(strPath);] rather than throwing an exception. If the folder doesn't exist, you can write to a log file to log the error.
rajesh_kumar_24 wrote: When the second instance of log file is trying to write while the first instance is still writing some message, C# is throwing IOException when the file is opened in Append and Share None mode.
Why not write a function to pass the string to be logged and the function will look after reading and writing to the file. Is there a reason you want to open 2 different filestreams?
|
|
|
|
|
Actually, I have 5 different components trying to use the log class. All 5 instances can try to write the message to log file at the same time. So, I want to keep rest of the 4 in waiting (loop) till 5th one completes its logging. I can control this loop and with the help of a static variable.
Can you please advise how to achieve this?
|
|
|
|
|
You should put a separate class for logging. The class will look after writing to the log file, every component/class in your code can create an instance of this class and log the details to it. I am actually writing an article on this and should be out in 2-3 days time. You can have a look at this article by Ravi Bhavnani[^]
|
|
|
|
|
Catch DirectoryNotFoundException and IOException.
---
single minded; short sighted; long gone;
|
|
|
|