Now the garbage collector always sees a reference to the Icon object as long as the form object stays alive. Panel1.Cursor = panel2.Cursor = new Cursor(customCursor.Handle) You have to write it like this instead: private Icon customCursor On the Devices page, click the Device Name for the device on which you want to enable anomaly. The only relevance of the images is what impact they have on the GC. So as soon as the garbage collector runs, the icon object is history. That is a problem in your code, you are not making sure that the new object returned by is referenced anywhere. What it does mean is that Handle is only valid as long as the Icon object is not destroyed. This a bit more cryptic than it could be, to put it mildly. This is not a copy of the handle do not free it. Maybe i shouldn't be using the cursors this way, but the question remains, what makes c# behave in such a way when nothing but the background image is being modified.įrom the MSDN article for the Icon.Handle property that you use: I just want to find out what causes this behavior as I encountered it while working on bigger project, and it took me a while to track the core of the problem. 1 Form, 2 Panels, 1 icon as the cursor, 3 images and a totally senseless (or maybe not, maybe i'm missing something) behavior. There is nothing else that's being modified in the entire project. If I change the backgroundimagelayout property of the form to None instead of Tile, the cursor works no matter what the image is. I know they can unlock new technologies (key), provide science points (beaker) and maybe do other stuff like tech cost reductions (magnifying glass). I've even found an image with which panel1 has its cursor for the first few seconds, but if I happen to get out and back in the panel after those few seconds, the cursor gets permanently removed. So, I was wondering, has anyone kept track of whether an anomaly's icon indicates what you sort of get from scanning it I have seen anomalies with a magnifying glass, with a beaker and with a key. The game takes places in the years following the invasion of Earth in. When I set other images, only the second panel has its cursor. Anomaly 2 is a real-time strategy game that takes the tower offense concept from Anomaly Warzone Earth to a new level. When I set some of them and run the program, both of the panels have their custom cursor. I've downloaded multiple random images from various sources and set them as form's background image. Now, the weird behaviour starts when I modify the backgroundimage property of the Form. The only code the project will have is this using System I've reduced the problem to a new project with 1 form, 2 panels added to the form, 1 icon added to project's properties/resources.resx, and 3 images added to the same place. I've come across some weird behavior while playing with custom cursors in c# using Windows Forms.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |