|
ljw1004 posted:You can use lambdas as event handlers! This is how you remove them: I thought that this was a very clever construction when I discovered it, and I still use it. But it has the major flaw that if the event never fires, the event handler doesn't get removed, and then you're leaking instances all over the place. Event handlers root objects. It's one of the few ways you can leak memory in C#. I have gotten to learn alllll about this the last couple weeks. You have to hold a reference to that handler somewhere so you can try to remove it yourself later. I think this isn't a problem if your object is subscribing to its own event, though. In that case, you can just implement Dispose to null out your events. Unless there's a much simpler way to handle this problem which I would love to hear.
|
# ? Jul 27, 2011 07:02 |
|
|
# ? Apr 26, 2024 08:46 |
|
Ryouga Inverse posted:I thought that this was a very clever construction when I discovered it, and I still use it. But it has the major flaw that if the event never fires, the event handler doesn't get removed, and then you're leaking instances all over the place. Event handlers root objects. It's one of the few ways you can leak memory in C#. I have gotten to learn alllll about this the last couple weeks. Ryouga Inverse posted:I think this isn't a problem if your object is subscribing to its own event, though. In that case, you can just implement Dispose to null out your events. Ryouga Inverse posted:Unless there's a much simpler way to handle this problem which I would love to hear. chglcu fucked around with this message at 10:26 on Jul 27, 2011 |
# ? Jul 27, 2011 10:19 |
|
Kind of a simple, dumb question, but is there anything out there that can "figure out" and set the correct tab order on a WinForms form? I assume it can be done if you make some assumptions about layout and how control trees should look. I assume it can't be done for our insanely messy forms, but it'd still be cool to know if anyone has come across anything.
|
# ? Jul 27, 2011 17:57 |
|
EDIT: I am using C# for this project. Not sure if this is the right place. Point me in the right direction if it is not. I'm trying to recolor a series of images based on the color a user picks. My problem is, all of my images have a white background. Is there some way to remove this white background or make it transparent? I have created the images in my code as a bitmap and then recolored the pixels using for loops. I have based my code off of some source code I have used for reference. My code is (obviously) very similar to the reference (minus the extraneous parts) but I am still getting a recolored square instead of just a recolored head, shirt, pants, etc. I'd also like to be able to remove the unnecessary white portions of the images to make my GUI look better.
|
# ? Jul 27, 2011 19:46 |
|
TJChap2840 posted:EDIT: I am using C# for this project. _aaron fucked around with this message at 01:12 on Jul 28, 2011 |
# ? Jul 27, 2011 20:10 |
|
_aaron posted:It'd probably be helpful to see the code, and you might be better off asking in the .Net Megathread (though I imagine there's quite a bit of cross-readership between that thread and this one). I was more asking if there was a known simple way. My way is technically correct, but because of the white background in my images, the result isn't correct. and, if I am not mistaken, you linked me to thread that we are in? TJChap2840 fucked around with this message at 21:04 on Jul 27, 2011 |
# ? Jul 27, 2011 21:01 |
|
_aaron posted:.Net Megathread Cool, never knew this thread existed.
|
# ? Jul 27, 2011 23:21 |
|
TJChap2840 posted:I was more asking if there was a known simple way. My way is technically correct, but because of the white background in my images, the result isn't correct.
|
# ? Jul 28, 2011 01:11 |
|
TJChap2840 posted:I was more asking if there was a known simple way. My way is technically correct, but because of the white background in my images, the result isn't correct. You look at each pixel, see if it's white, if is, set the alpha for that pixel to the max.
|
# ? Jul 28, 2011 01:49 |
|
TJChap2840 posted:I'm trying to recolor a series of images based on the color a user picks. My problem is, all of my images have a white background. Is there some way to remove this white background or make it transparent? (1) You should remove the white backgrounds BEFORE the image goes into your software. Load up Photoshop, use its tools to make the white things transparent, and save as a PNG with transparency. Then your software can load them and have Images which already have their alpha values (i.e. transparency values) correct for each pixel. (2) As for your code, well, we don't have a clue how you're doing the recoloring or what exactly is your specification for how the recoloring behaves. It's likely that you shouldn't be using a loop. Instead you should find a way that uses calls that can potentially just ask the graphics accelerator card to do the recoloring. In .NET, it looks like you can maybe use ColorMatrix to recolor your image. See if that can express the kind of recoloring you want: http://msdn.microsoft.com/en-us/library/7fkd49hh.aspx http://msdn.microsoft.com/en-us/library/6tf7sa87.aspx
|
# ? Jul 28, 2011 02:10 |
|
ljw1004 posted:(1) You should remove the white backgrounds BEFORE the image goes into your software. Load up Photoshop, use its tools to make the white things transparent, and save as a PNG with transparency. Then your software can load them and have Images which already have their alpha values (i.e. transparency values) correct for each pixel. Thanks for the help. I think I have the issue solved. I'm going to look into into drawing the images using Graphics instead of trying to mess around with PictureBoxes tomorrow As for code: code:
|
# ? Jul 28, 2011 06:48 |
|
What's the fastest way to get a bunch of data from Excel into a SQL Server table with C# and ADO.net (or something else)? Doing it row by row, even within a transaction and using prepared statements, is slow as hell. Like, several minutes for a few thousand rows, even if they contain just one or two int columns. The MS import/export tool from their toolkit does the same thing in seconds, but it would be much more convenient to do it directly from my app for everyone involved. Also, the reverse would be great too - the Office interop method I'm using to export data into excel and format it appropriately is slooooow.
|
# ? Jul 28, 2011 13:30 |
|
mobby_6kl posted:What's the fastest way to get a bunch of data from Excel into a SQL Server table with C# and ADO.net (or something else)? Doing it row by row, even within a transaction and using prepared statements, is slow as hell. Like, several minutes for a few thousand rows, even if they contain just one or two int columns. The MS import/export tool from their toolkit does the same thing in seconds, but it would be much more convenient to do it directly from my app for everyone involved. Use a DTS package, SSIS can do stuff like that on a timed or triggered basis. Edit: I should add that when you do an import though management studio, it creates a one-off DTS package to perform the import. SSIS is quite good at reading data out of excel files. No need to reinvent the wheel. Dietrich fucked around with this message at 15:37 on Jul 28, 2011 |
# ? Jul 28, 2011 13:34 |
|
mobby_6kl posted:What's the fastest way to get a bunch of data from Excel into a SQL Server table with C# and ADO.net (or something else)? Doing it row by row, even within a transaction and using prepared statements, is slow as hell. Like, several minutes for a few thousand rows, even if they contain just one or two int columns. The MS import/export tool from their toolkit does the same thing in seconds, but it would be much more convenient to do it directly from my app for everyone involved. Look into the SqlBulkCopy class, it's designed exactly for this sort of thing.
|
# ? Jul 28, 2011 15:06 |
|
The above advices are good and probably the right answer. That said, the troubleshooting part of my guesses that the issue is on the read side -- how are you pulling data from excel?
|
# ? Jul 28, 2011 15:35 |
|
From my testing in the past, the fastest way to get data into Excel is by putting tab delimited data onto the clipboard and pasting it in. Unfortunately, it's also a fragile method that can easily fail silently with large amounts of data.
|
# ? Jul 28, 2011 15:53 |
|
Be wary that SQL Management Studio can do a really lousy job of figuring out what data type to use for the sql columns. It only scans the first x amount of rows(instead of, I dunno, using the column cell type from the Excel file) and then picks out a data type. This annoys the poo poo out of me when I import data at work and it decides that zip codes should be floats, or that a column with mixed alphanumeric characters should be an int because the rows it scanned happened to all be convertible to int. Edit: Also the one time I wanted it to throw an error, it didn't. I think this was on SQL 2000, but we had to import a bunch of contact info from an Excel 2003 file. The import wizard decided "Hey! Phone numbers! Those should be int values!" and then proceeded to null out any cell where the phone number(as an integer) would be greater than 2,147,483,647. PhonyMcRingRing fucked around with this message at 03:44 on Jul 29, 2011 |
# ? Jul 29, 2011 03:38 |
|
^^^ Yeah, I noticed that too, but thankfully you can specify the types yourself with a bit more effort. wwb posted:The above advices are good and probably the right answer. That said, the troubleshooting part of my guesses that the issue is on the read side -- how are you pulling data from excel? Actually, the data is already in memory by the time I try to upload it, I don't recall right now (or have access to the code) but it's either in a list/array or a datatable. Actually reading with Jet db is pretty fast anyway. I'll try the stuff suggested here and see how it works. As for exporting to excel, I suppose I could directly write a CSV, but then all the formatting would have to be done manually or with macros
|
# ? Jul 29, 2011 14:03 |
|
If I recall, while working with Excel in Office macros, accessing the cells is like accessing a 2-dimensional array. It should be relatively trivial to have 2 nested for loops in your code to loop your in-memory dataset and dump it into an in-memory Excel spreadsheet, then just save it to disk after doing whatever formatting you wish to it.
|
# ? Jul 29, 2011 14:44 |
|
Open xml is the easiest way to work with excel spreadsheets programmatically, afaik. I believe it only handles 2007 and up (xlsx format), but if that's an acceptable limitation, the ease of working with cells/formatting/etc is well worth it. http://blogs.msdn.com/b/erikaehrli/archive/2008/06/10/announcing-the-open-xml-format-sdk-1-0.aspx
|
# ? Jul 29, 2011 16:47 |
|
^^^yup. Another option if you need pre 2007 compatibility is spreadsheet XML, look up CarlosAgExcelXmlWriter for that.
|
# ? Jul 29, 2011 16:56 |
|
This is an embarrassingly dumb question that you guys are going to laugh at me for but here goes: Visual Studio 2005 working on an auto-converted old project. I'm make a new EDI document translator (210) and I've got some great sample code that I've tweaked all the logic for perfectly (as opposed to writing the code from scratch like I did for 810/850/856 etc.). The problem? The original project is so old, that it doesn't include <formname>.designer.vb, which means I can't launch Design mode. Is there a way to automate generation of the designer.vb file? I notice there's a giant swack of code in the 'Windows Form Designer generated code' region; do I just have to move all that into a 'fake' designer.vb that I make myself? Sorry for the basic nature of the question, but I've never really 'got' how the design side fits together (I normally write data transformation/non-interactive services).
|
# ? Jul 29, 2011 19:02 |
|
Why not just connect to the Excel spreadsheet directly via a oledb connection? Then select the data out into a data table, and feed that to your sqlbulkcopy object.
|
# ? Jul 29, 2011 20:29 |
|
So I have a VC# project that I'm building on a Win 7 64-bit machine. This is the login screen I expect, and that I'm getting on this primary machine. Note how the Server list box on top has two visible lines; the Domain and Project list are the same way. When I install the published app on an XP machine, this is what I see: The list boxes have collapsed to one visible line each. This makes choosing servers, domains, and projects a pain in the rear end. What could be causing this?
|
# ? Aug 2, 2011 01:07 |
|
IMJack posted:So I have a VC# project that I'm building on a Win 7 64-bit machine. This is the login screen I expect, and that I'm getting on this primary machine. Anyhow, I would highly suspect this has something to do with application styles. I believe there should be something in your program main before the form is launched where you can control whether windows styles should be used in your application. I'd try hardcoding your app to a certain (backwards compatible) style and see if that fixes the discrepancies between OSes (first is to ensure the form elements look the same on both OSes, next is to get them to look the way you want them to look).
|
# ? Aug 2, 2011 03:30 |
|
IMJack posted:The list boxes have collapsed to one visible line each. This makes choosing servers, domains, and projects a pain in the rear end. What could be causing this? Your Windows 7 system appears to be using large fonts, and your Windows XP system is not. Windows Forms, by default, will automatically attempt to change the location and size of controls when the system font size is different; but because Windows prefers crisp scaling instead of smooth scaling, so the metrics change in surprising ways as a result. So what it appears to be happening is that Windows Forms is shrinking the listbox to account for the smaller system font size, but it's shrinking it enough that the IntegralHeight property of the ListBox is forcing it to collapse down to one line.
|
# ? Aug 2, 2011 04:59 |
|
Can any gurus here comment on http://northhorizon.net/2011/the-right-way-to-do-inotifypropertychanged/ ?
|
# ? Aug 2, 2011 16:07 |
|
IMJack posted:So I have a VC# project that I'm building on a Win 7 64-bit machine. This is the login screen I expect, and that I'm getting on this primary machine. Change the control to a combo box with dropdownstyle as dropdown .
|
# ? Aug 2, 2011 16:56 |
|
epswing posted:Can any gurus here comment on http://northhorizon.net/2011/the-right-way-to-do-inotifypropertychanged/ ? That looks like a pretty elegant solution. I used a combination of the lambda and the MS recommendation, which isn't as painful to work with if you're also using ReSharper. The lambda issue is only god-awfully slow if you're doing a lot of notifications - updating a property through databinding after a user has tabbed off a field isn't going to (or usually shouldn't) trigger a load of notification events.
|
# ? Aug 2, 2011 17:21 |
|
epswing posted:Can any gurus here comment on http://northhorizon.net/2011/the-right-way-to-do-inotifypropertychanged/ ? He creates separate callback methods for each property change. This has pros and cons so I'd say it's personal preference. The alternative: code:
I don't like how he handles the Foobar property. I would prefer this: code:
code:
|
# ? Aug 2, 2011 17:48 |
|
I appreciate it only runs in Debug, but creating StackTraces is horrible for performance, and is likely to bite you in the rear end with race conditions and whatnot when everything runs faster on Prod. More importantly, it uses reflection to subscribe to events. This could be fairly horrible if you're subscribing to lots of objects. Additionally, it doesn't seem like there's a nice way of raising PropertyChanged events on calculated fields (Silverlight still does not support multi-value binding, or even a nice way of saying "Holy poo poo, the entire object has changed", so you're stuck with sometimes triggering multiple RaisePropertyChanged calls from a single setter). The code whilst beautiful, doesn't live in a vacuum - you'd still be using the old form of INotifyPropertyChanged when dealing with ObservableCollection, auto-generated code (e.g. WCF web services and no one hand cranks that poo poo unless there is a bloody good reason to). Also it doesn't really work for views, given the point that you don't need to know the exact type of the view model, just that it has some properties. To be quite blunt, it smacks of something done by someone who needs to learn when to let go of type safety a little. Don't do this sort of thing in a work project.
|
# ? Aug 2, 2011 21:34 |
What's the best way to redirect urls from domains in IIS7. So let's say my client buys https://www.bad-example.com adds it to my DNS, and wants it to go to https://www.my-domain.net/bad-example ? I can figure it our for paths after "/" but not redirects for the base domain. Right now all I can get is those URLs to point to https://www.my-domain.net. Do I have to set up a new website to do this? It's been a long day, so maybe I'm just not thinking straight. But IIS6 seemed a lot better at this sort of thing... \/\/\/Thanks\/\/\/ A MIRACLE fucked around with this message at 23:31 on Aug 2, 2011 |
|
# ? Aug 2, 2011 22:46 |
|
A MIRACLE posted:What's the best way to redirect urls from domains in IIS7. So let's say my client buys https://www.bad-example.com adds it to my DNS, and wants it to go to https://www.my-domain.net/bad-example ? I can figure it our for paths after "/" but not redirects for the base domain. Right now all I can get is those URLs to point to https://www.my-domain.net. Do I have to set up a new website to do this? Yea you have to create a new website folder that binds the dns name or ip address/port. Sprawl fucked around with this message at 23:00 on Aug 2, 2011 |
# ? Aug 2, 2011 22:57 |
|
Or bind the same website to bad-domain.net and then use the url rewriting function to point it in the right direction.
|
# ? Aug 3, 2011 15:01 |
|
I'm trying to work on a Silverlight application and I don't really want it to open in my default browser (Opera) because if it does and I hit a breakpoint, the whole browser is locked until the debugger is finished. I tried using the option in the ASP solution to start an external program, but when I run it that way, no debugging symbols will load. Has anybody else had this problem and figured it out?
|
# ? Aug 4, 2011 23:26 |
|
You can change the default browser that Visual Studio uses:quote:...right click on the web page that has your Silverlight control (such as default.aspx) and choose “Browse with…” from the context menu.
|
# ? Aug 5, 2011 01:57 |
|
There is even a VS2010 extension for fast browser switching. Also, my experience with other web apps is that if you just open the browser and browse to the url you get the same server-side debugging session. Not sure if that applies to SL as I don't play that poo poo.
|
# ? Aug 5, 2011 14:13 |
|
Sedro posted:You can change the default browser that Visual Studio uses: Funny story - picking IE still opens the page in Opera, but in a private tab for some reason. Doesn't matter, though. There are still no debug symbols loaded on any other browser. Edit: Setting IE as the system default works but not FF. Ugh Munkeymon fucked around with this message at 14:55 on Aug 5, 2011 |
# ? Aug 5, 2011 14:42 |
|
Prefacing this by saying that I have very little .NET experience. My company uses an internal tool for automating certain kinds of hardware testing which uses C# for scripting. There's a device I'd like to talk to inside one of these scripts which is not supported by the tool natively, but I found a C library that lets me talk to it. What I've done is wrapped the C Library in a C++/CLR class, then compiled that into a DLL, used Assembly.LoadFile to load the DLL, assembly.GetType() to get my class, Activator.CreateInstance() to make an instance of my class, then Type.InvokeMethod() to call methods on the class. This works, but I feel like I'm making something that's going to show up in the Coding Horrors thread in a couple of years. Is there a Simpler / Better way to do this? The tool I need to be able to run this in is running on .NET 2.0.50727.3623 and seems to be using NRefactory to parse the C# scripts (I am guessing anyway, because I found a dll for that in the application directory). Stupid internal politics prevent me from having access to the source of the tool I'm trying to interact with, so the only solutions I can use are ones that can be run directly in the script. TasteMyHouse fucked around with this message at 20:17 on Aug 8, 2011 |
# ? Aug 8, 2011 17:52 |
|
|
# ? Apr 26, 2024 08:46 |
|
You should be able to reference the C++/CLR wrapper class without a bunch of reflection. There is a way to add a reference using CodeDom, and I would assume NRefactory as well. If the scripting tool doesn't expose this, you're SOL. If you were using .NET 4, dynamic dispatch would make things a bit easier.
|
# ? Aug 8, 2011 20:14 |