|
You're going to have the performance problem no matter what. Even using whatever interface that is, it's going to have to open the file and read the entire thing to generate the thumbnail.
|
|
|
|
|
As Dave has said, no - it's not possible.
However, there are two things you might consider to speed things up:
1) Cache your thumbnails. Create a new folder (if it doesn't exist) below the source image folder called "Thumbs", and when you need a thumbnail check that folder first for a file of the same name. If it exists, just read the thumbnail file. If it doesn't, generate the thumbnail and add it to the Thumbs folder. That doesn't speed everything up, but the second and successive times it will.
2) Do the above, but add a background thread that checks the images folder for "missing thumbs" and create them as needed. That again doesn't speed anything up, but it moves the generation into the background and "pre-prepares" thumbs that haven't been asked for yet.
Obviously, it'll take some work to ensure everything doesn't start colliding and your app crashes as a result, but it's that or insist that the images need to be added to your app before they are used (and creating the thumbnail then) - which may not be possible / convenient for your users / app.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Some file formats allow embedding a thumbnail in metadata. For example JPG allows it in the EXIF data section.
Not all image formats support this, and even if they do, not all images will have it. And even if it is present, the quality might not be sufficient.
I have not looked at it for years (decade+) so have no code nor libraries, but maybe googling "EXIF thumbnail c#" or similar will help.
|
|
|
|
|
Le@rner wrote: is there any option to get image file thumbnail ,but without open the image file.
Using those requirements and NOTHING else, then yes.
Create (or buy, acquire) say 100 or 1000 very small images.
Then for each file assign one of those to the file either sequentially or randomly. The number of files will determine if you produce repeats.
You could also just populate a small image with random data also. A variation of that is to use the name of the file and/or the current date/time as a seed for the random data.
|
|
|
|
|
i am create a PDF file using Microsoft Print to PDF,
PaperSize paperSize = new PaperSize("Custom", 400, 200);
PrintDocument pd = new PrintDocument();
pd.PrinterSettings.PrinterName = "Microsoft Print to PDF";
pd.PrinterSettings.PrintToFile = true;
pd.PrinterSettings.PrintFileName = PDF_File_name;
pd.DefaultPageSettings = Default_PrintProfile_PDF;
pd.PrinterSettings.DefaultPageSettings.PaperSize = paperSize;
pd.DefaultPageSettings.PaperSize = paperSize;
pd.PrintController = new StandardPrintController();
pd.PrintPage += PrintPage_As_PDF;
pd.Print();
but custom size not set, printable area is eqal to letter paper size.
please help me for this.
|
|
|
|
|
Yousef10 @ stackoverflow (SOS: "Microsoft Print PDF" PaperSize) says "don't worry" ... it's the printer's fault. And your code's the same as his; so first step -> try running your print PDF routine with a different printer?
|
|
|
|
|
Is there a way to set where to drop an event handler? When I double click on a button it drops mine at line 1500 for some reason. Then I have to cut and paste. It's doing it in a region of code and it expands that region, which is a little annoying. I'm hoping to drop at the top somewhere, possible?
|
|
|
|
|
Annoying, isn't it?
I've never found a solution to that either, and I've been using VS for 15 years ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
YES VERY VERY ANNOYING lol!! Kind of glad I'm not alone! Come on MicroSoft. Geez a whiz. It puts it in a random spot in the middle of nowhere. Where's the add event by line number?? That would make so much sense. Why MicroSoft Whyyyyy??? It would also be nice to apply a static do not expand my code unless I absolutely say so clause. And my last rant of the day is the 3 word line of code that can be simplified warning? Ok it's 3 words how much simpler can it be? I have a few more rants, but I'll table them for another day. Other than that it's a great product. And if I knew someone that was professional at this to tell me where and why's of doing things I would probably rant a lot less. But as it is all I have is Youtube and a lot of books. And nice forums like this one. So let's all be friends and give us our event handler by line number !
|
|
|
|
|
geomeo123 wrote: Where's the add event by line number?
Well ... no. Line number isn't helpful, and it's far too easy to add it in the wrong place and get code that doesn't compile - which might be quite difficult to spot! I'd rather have to move it to the right region of the file manually - which isn't hard to do - than have it appear in the middle of an XML comment, or a switch block for example.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Quote: and it's far too easy to add it in the wrong place and get code that doesn't compile
That would be pretty impossible. Since any time you click for the eventHandler MicroSoft prompts you exactly where your event code has landed so that you can start writing what you want to do when the event has occurred. I'm fairly sure choosing the line number rather than have that done for us would work.
|
|
|
|
|
You can manually add the handler name to your button in the properties window, and then add the actual handler code wherever you want.
|
|
|
|
|
Can you explain? You lost me on the word manually? Do you mean manually type it in to the event handler property text box then manually write it to whereever I want? Screenshots would be nice.
|
|
|
|
|
It seems that things have changed since I last did this, and even typing the event name into the event handler, VS automatically adds the handler skeleton at the end of the Form class.
|
|
|
|
|
Find a program with over 1500 lines of code. It doesn't add to the end of the code anymore. (which would be nice too).
|
|
|
|
|
Where would VS know where to definitively add the handler, other than at the end of the class definition in the first file of the class?
The code for a Form class could be spread across several files, so this makes identifying a target location harder. I organize my code in #region elements and have gotten (there - I said it ) used to moving the handler to an appropriate location.
/ravi
|
|
|
|
|
I don't understand your question?
|
|
|
|
|
I was suggesting there's no definitive way for VS to know where to place the new handler.
/ravi
|
|
|
|
|
Did you read the entire thread?
|
|
|
|
|
|
I have an application developed in Visual Studio 2022 that works with forms. In this application, there is a main form, from which other forms can be opened. In this main form, there is an item in the top menu (“selection”), whose name is M_Selecao, which must be activated or deactivated depending on which form was opened.
For example, when the “Expenses” form is opened, the menu must be activated (enabled).
When this secondary form is closed, the “selection” menu must be disabled. I can enable the menu, but I can’t disable it. I tried to make the main form’s menu “public” in the “TelaPrincipal.Designer.cs” file:
public System.Windows.Forms.ToolStripMenuItem M_Selecao;
This way I could disable the menu in the main form when closing the secondary form, but I get the message that "an object reference is required for the method or property 'TelaPrincipal.M_Selecao'. I also don't know how to do it from the main form. Can anyone help me? Thanks.
|
|
|
|
|
|
Ok, Richard. I'll try it. Thanks
|
|
|
|
|
OK, let's take this in two stages, starting with your error message:
An object reference is required for the non-static field, method, or property 'TelaPrincipal.M_Selecao' This is one of the most common problems we get asked, and it's also the one we are least equipped to answer, but you are most equipped to answer yourself.
Let me just explain what the error means: You have tried to use a variable, property, or a method return value but it contains null - which means that there is no instance of a class in the variable.
It's a bit like a pocket: you have a pocket in your shirt, which you use to hold a pen. If you reach into the pocket and find there isn't a pen there, you can't sign your name on a piece of paper - and you will get very funny looks if you try! The empty pocket is giving you a null value (no pen here!) so you can't do anything that you would normally do once you retrieved your pen. Why is it empty? That's the question - it may be that you forgot to pick up your pen when you left the house this morning, or possibly you left the pen in the pocket of yesterday's shirt when you took it off last night.
We can't tell, because we weren't there, and even more importantly, we can't even see your shirt, much less what is in the pocket!
Back to computers, and you have done the same thing, somehow - and we can't see your code, much less run it and find out what contains null when it shouldn't.
But you can - and Visual Studio will help you here. Run your program in the debugger and when it fails, it will show you the line it found the problem on. You can then start looking at the various parts of it to see what value is null and start looking back through your code to find out why. So put a breakpoint at the beginning of the method containing the error line, and run your program from the start again. This time, the debugger will stop before the error, and let you examine what is going on by stepping through the code looking at your values.
But we can't do that - we don't have your code, we don't know how to use it if we did have it, we don't have your data. So try it - and see how much information you can find out!
The second part is what you are trying to do, and the whole way you are going about it - so let me summarise what you are trying to achieve:
You have a main form which opens a "child" form. When some of these forms are opened, a main form menu option must be enabled, and disabled again when it closes.
First off, don't make the menu item public so that the child forms can enable or disable it - that requires the child form to "know" about how it's parent works and even that a specific parent type exists - which is against the principles of OOPs design, and complicates your code.
Secondly, that's a pretty nasty things to do, because in order to activate the menu item, the child form cannot be modal - which means it must be opened by calling Show instead of ShowDialog . The difference is that a modal form (opened with ShowDialog ) does not allow the user to continue working with the main form until the child form is closed so that menu options can't even be selected. Opening it with Show does allow the user to continue working with the main form and thus selecting items from the menu, but ... it also allows the user to do whatever opened the child form in the first place!
Which means he can open a second copy of the child form, or worse of a form that should have the menu option disabled. What state should the menu option be in then? Enabled (because the original child is open) or disabled (because a different child is also opened)? From the perspective of the user that's confusing, and could lead to problems!
So first you need to think about what you are trying to do: open a form and enable the menu item - but forbid any other form from opening, or enable and disable the parent form menu item not just when the child form is open, but when it has the input focus as well! Both can be done, but they require changes in the parent form, and communications between the two forms - the child form must tell the parent what is happening and let it decide what to do instead of trying to make changes to it itself. The way that is done in C# is via events just like clicking a button raises an event your form handles. Those aren't actually difficult to work with - though they can seem confusing - all you have to do is know how to create and raise them.
When you have decided exactly what you want to happen have a look here: Transferring information between two forms, Part 2: Child to Parent[^] - it explains how to do talk from your child form to the main form and provides sample code. You can create events to ask the parent form to Enable or Disable the menu item and let it worry about everything else - the child form then raises the event as needed and the main form just handles it internally.
I know that all probably sounds confusing and you probably wanted us to just give you code which solved your problem but it's not that simple - you need to make decisions about how your app is supposed to work, and we can't do that for you!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Once again you help me, OriginalGriff. I'll Think about. Thanks.
|
|
|
|
|