|
whenever you want to update scrollbars, call:
myPanel.OnResize(EventArgs.Empty);
|
|
|
|
|
Thanks, but I don't think that would help. The panel simply ignores the bitmap when calculating the scroll margins.
Yigal
|
|
|
|
|
I have app working with MDIs - there are also panels with bitmaps and AutoScroll on, but it works fine.
My panel contains PictureBox and this PictureBox has fixed size (same as bitmap) and location (0, 0).
Maybe you just setting Panel.BackgroundImage property (??). This will not work. Panel 's scroll bars depends on size of controls it contains.
|
|
|
|
|
I've created some control that browses directories using TreeView on the left side and shows image thumbnails on the right side.
This control contains thumbnail management. It works this way:
Create hash string from image file address: C:\hello.png -> e8f838d8283kn4.jpg
Does e8f838d8283kn4.jpg exist?
Yes: load this file
No: 1) shrink source image and save as e8f838d8283kn4.jpg
2) dispose source image
But when I browse gallery of 100 3.0 mpx images, my app creates about half of them and then system tells me, there is not enough virtual memory. Next message comes from mscorlib.dll (Out of memory exception) and program falls down.
But thumbnails are small enough. If there are 100 128x128 thumbs, it takes up to:
128x128x3x100 = +- 4.6 MB
Every 3 mpx source image is disposed (using Image.Dispose() call) as well as thumbnails, when directory changes. So why is there lack of memory (my PC has about 240 MB RAM, this may not be a problem).
GC must clear all resources since system needs memory occupied by disposed images, doesn't?
|
|
|
|
|
I'd have to question how your making the thumbnail images and making absolutely sure of what your doing. It sounds like your not aactually creating the thumbnail, but making a copy of the original image and just showing it scaled down in a picturebox.
Without seeing the relevant code, it's impossible to tell you what's going on.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
No, I'm not so silly.
This is the pseudo-code (loading and saving thumb) of my Thumbnail class:
<br />
Image source = Image.FromFile(sourcePath);<br />
Image img = new Bitmap(128, 128);<br />
<br />
Graphics grfx = Graphics.FromImage(img);<br />
grfx.DrawImage(img, ...)<br />
<br />
grfx.Dispose();<br />
source.Dispose();<br />
<br />
this.image = img;<br />
The thumbnail creation process runs on background and Thumbnail instance draws its image in overriden OnPaint method (not in PictureBox).
|
|
|
|
|
oh, sorry - this is on the one line:
<br />
grfx.DrawImage(source, new Rectangle(..., 128, 128), new Rectangle(... source.Size), GraphicsUnit.Pixel);<br />
I draw the large image onto small image. Then I dispose Graphics object and source image.
Thumbnail control disposes the small 128x128 image in the Dispose() method.
|
|
|
|
|
Have you tried calling (in order)
GC.Collect(); // collect unused memory
GC.WaitForPendingFinalizers(); // wait for any pending objects
GC.Collect(); // free any pending objects
Often it's not recommended, but sometimes the GC needs a little kick in the rear to start cleaning things up. This is especially true in pre-.NET 2.0 frameworks, where the GC has no knowledge of how "heavy" a particular unmanaged resource is.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
It seems to work fine!
Eh - Image object in unmanaged?
|
|
|
|
|
Well, in essence an Image is an 'unmanaged' resource, because the CLR and the GC do not manage the raw resources (in this case, a bunch of bytes representing a file) held by the object.
FYI, in .NET 2.0, you can call GC.AddMemoryPressure(long numberOfBytes) to let the GC know that you're holding on to some big resource like an image.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
Thx again. Important thing to remember.
|
|
|
|
|
You probably want to profile your application while you are at it to see if you have any other memory issues.
How To: Use CLR Profiler[^]
|
|
|
|
|
This is a very fundamental question about the use of enumerations in C#. I want to write out the value of an enumeration like System.Drawing.FontStyle to a file like this:
Font f...<br />
StreamWriter sw...<br />
<br />
:<br />
<br />
sw.WriteLine(f.FontStyle);
But then I want to read it in without having to use an if statement to decode it. This is what I want to avoid doing:
String myFontStyleReadIn...<br />
<br />
if (myFontStyleReadIn == "Bold") f = new Font("Arial",8,FontStyle.Bold)<br />
else<br />
if (myFontStyleReadIn == "Italic") f = new Font("Arial",8,FontStyle.Italic)
...
How do I write out the value of the enumeration, then read in the value and instantiate a new font using it?
Thanks!
Mark
|
|
|
|
|
Don't save enumeration members as strings. Save them as integers:
int index = (int)f.FontStyle;
Whenewer you want a string, use:
string style = ((FontStyle)index).ToString();
|
|
|
|
|
Do you mean something like this?
Array folders = Enum.GetValues( typeof(System.Environment.SpecialFolder) );
System.Console.WriteLine( "Special Folders:" );
System.Console.WriteLine( "----------------" );
int longest = 0;
foreach( System.Environment.SpecialFolder folder in folders )
if( folder.ToString().Length > longest )
longest = folder.ToString().Length;
foreach( System.Environment.SpecialFolder folder in folders )
{
System.Console.Write( folder.ToString() + ": " );
for( int i = 0; i < longest - folder.ToString().Length; i++ )
System.Console.Write( " " );
System.Console.WriteLine( System.Environment.GetFolderPath(folder) );
}
Matt Gerrans
|
|
|
|
|
Ah I knew I had done something more similar that this to exactly what you're asking before. Here it is:
private void LoadOptions()
{
string [] keys = new string[currentOptions.Keys.Count];
currentOptions.Keys.CopyTo( keys, 0 );
foreach( string optionName in keys )
{
System.Type optionType = currentOptions[optionName].GetType();
string iniSetting = GetSetting( optionName );
Array enumValues = Enum.GetValues( optionType );
foreach( object enumValue in enumValues )
{
if( enumValue.ToString() == iniSetting )
{
Utils.Trace(null,"Option {0} changed from {1} to {2}.", optionName,
currentOptions[optionName].ToString(), iniSetting );
currentOptions[optionName] = enumValue;
}
}
}
}
Matt Gerrans
|
|
|
|
|
Thanks for the responses. Itinka understands what I want to do. But how do I convert an integer value back into a FontStyle that I can pass to the Font class constructor?
Mark
|
|
|
|
|
I think I wrote:
(FontStyle)(int)
...just convert it (every enumeration member naturally has an index).
|
|
|
|
|
Hi All,
I have a WinForm that has a static panel on it. Everytime I go to add something to my WinForm the IDE is trying to outsmart me and keeps on deleting that static panel along with all the code for it. Is there a way to stop the IDE from doing this ?
-Pete
|
|
|
|
|
Once upon a time, I was working on custom Windows Forms Designer. It's based on some kind of "roundtrip", which parses your code into DOM tree and then recreates the code back. If you've written something what doesn't smell much good to parser, it may not create right representation in DOM and your code is lost.
This was a problem in VS .NET 2003, I don't know if it's better on new VS Beta, but I solve these problems creating regular panel in designer and then adding my own controls in constructor:
myControl.Parent = panel1;
And you can also learn how to work with IExtenderProvider.
I don't know if I helped you much.
|
|
|
|
|
how can i disable windows's hotkeys like:
alt+tab
cntrl+esc
windows key
etc... i dont need to disable control alt delete though.
|
|
|
|
|
I haven't actually tried this but in theory you could listen to KeyEvents and see what key combination has been pressed. If you pick up something that interests you can choose to act on it or ignore it.
|
|
|
|
|
Hi,
We've wrote an app that utilizes asynchronous sockets to collect real-time information and write it into the database. We are using a slightly modified version of this example: http://www.codeproject.com/csharp/socketsincs.asp for our socket component.
Our app works fine, we've been testing it for a week and a half now and it performs almost flawlessly. The problem is that we also need a windows service version of the app, we've completed the windows service a week ago but for some reason it won't work. I've tracked it down and it turns out the BeginConnect call does not work. It just won't connect to the server and therefore no socket is created.
m_sock.Blocking = false;
AsyncCallback _connect = new AsyncCallback(ConnectServer);
m_sock.BeginConnect( epServer, _connect, m_sock );
ConnectServer should return IAsyncResult ar from which we can derive a socket, however it does not work. BeginConnect call fails and service simply fails to establish a connection.
Now with the exception of couple of lines specific to the app, the code in the app and in the service is absolutely identical, yet the app works absolutely fine and the service does not. We have no idea what is wrong with the service, why it won't establish connection. We've tried running the service under the domain administrator account thinking it was security issue, but it still won't work.
Anyone has any idea what's wrong here? I'm at a complete loss, been searching google for several days now to no avail.
|
|
|
|
|
LOCAL SERVICE user account, which is the default for services, does not allow network access. Set your service to run under the NETWORK SERVICE account or ADMINISTRATOR.
|
|
|
|
|
We have already tried network service and domain administrator accounts. We just tried administrator and it still won't work...
|
|
|
|