個人檔案November Notes相片部落格清單更多 ![]() | 說明 |
|
2008/12/31 drag’n drop files into richtext boxes (so it’s actually useful)There’s a ton of howto’s out there showing people how to do the drag and drop into a richtext box. But recently I had a job that required me not to drag the contents from one part of the form to the other but to actually drag a file (or files) into a RichTextbox control – and process them. Which… if you’ve never tried this before drops the file as an icon you can click on and open. Not really Which is fine if that’s what you need. But what I needed was to be able to grab several files – of either text or xml – and then process them and display the output. Since I can’t share my work code – here’s the training wheels version of the code for you.
Since I’m reallllly running behind – that’s all I can get out this week - but hopefully it’ll be of use to someone out there. As you can see – I’m calling the richtextbox dragenter event and customizing it. The first thing I do is hunt for the dataformats.filedrop type off the event handleer – this allows me to grab the filename and – load it appropriately into the richtextbox. Anyway… to all out there – here’s the code – have an AWESOME New Year… and I’ll be back on line to annoy all as soon as I can.
Imports System Imports System.Drawing Imports System.Data Imports System.IO Imports System.Collections Imports System.Windows.Forms Imports System.Xml Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'This call is required by the Windows Form Designer. RichTextBox1.AllowDrop = True End Sub Private Sub richTextBox1_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs) Handles RichTextBox1.DragEnter Try If e.Data.GetDataPresent(DataFormats.FileDrop) Then ' Put all file names into a string array 'in case the user grabbed more than one file. Dim files As String() = CType(e.Data.GetData(DataFormats.FileDrop), String()) Try 'Now we break it down - we only want text files, xml or xsd files 'so we trap for that if it's not one of those - we ignore it. If files(0).Contains(".txt") Then Dim f_stream As IO.StreamReader = FileIO.FileSystem.OpenTextFileReader(files(0)) RichTextBox1.Text = f_stream.ReadToEnd() 'Just for fun we show the name of the file and link it llblFileName.Text = files(0).ToString f_stream.Close() ElseIf files(0).Contains(".xml") Then Dim filename As String = files(0) Dim reader As New XmlTextReader(files(0)) llblFileName.Text = files(0).ToString reader.MoveToContent() 'Loop through the XML and display it in the richtextbox Do While reader.Read RichTextBox1.AppendText(reader.ReadContentAsString) Loop reader.Close() End If Catch ex As Exception MessageBox.Show(ex.Message) Return End Try End If Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Private Sub llblFileName_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles llblFileName.LinkClicked System.Diagnostics.Process.Start(llblFileName.Text) End Sub End Class 2008/12/10 We’re not dead yet…Been a week or two since I updated so this is going to be quick before I lumber off to work. The recession isn’t as bad as it might appear. It’s bad – almost every IT company out there decided to put the breaks on a lot of hiring and dropped the expected wages they’re paying. But the jobs are still there. Nationally I just got a ping for over 35 IT Jobs that opened since December 10th – most are east coast related (NY, NH, NJ, FL) although there’s a surprising number from TX and IL that I really didn’t see coming. Most of these are Dev and Engineering – but there’s a smattering of UI designer and PM type roles. In the NW USA we’re still seeing a remarkable amount of stuff going on – although most is at MS still around 36 jobs posted through Dice and Careerbuilder since Dec 5th. Once again – MS leads with Test positions and Dev positions, but has a nice nearly equal compliment of PM jobs. Had someone ask me how to tell if companies are gearing up for work or completing projects based on job postings… here’s the tip: If they need more PMs than they do Developers – they’re gearing up and there’s more work coming. If they’ve got more Developer positions than PM and Test it generally means they aren’t planning they’re completing what they have on their plates. This is often cyclical so don’t read a whole lot into it. If you want a good idea of how to predict work in an economy – check comic books. They’re a luxury item but they’re one that kids save up for – so if the kiddies have money for comics then mom & dad we can guesstimate if times are really tight. If kids buy a lot of comics – then the allowance is healthy if they buy fewer – then the allowance is down. As a result the comics industry has always been a good way to tell how hard hit families are in a financial crunch. They’re one of those trail indicators you don’t think about but watching their wake tells you the size of the destructive forces applied to children. Hate to be so cold blooded – but economics suck. Warren Ellis sent off a ping saying the comics industry’s finally feeling the pinch – and his info seems to match up with mine. It’s not that financially the industry’s gone south yet – tons of work being done and things are being bought – but the fear of the slow down is causing less work. His recipe for digging out of holes in the comics industry is the same as mine – raise your game up a level or two. What every business from Film & Entertainment (Web especially) to GM & FORD to Marvel Comics and Microsoft has had for the last decade has been an assumed captive market. Raise your game and create better products or you’re going to get your corporate clocks cleaned by people willing to raise their game and give customers what they want. This isn’t the time to get conservative – this is the time to get creative. To dig deep take some risks (not financially but creatively) and come up with great product. Warren’s DOKTOR SLEEPLESS is a good example of a comic built and crafted for fans that’s selling in a market where others are slipping back. Dr. Horrible (from Joss Whedon) is another example – built for fans it was what fans wanted. It sold beyond well (waaay past expectations) for no advertising, no budget, and not a lot of time. But the quality was there and they created a product they knew their target audience would want. These are the kinds of products that save companies and that’s the strategy needed to pull it out and win. That’s all for this week… back to slaving away… Oh… and for those who haven’t seen it yet – did a new experiment with Vanishing Point in Photoshop and After Effects… it’s up on the web. A 20 minute wonder here… but always fun to play. The original here was a still photo of an alley – near canal street as I recall – a bit of adjustment, and wallah… 3D from flat using Vanishing Point in Photoshop to extract the planes for AE. To belabor the theme of this week’s blog here … if you haven’t picked up a new skill this week you’re not raising your personal game up a notch. Find something you haven’t done before – and go do it! If you don’t someone else will. If you do – you get to choose what it is you want to learn – what it is you want to do – and you’re a lot closer to doing what you want to do in life. Remember … you can be a passenger or the guy driving the bus in your life. Do you want to be the guy who gets to tell everyone where they’re going and when they can get off or do you want to be told? The choice is up to you. |
|
|