|
In WinForms, I'd try and center the title-text on the form; that way it could grow in both directions. I assume you're talking about the title, as the rest looks quite good.
robwm1 wrote: I'm thinking at this point that I should get the current DPI setting and if it's greater than 96 dpi then move the x-coordinate of the labels. If the label is autogrowing, then that "could" be enough. It may overlap other controls though if it grows.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The title "File Archiver Utility" is in a label. The label itself wraps tightly around the text and the text-align property is set to MiddleCenter and AutoSize is set to True. I might be able to get away with making a banner that includes the logo and title because the image seems to scale or just move the label to the left at launch. I have a couple of other labels that are to the right as well so moving them at launch is probably the best approach.
|
|
|
|
|
robwm1 wrote: The label itself wraps tightly around the text and the text-align property is
set to MiddleCenter and AutoSize is set to True Alignment doesn't help then, as the size of the label is as small as possible. There's no wiggle-room then.
Disable autosizing and make it as wide as the form (the maximum size it should be allowed to be), then anchor it, and then "align middle" will work better.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I made the label the full width from the right edge of the logo graphic to the right edge of the window. Although the text isn't aligned proportionally the same as when DPI is 100%, I would say it falls into the "good enough" category. I'm going to try changing the X location to see how that works.
I could probably put the left edge of the label to where I want the text to be aligned when DPI is 125% and then change the alignment of the box to LeftCenter.
|
|
|
|
|
So getting the DPI setting and changing the control's Location property pretty easily solves this matter. This way I can make the two 'views' look the same without much trouble.
Thanks a lot for your help, Eddy!
|
|
|
|
|
You're welcome
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Suppose I have following code. (not necessarily in one function or even one class.)
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap("[path]");
bmp.Dispose();
How can I detect if bmp was disposed or not? it is not set to null when calling Dispose, but trying to check a property (ef width and height) to see if it is a valid property immediately results in an exception being thrown.
I searched google, but found not real satisfactory option. I try to set bmp = null where I can after dispose, but this is not always and option. (for one thing, this application is a heritage of someone else )
thanks.
|
|
|
|
|
One somewhat horrible way of doing this is:
Bitmap bitmap = new Bitmap(200, 200);
IntPtr hBitmap1 = bitmap.GetHbitmap();
bitmap.Dispose();
try
{
IntPtr hBitmap2 = bitmap.GetHbitmap();
}
catch (ArgumentException ex)
{
Console.WriteLine("Bitmap has been disposed!");
}
Otherwise, you might try figuring out how to test the native handle.
[edit] BTW, I tried reflection to see if Bitmap or Image has a "disposed" field or property. No such luck. [/edit]
Marc
|
|
|
|
|
There is no way to find out if an object is disposed AFAIK, other than to try and use it and catch the ObjectDisposedException exception.
The problem is that Dispose releases all memory for the object, so there is nothing there at the reference instance to hold info for "this is disposed"!
You could add your own bool and check that, but it does seem like a nasty kludge.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
You could derive a class of your own from Bitmap , and add a Disposed property that tracks whether the object has been disposed.
You would need to override the Dispose method to set the flag to true.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Not sure that would work, since the flag would be Disposed at the same time as the rest of it. At best, it would risk problems with consistency once the GC kicked in, wouldn't it?
He could get away with encapsulating a Bitmap, and Disposing that without disposing the outer object, but...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
You're right. I guess I didn't engage the brain before the fingers.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
On second thought, I thought the purpose of Dispose is to release unmanaged resources.
The managed memory of an object would remain valid until it goes out of scope, no?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I was thinking about all this when I went to bed last night, and it's really quite nasty. And yes, you are absolutely right: Disposed objects are not deallocated until they go out of scope - My mistake
So I thought Id give it a try today. And got real problems trying to derive a class and dispose it. Until I finally twigged: You can't derive from a Bitmap anyway: it's a sealed class...http://msdn.microsoft.com/en-us/library/system.drawing.bitmap%28v=vs.110%29.aspx[^]
You can derive from non-sealed disposable classes, and add variables (which you are absolutely right, won't be deallocated until they go out of scope), but...MSDN says you shouldn't!
"An ObjectDisposedException is thrown when you try to access a member of an object that implements the IDisposable interface, and that object has been disposed. Typically, this exception is caused by one of the following conditions:" http://msdn.microsoft.com/en-us/library/system.objectdisposedexception(v=vs.110).aspx[^]
So the way I read it is that if an object is Disposed, you should get an exception whenever you try to use it again - I know you don't, but technically you should.
And the OP is back to encapsulation!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
OriginalGriff wrote: Until I finally twigged: You can't derive from a Bitmap anyway: it's a sealed class...
Ahem![^]
Richard Deeming wrote:
The only problem is, you can't write a class derived from Bitmap, as it's sealed.
That'll learn ya to ignore your notifications!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Everyone knows I can't read...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
I probably will do something like this. I have some static functions working on Bitmaps in a framework dll anyway. I could Encapsulate a Bitmap object in there that can handle the dispose and hold the bool indicating this.
Not my favorite solution, but for now the best option
|
|
|
|
|
I have a C# project in Visual Studio which has several classes under it. I am trying to run each class separately but when ever I hit the start or debug buttons,only one of the classes (the first one I created) runs.I tried right-clicking the other classes but they don't have the run option. I am using Visual Studio Express 2013
|
|
|
|
|
Let me see if I understood this correctly, you have a console application with a few classes you added on your own ?
If so, you should call functions from your classes in the console application's main function.
Edit: if you have multiple projects, you can just set one as a startup project and run that one.
|
|
|
|
|
|
You can't execute classes. Methods CAN be executed. A console-app will have one (1) method that gets executed when the application starts. From there, you can create other classes and call methods on them.
I'd recommend the book "Head First C#".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I attempted to create an extension method for a list of my data. For example:
public static class MyExtensions
{
public static List<Foo> GetModified(this List<Foo> list)
{
if ((list == null) || (list.Count == 0))
{
return null;
}
else
{
return list.Where(r => r.IsDirty).ToList();
}
}
}
The code was compiled without any error. The problem is how to consume the feature. The following code does not compile since the extension method can’t be found:
fooList.GetModified();
It appears I need to create a class to wrap up the List of Foo, which is what I try to avoid and keep my code simple. Does anyone know how to call this extension method without create a list wrapper? If not, why doesn’t the compiler present a message for the extension mothed? Is the extension method just syntax correct but can’t be invoked? Sounds odd?
|
|
|
|
|
Add reference and using for the assembly containing the extension method...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
I might be mistaken, but I don't think you can create extension methods for a specific generic type. You need to create it for the generic itself (List<T>) and then add a constraint.
public static List<T> GetModified<T>(this List<T> list)
where T : Foo
{
}
something like that... the IDE will filter intellisense on the constraint as well.
|
|
|
|