Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
chippy
Aug 16, 2006

OK I DON'T GET IT
Someone please help me with this problem, it's driving me mental.

I maintain and extend an old .net 3.5 Winforms app. It was created in VS 2008 but I recently updated the project to VS 2013. As part of the migration, it automatically switched the targeted framework to 4.5. I didn't want to force all my users to upgrade (they have some XP machines), so I switched the target back to 3.5. There was a warning that I might have to manually edit some project files to get it to build, but it built and run fine so I didn't worry about it after that, everything was running fine on the customer's machines.

Recently I was asked to make some changes in part of the system that uses a bunch of stuff from Windows.Forms.DataVisualization.Charting. I can't open these forms up in the designer, I get a big page of errors and a warning that the designer might become unstable and I might lose some controls. The main errors are a bunch of failures to resolve the charting classes, stuff like this:

"Could not find type 'System.Windows.Forms.DataVisualization.Charting.ChartArea'. Please make sure that the assembly that contains this type is referenced. If this type is part of your development project, make sure that the project has been successfully built using settings for your current platform or Any CPU'.

If I ignore them and open them in the designer, all those charts disappear.

The thing is, all the references in the project are pointing to the 3.5 version of the assembles, the projects build and run fine, and if I add new charts, they work fine too. The only thing that doesn't work, is opening up the existing forms in the designer. I don't understand why the compiler can resolve the references, and build the project, but the designer can't.

I've tried deleting and re-adding the references and it doesn't help. Although one thing I've noticed is that if I hover over the Chart control in the toolbox, it says version 4.0, even if I manually add those controls by adding the 3.5 version of the DLL onto the toolbox.

I tried switching the project to 4.0 and was then able to open the forms in the designer (wtf), but then when I tried to add new charts, I got an error message about not being able to create a reference to the assembly, which also seems odd, since I already had one. I managed to fix this by deleting and re-adding the references, and then everything worked, but the project was targeting 4.0, which I'm really trying to avoid.

Does anyone have any idea how I can get this working while still targeting 3.5?

Adbot
ADBOT LOVES YOU

chippy
Aug 16, 2006

OK I DON'T GET IT

chippy posted:

Someone please help me with this problem, it's driving me mental.

I maintain and extend an old .net 3.5 Winforms app. It was created in VS 2008 but I recently updated the project to VS 2013. As part of the migration, it automatically switched the targeted framework to 4.5. I didn't want to force all my users to upgrade (they have some XP machines), so I switched the target back to 3.5. There was a warning that I might have to manually edit some project files to get it to build, but it built and run fine so I didn't worry about it after that, everything was running fine on the customer's machines.

Recently I was asked to make some changes in part of the system that uses a bunch of stuff from Windows.Forms.DataVisualization.Charting. I can't open these forms up in the designer, I get a big page of errors and a warning that the designer might become unstable and I might lose some controls. The main errors are a bunch of failures to resolve the charting classes, stuff like this:

"Could not find type 'System.Windows.Forms.DataVisualization.Charting.ChartArea'. Please make sure that the assembly that contains this type is referenced. If this type is part of your development project, make sure that the project has been successfully built using settings for your current platform or Any CPU'.

If I ignore them and open them in the designer, all those charts disappear.

The thing is, all the references in the project are pointing to the 3.5 version of the assembles, the projects build and run fine, and if I add new charts, they work fine too. The only thing that doesn't work, is opening up the existing forms in the designer. I don't understand why the compiler can resolve the references, and build the project, but the designer can't.

I've tried deleting and re-adding the references and it doesn't help. Although one thing I've noticed is that if I hover over the Chart control in the toolbox, it says version 4.0, even if I manually add those controls by adding the 3.5 version of the DLL onto the toolbox.

I tried switching the project to 4.0 and was then able to open the forms in the designer (wtf), but then when I tried to add new charts, I got an error message about not being able to create a reference to the assembly, which also seems odd, since I already had one. I managed to fix this by deleting and re-adding the references, and then everything worked, but the project was targeting 4.0, which I'm really trying to avoid.

Does anyone have any idea how I can get this working while still targeting 3.5?

Further to this...

On my work machine (probably because I hosed around with it so much yesterday, trying to clear out all .NET 4.0 versions of the charting DLLs), I'm no longer able to add the .NET 3.5 chart controls to my toolbox in VS 2013. If I drag the DLL on, nothing happens. If I choose "Add Items", browse to the DLL and select it, I'm told the file doesn't exist, which is clearly not true as I just browsed to it.

And before that, if I add the chart DLLS from C:\Program Files (x86)\Microsoft Chart Controls\Assemblies, I'd get the massive page full of errors saying the types could not be found, but if I added the exact same files from a different location (C:\Charts), I'd get a single message saying the assembly couldn't be loaded.

So last night I tried the project on VS 2013 on my machine at home. I was able to install the .3.5 Chart Controls, add them to my toolbox, and add a chart to the project, all with no issues. But then when I saved, closed and re-opened the project, I got the page full of errors saying the types couldn't be initialised, on the form that was previously working fine in the designer.

Help :(

chippy
Aug 16, 2006

OK I DON'T GET IT

Newf posted:

I cannot help, but you have my sympathy. These are the parts of development that make me want to jump out of a plane.


You're telling me. I can't even add the 4.0+ Chart Controls to my toolbox anymore in VS 2013. They're in my GAC and I can add references to the project but if I try and add them to my toolbox they're not in the list of available .NET components, I have to browse to the files or drag them onto the toolbar. The former produces a message telling me either the DLL is invalid or doesn't exist, depending on what version I try. The latter produces a default 'bing' sound and absolutely nothing else

This is after completely uninstalling and reinstalling VS and the .NET Framework.

Some of these chart widgets are on the main dashboard of the software so I can't even do any changes to that any more because even I changed something unrelated, the designer fucks the charts up.

I've had to go back to an older branch of the project on VS 2008 for now, but the other migrated version has a couple of months of work on other features on it, including changes to various forms, so including designer files, and I've no idea if it'll even be possible to merge that into the unmigrated VS 2008 branch without buggering up everything.

chippy
Aug 16, 2006

OK I DON'T GET IT
I sometimes scaffold a view or two and then customise it, just to get all the labels and displayfors and things in place first, but I generally do it manually. Controllers I always just write from scratch.

chippy
Aug 16, 2006

OK I DON'T GET IT
Well, after my previous posts, I can no longer add chart controls of any version to my toolbox in Visual Studio, to the point where I've had to install Windows and VS 2013 on a VM today in order to do anything.

Incidentally, on the VM, if targetting .NET 3.5, I can add chart controls to my toolbox and add them to a form in the designer and it seems but, but if I close and re-open the solution again, the designer freaks out in the same way as before, saying the types are undefined. Even though I added them in the same environment right before.

Targeting .NET 4, I can add the controls. At this point I think I might just force an upgrade on my users.

chippy
Aug 16, 2006

OK I DON'T GET IT

Newf posted:

Ah, that clarifies.

Overriding Equals did work (thanks Betjeman!), but I was confused because I knew that Add (and Contains) were supposed to be O(1), so I figured that it had to be checking with GetHashCode(). Makes sense that it's done as a first pass.

Thanks all.

Bear in mind that it's also recommended that if you override Equals(), you should also override GetHashCode(), to ensure that in any case where Equals() returns true for a pair of objects, GetHashCode() would return the same hash, and vice versa.

In Java at least, if you don't do this, you can get funky behaviour with Sets and other collections. I'm not 100% sure if this applies to C# too, but I would think it likely.

chippy
Aug 16, 2006

OK I DON'T GET IT

RICHUNCLEPENNYBAGS posted:

Yes, I know that. But that doesn't help me do things like visit expressions, modify them, etc. So what I would like to see is the equivalent, long-way-round code. I think maybe you can do this by compiling and then decompiling with the decompiler set to a lower version of .NET or something like that.

Is this what you need?

http://msdn.microsoft.com/en-us/library/bb397951.aspx

chippy
Aug 16, 2006

OK I DON'T GET IT
Help a brother out with a simple Winforms problem.

I want a ComboBox that you can type in, and it will autocomplete/suggest items from the list, but NOT allow free entry of something not in the list - it still has to be something from the list.

Setting the ComboBoxStyle to DropDownList comes close, but it doesn't "walk along" search; pressing a key jumps to an item whose first letter matches the key you pressed, but pressing another key will do the same again instead of matching the second character.

Is there a way of achieving this that doesn't involved hijacking OnKey or TextChanged events? This seems like something that should be easy without that much loving about.

chippy
Aug 16, 2006

OK I DON'T GET IT
I'm working on a number of reporting widgets for a factory control system that I maintain. They show KPIs in a variety of formats. The boss wants to be able to resize them so he can have them nice and big on large displays in the factory, and he always wants to be able to make them small so he can open lots of them on one screen for his own benefit.

I've got the charts themselves resizing nicely but the labels (not the chart labels, but other text labels on the form) are being a real pain. At the moment I'm having to just fiddle about and find optimum font sizes for different heights and weights of the form, and change them as appropriate by handling the resize event. Does anyone know if there's a less fiddly and soul destroying weight of doing this? Something a bit more automagic?

chippy
Aug 16, 2006

OK I DON'T GET IT

Bognar posted:

Why not make use of Ajax? The "link" is just an anchor tag that is bound to an event that fires an Ajax POST to your server. You could then register a callback on successful completion of that HTTP request to change that row, refresh the table, or do whatever you want to do.

This is what I would do. Use Ajax.ActionLink. You can set the method to POST in the Ajax options so that you can't just approve users using the URL. It would be something like this (dependant on the name of your action methods and controllers):

code:
@Ajax.ActionLink("Approve", "ApproveUser", new { userId = item.Id }, new AjaxOptions {HttpMethod = "POST", Update-Target="user-list"})
If you pass a collection of users to the view you can iterate over it and generate a bunch of links like this, one for each user. You will need to include one of the ajax javascript files like unobtrusive, although I think these are referenced by default anyway.

e: If it's not referenced by default you can install it with NuGet: http://www.nuget.org/packages/jQuery.Ajax.Unobtrusive/

e: This might be worth a look too: http://haacked.com/archive/2009/01/30/simple-jquery-delete-link-for-asp.net-mvc.aspx/
e: This is also good reading, although it deals with delete links, a lot of these concepts apply still: http://stephenwalther.com/archive/2009/01/21/asp-net-mvc-tip-46-ndash-donrsquot-use-delete-links-because

chippy fucked around with this message at 11:10 on Nov 11, 2014

chippy
Aug 16, 2006

OK I DON'T GET IT

mortarr posted:

In fact, I remember I got so cross with the whole thing I put the report up on the sql server and just called that from my mvc proj.

This is what we do too.

chippy
Aug 16, 2006

OK I DON'T GET IT
Can I use a List of Strings as a the key for a dictionary?

Or, can anyone think of a neat solution to this? I've got a collection of Foos, each of which has a collection of Strings. I need to find each unique list of Strings, along with the Foos that share it.

p.s. VB, not C#, if it makes any difference.
p.p.s. I am aware that this is a somewhat remedial level question, but I am ill and sleep deprived and it is the end of the day.

chippy fucked around with this message at 18:24 on Dec 22, 2014

chippy
Aug 16, 2006

OK I DON'T GET IT

Sedro posted:

You can, but the List in .NET doesn't implement equality/hash in terms of its items. So you should use a custom EqualityComparer when you construct the dictionary.

Thanks, yeah I just tried it out in LINQPad and found that the standard equality operator won't work. I'll look into that.

chippy
Aug 16, 2006

OK I DON'T GET IT
Thanks everyone. I ended up writing a custom IEqualityComparer and using GroupBy().

chippy
Aug 16, 2006

OK I DON'T GET IT
DreamSpark is pretty great. You don't get quite as much stuff as is available with an MSDN subscription but there is plenty of stuff, including all versions of VS.

I signed up for the Github student developer pack thing recently and was told they would email me about it in "a few weeks". Anyone know why there's such a long delay setting it up?

chippy
Aug 16, 2006

OK I DON'T GET IT
For what it's worth, I've seen non-conflicting merges produce invalid XML in project files as well.

chippy
Aug 16, 2006

OK I DON'T GET IT
I'm afraid I don't know the answer to your specific question but this looks to be a good starting point:

https://msdn.microsoft.com/en-us/library/office/hh243703(v=office.14).aspx
https://msdn.microsoft.com/en-us/library/office/hh243697(v=office.14).aspx

edit: Looks like you would want to use the ConversationManager to get the Conversation that interests you, and then you can set the title via its 'Properties' Property dictionary, one of which is 'Subject', which I'm guessing is probably the title you want.

https://msdn.microsoft.com/en-us/li...office.14).aspx

chippy fucked around with this message at 17:59 on Feb 17, 2015

chippy
Aug 16, 2006

OK I DON'T GET IT
In WinForms, if I've got a ListBox showing a list of entities, and I want to update this listbox with a fresh list I just pulled out of the database, what's the 'best practice' way of doing this?

More specifically, I want to maintain the selection. If an item is selected in the list and is still in the list after the update, it should remain selected. It it's removed I guess the selection should jump back to the first in the list, or maybe the previous.

Just changing the DataSource property to the new collection will reset the selected item as well. I'm guess I should be using a BindingSource or something like that?

chippy fucked around with this message at 14:35 on Feb 25, 2015

chippy
Aug 16, 2006

OK I DON'T GET IT

crashdome posted:


From my horrible WinForms memory:
You'll have to store a key or some way to lookup the object in the new datasource, find the index, and reset the selected index if you choose to change the datasource. - This is the fastest for large lists but the change in datasource may cause UI flickering or some other weird behavior if you hold object references.
The alternative is to have a single datasource that you add or remove items by comparing your refreshed data with the existing data.

Either way you go, if the list is small (say <1000 items), you wont see any performance problems. Although, I recommend keeping a single datasource and updating it yourself manually if it is only ever "read only" list. You can use the datasource methods to perform lookups and object comparisons. For example, with a single datasource, you can grab a reference to the selected object prior to refresh, see if it exists in the datasource when refreshed and if not, just set selected index to 0 (assuming there is always at least one item) and leave well enough alone. Its pretty simple too...

[*]Clone your datasource as a new list of "To be deleted" and make an empty "to be added" list
[*]Traverse the refresh list, compare items, and remove existing items from the "delete list" while also adding new items to the "to be added" list
[*]Remove and add each list as a range from your datasource

This has, for me, been the most effective and smooth way to do it and keep the UI responsive.

Thanks for this. When I used the List as the datasource for the ListBox directly, it didn't seem to update the display of the listbox as I added and removed items. I ended up creating a BindingSource with the list as its datasource, and then using that as the datasource for the listbox. Once I did it that way, it kept up with any items added or removed, and also took care of maintaining the selection automatically.

chippy
Aug 16, 2006

OK I DON'T GET IT

crashdome posted:

Yeah, BindingSource is great. A list doesn't have any INotify ....blah blah... so you'd have to call Suspend, Resume, Refresh on the listbox control manually during the update. Thanks for reminding me how much I don't miss WinForms.

Yeah, it sucks balls. Really hoping to get some WPF work in my job come up so I have a chance to learn it - I don't have the time in my spare time in between doing my degree. I used to do 3 days a week on a MVC project and 2 days on the old Winforms nonsense but it's been 5 days a week on Winforms recently :(

chippy
Aug 16, 2006

OK I DON'T GET IT
Another (VB) WinForms question for you. I found out yesterday that a custom control (a sort of file browser thing cobbled together out of a treeview) was throwing null reference exceptions in multiple places. However, none of the users had mentioned it to me. After some fiddling I realised that they are only thrown when I'm debugging, and when the app is running in deployment, something is swallowing them.

The exceptions are being thrown by code in event handlers for drag and drop events, there is no Try/Catch block in the handlers... where exactly 'above' the form can they be being caught? My googling so far has suggested that they might be being caught by a Try/Catch in the 'Main' sub, but I haven't explicitly implemented one so it seems that in Winforms that means it would be getting injected by the compiler when built - or, that it could be being caught by global exception handling, but ApplicationEvents.vb is empty.

Does anyone know where this exception could be going, or how I can found out?

update: I placed a button on the form that holds the control that's throwing the exceptions, that does nothing but throw a new NullReferenceException. If I click this in deployment, the unhandled exception is being alerted and the program exits, so it's not that somethign is catching all such exceptions. What is the difference here? The custom controls are in a seperate project in the same solution, could this have anything to do with it?

another update: I put a TreeView on the form next to the custom control and wrote drag-drop event handlers for it that just throw exceptions. They just disappear when running in deployment just like the custom control ones do. So I guess it's not to do with it being in a different project. Could it be something to do with it being a drag event?

chippy fucked around with this message at 11:29 on Mar 4, 2015

chippy
Aug 16, 2006

OK I DON'T GET IT
Ah. It's because it's in a drag drop event. Something to do with boundaries between managed and unmanaged code.

chippy
Aug 16, 2006

OK I DON'T GET IT

Hughmoris posted:

Is there a simple way to iterate through regex matches in C#?

For instance, if I have a string: "Test string 123 and another 456 and a third 789"
And I want to capture any three digits that are together, I think my regex pattern would be "(\\d\\d\\d)"

I'd like to regex the test string and have an output of:

123
456
789

The little snippets I can find online seem overly complicated for iterating through matches.


code:
string testString = "Test string 123 and another 456 and a third 789";
Regex testRegex = new Regex(@"\d\d\d", RegexOptions.Compiled);
foreach (Match testMatch in testRegex.Matches(testString))
{
	Console.WriteLine(testMatch.Value);
}
Match has other properties you can access too if you need more than just the matched string. Using @ before the string means you don't have to escape your escape characters.

chippy
Aug 16, 2006

OK I DON'T GET IT
Does anyone know--- if you call a method that does ADO.NET stuff, from inside a 'using x as TransactionScope' block, does the stuff in the called method get done within the transaction scope too?

e: Looks like yes.

chippy fucked around with this message at 10:35 on Mar 13, 2015

chippy
Aug 16, 2006

OK I DON'T GET IT

Scaramouche posted:

Off the top of my head the &/&&/AndAlso and |/||/OrElse are probably the two biggest 'gotchas' about VB.net as compared to how other languages work. Actually bitwise operators too have a few quirks, maybe brain up on them:
https://msdn.microsoft.com/en-us/library/wz3k228a.aspx

The other big change is how variable declaration is done, but that's mostly syntactical and you probably won't even run into it unless you're doing a bunch of List (of or LINQ style one line statements.

I know this was a couple of pages back but it's probably also worth mentioning that 'And' does not short-circuit whereas 'AndAlso' does, likewise 'Or' and 'OrElse'.

chippy
Aug 16, 2006

OK I DON'T GET IT
Dapper performance question, if anyone can help:

I'm using dapper in a Winforms project. At some point, I have to shove a load of Foo's (anything from 1 to probably around 100 at the top end) into the database. Dapper handles this pretty nicely, I can pass the SQL and the collection of Foos in to the Execute method and it deals with it. Previously it was fine to just shove them in the db and forget about them as that is the last time they were needed. Now, however, I need to populate their ID fields as they are updated as we need them for something afterwards. This is easier enough to do, I'll just add SELECT SCOPE_IDENTITY() on to the end of the SQL and use the Query() method instead. However, this does mean I can't just hand in the collection of Foos because I need to individually update the ID property of each one, so I'll have to loop through the collection and hand each into the Query method individually.

Two questions here: Is there a better way of doing this with Dapper, and is this going to perform horribly compared to the batch insert I was doing before?

If it makes any difference, I'm doing all of this wrapped in a TransactionScope.

chippy fucked around with this message at 18:05 on Apr 13, 2015

chippy
Aug 16, 2006

OK I DON'T GET IT

chippy posted:

Dapper performance question, if anyone can help:

I'm using dapper in a Winforms project. At some point, I have to shove a load of Foos (anything from 1 to probably around 100 at the top end) into the database. Dapper handles this pretty nicely, I can pass the SQL and the collection of Foos in to the Execute method and it deals with it. Previously it was fine to just shove them in the db and forget about them as that is the last time they were needed. Now, however, I need to populate their ID fields as they are updated as we need them for something afterwards. This is easier enough to do, I'll just add SELECT SCOPE_IDENTITY() on to the end of the SQL and use the Query() method instead. However, this does mean I can't just hand in the collection of Foos because I need to individually update the ID property of each one, so I'll have to loop through the collection and hand each into the Query method individually.

Two questions here: Is there a better way of doing this with Dapper, and is this going to perform horrible compared to the batch insert I was doing before?

If it makes any difference, I'm doing all of this wrapped in a TransactionScope.

p.s. I'm gonna test this myself, just hoping someone also happens to have a quick answer :)

chippy fucked around with this message at 18:04 on Apr 13, 2015

chippy
Aug 16, 2006

OK I DON'T GET IT

Mr Shiny Pants posted:

For a 100 inserts? I would test it, I think you will be pleasantly surprised by the performance.

Yeah, I'm not expecting it to take too long. I know that Dapper is pretty performant and this isn't a lot of data to be inserting, the problem is that this application is used at a factory where it's run on a lovely network. mostly on terminals with poor wireless connections, and all supported by a copy of SQL Server 2008 Express running on lovely old hardware. All of which they are very resistant to improving if it involves spending any money. There are hundreds of these inserts flying around all the time and they do have performance issues already, so I have to be very careful with anything that might make it worse.

chippy
Aug 16, 2006

OK I DON'T GET IT
Piss, it takes about twice as long.

e: No it doesn't, I'm a twat.

chippy fucked around with this message at 10:12 on Apr 14, 2015

chippy
Aug 16, 2006

OK I DON'T GET IT
I would absolutely love to be able to do something like that but I would never be given the time to do it. The application is a years-old hulking mess cobbled together by a non-programmer and most parts of it are too far gone for anything other than a major rewrite. There's no core application, just a load of WinForms clients throwing SQL at the database. I posted some code once in the Coding Horrors once and got a lot of condolences and "get out as soon as you can" type responses. It's just me, bolting on new features on my own, to unreasonably short timescales.

chippy
Aug 16, 2006

OK I DON'T GET IT
gently caress me, ListViews in WinForms are the WORST thing.

chippy
Aug 16, 2006

OK I DON'T GET IT
Does anyone know why Visual Studio would do this?



I'm referring to the first incidence of panelProducts being highlighted like that. It's a local variable, passed in to the Sub as a parameter, and that's the first time it's references in the method. At first I thought I must have accidentally clashed with a class name or something, but as you can see, subsequent references aren't highlighted, and it does it no matter what I call it.

chippy
Aug 16, 2006

OK I DON'T GET IT
loving help me goons before I kill someone.

All I want to do is copy the client area of one form, and set it as the background of another form. I've tried a million things today, mostly nicked from SO, and I either get no background or some sort of stupid "General GDI error' exception. When I write the capture BitMaps to files they are just plain black rectangles.

Here's what I have at the moment, as I say, mostly stolen

code:
Public Sub CopyFormToBackGround(formToCover As Form)
        Dim bmpScreenShot As Bitmap = New Bitmap(formToCover.Width, formToCover.Height, PixelFormat.Format32bppArgb)
        formToCover.DrawToBitmap(bmpScreenShot, New Rectangle(0, 0, Me.Width, Me.Height))
        'bmpScreenShot.Save("c:\first screenshot.bmp", ImageFormat.Bmp)

        Dim origin As Point = formToCover.PointToScreen(New Point(0, 0))
        Dim dx As Integer = origin.X - formToCover.Left
        Dim dy As Integer = origin.Y - formToCover.Right

        'Copy client area into new bitmap
        Dim width As Integer = formToCover.ClientSize.Width
        Dim height As Integer = formToCover.ClientSize.Height

        Dim clientAreaBmap As New Bitmap(width, height)

        Using graphics As Graphics = graphics.FromImage(clientAreaBmap)
            graphics.DrawImage(bmpScreenShot, 0, 0, New Rectangle(dx, dy, width, height), GraphicsUnit.Pixel)
            Dim rectangle = New Rectangle(0, 0, width, height)
            'graphics.FillRectangle(New SolidBrush(Color.FromArgb(50, Color.Black)), rectangle)
        End Using

        clientAreaBmap.Save("C:\Temp\test.bmp", ImageFormat.Bmp)
        BackgroundImage = clientAreaBmap
        Refresh()

    End Sub
This earns me a plain gray background, and a black rectangle saved to disk.

Someone save me?

p.s. Winforms

p.p.s Also tried this, similar results:

code:
        Dim bmpScreenshot = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb)
        Dim x = formToCover.Left
        Dim y = formToCover.Right
        Dim size = formToCover.Size

        Using g As Graphics = Graphics.FromImage(bmpScreenshot)
            g.CopyFromScreen(x, y, 0, 0, size, CopyPixelOperation.SourceCopy)
            Dim rect = New Rectangle(0, 0, size.Width, size.Height)
            'g.FillRectangle(New SolidBrush(Color.FromArgb(50, Color.Black)), rect)
        End Using

        bmpScreenshot.Save("C:\Temp\test.bmp", ImageFormat.Bmp)
        BackgroundImage = bmpScreenshot

chippy
Aug 16, 2006

OK I DON'T GET IT
Wait, no! The second bit is now getting *something*, but it's the wrong part of the screen.

I am going to shoot myself.

edit: OK, mostly there, except I'm getting the title and bar and minimize, restore, etc. controls.

final edit: Don't worry goons, you can take me off suicide watch. Next time I'll just ask for help immediately instead of just struggling for hours, as Sod's Law dictates that this will cause me to immediately get it working.

chippy fucked around with this message at 16:51 on May 7, 2015

chippy
Aug 16, 2006

OK I DON'T GET IT
I loving give up.

OK, so, Plexiglasss is just a borderless form with a blurred, faded image of the form it's given in its constructor set as its background.

If I do this:

code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim glass As New Plexiglass(Me, True, True, "Test")
        glass.Show(Me)
End Sub
It works perfectly. My window is overlaid with a blurred version of itself.

But if I do this in another method of the form:

code:
 Dim glass As New Plexiglass(Me, True, True, "Storing records...")
 glass.Show(Me)
        
  ' Do some work

glass.Close()

It doesn't work. All that happens is a Rectangle object on the form goes white for a bit.
I even tried sleeping for 5 seconds in case the work was just happening too quickly. Nothing.

Someone help me before I actually do kill myself?

e: Got it. Needed to call Refresh on the glass. Anyone know why calling it in its Shown event handler wasn't enough?
ee: Putting it in the Activated handler worked. gently caress Winforms.

chippy fucked around with this message at 17:47 on May 7, 2015

chippy
Aug 16, 2006

OK I DON'T GET IT
Goons, help (Winforms). I have a textbox that needs to be able to accept a tab character. I can do this by making it MultiLine=True and AcceptsTab=False. However, I also need it to NOT accept/type a carriage return when Enter is pressed, as I need this to trigger an event. However, according to MSDN, AcceptsReturn=False only works if the form has a default Accept button, otherwise the Textbox will get a carriage return in it anyway. The form doesn't have a default OK button so what is happening currently is that the Enter key is triggering the event, but is also inserting a carriage return into the Textbox, which is only 1 line high so the 1st line is then disappearing. I need to trigger the event on the Enter key, and NOT have it insert a carriage return.

I'm considering a hidden default Accept button but this seems hackish. Can anyone suggest a proper way of doing this?

If anyone's wondering, these weird requirements are because the form is driven by a barcode scanner that emulates a keyboard. Operators need to be able to drive the whole thing with just the scanner, without using keyboard and mouse. Some of the barcodes use a tab character as a delimiter (I have no control over this), and the scanner automatically sends an 'Enter' keypress at the end of the scan (I have no control over this either). This was all working before but the tabs in barcodes are a new thing that's thrown a bit of a spanner into the works.

Probably also worth mentioning that the handler for the Enter being pressed is a KeyDown event at the form level. I'm not sure why this was done rather than handling the keydown event for each textbox individually. I thought it might help to handle them at the textbox level but when I created a test form to try this out it didn't actually make any difference.

chippy
Aug 16, 2006

OK I DON'T GET IT

SirViver posted:

Just checked it and this should do it:
C# code:
// Set via designer...
textBox1.AcceptsTab = true;
textBox1.Multiline = true;
textBox1.KeyPress += textBox1_KeyPress;

// In code behind
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
	if (e.KeyChar == (char)13) // Return
	{
		e.Handled = true; // Prevent newline being added to textbox
		HandleBarcodeEntry(textBox1.Text); // Move this from your form handler to here
	}
}
Not exactly watertight or pretty to look at, but it should get you going. Note that it has to be the KeyPress event and not KeyDown/Up, as the Handled property on their event object does exactly gently caress all (for preventing key input). If you don't like the (char)13 comparison, you can also create a bool returnKeyPressed or similar and set that in the KeyDown event by comparing e.KeyCode against the nicer Keys.Return enumeration value (and also maybe move the barcode handling code there and only use the KeyPress event to prevent the newline from being added).

Ahhh, thanks, I'll give this a go. I actually already tried pretty much exactly this, but I was using KeyDown, so taht explains why that wasn't working.

chippy
Aug 16, 2006

OK I DON'T GET IT
Got a loving weird problem. As soon as I try and instantiate an SqlConnection, my application immediately exits, with nothing caught in my catch block. I'm literally just doing this in a simple C# console application:

code:
SqlConnection connection = new SqlConnection();
This was originally a using statement with the correct connection string but I've reduced it to this to try and work out what the problem is. Stepping through, it bails out as soon as it executes this line. Originally I had this in a Windows Service but I've moved it in a console app for easy debugging.

Any idea, anyone?

e: Saw someone on Stack Overflow with this problem, a using block fixed it for them (it doesn't for me). I also saw some people suggesting that his .NET installation was broken, but I have other projects that this is working fine in.

chippy fucked around with this message at 17:42 on Jun 3, 2015

chippy
Aug 16, 2006

OK I DON'T GET IT
No, not in release. The method that uses the connection is actually the callback for a Timer. I found that if I just call the method without using the timer it doesn't have this problem. Anyone know why that would stop it working?

It should be pretty simple. It's just a service that needs to run a stored procedure every few seconds. Maybe my approach is all wrong, I'm not at work now bit I'll post some code tomorrow.

Adbot
ADBOT LOVES YOU

chippy
Aug 16, 2006

OK I DON'T GET IT

ljw1004 posted:

https://msdn.microsoft.com/en-us/library/system.timers.timer.elapsed%28v=vs.110%29.aspx


(Well, the MSDN docs say it is subject to change, but I bet it never will change since that'd be a terrible breaking change.)

Hmm ok, well that solves one mystery, but the question is, why is just instantiating the SqlClient with its default constructor throwing an exception, and why is it not throwing the exception when the same method is run without using the timer?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply