Blog - Title

Visual Studio 2013 Current Status

  • The Ultimate Visual Studio Tips and Tricks Blog

    Collapsing Your Code with Outlining

    • 12 Comments

    Keyboard:  CTRL + M, CTRL + M
    Menu:  Edit -> Outlining -> Toggle Outlining Expansion
    Command:  Edit.ToggleOutliningExpansion
    Versions:  2008,2010
    Published:  3/15/2010
    Code:  vstipEdit0029

     

    By default, Outlining is enabled in Visual Studio.  It's the line you see with the boxes to indicate the status of the area (collapsed or expanded):

    image

     

    You can collapse areas of code to get them out of your way so you can focus on other areas.  There are four ways to do it:

    1. Click on the minus sign to collapse an area of code:

      image

      NOTE:  In VS2010 it now highlights the area that will be collapsed as seen here.  A very cool feature.  If you don't like the highlighting color you can go to Tools -> Options -> Environment -> Fonts and Colors -> Collapsible Region to change it.

    2. VS2010 ONLY:  Click ANYWHERE on the vertical line in the highlighted region.  In other words, you can now collapse a region from anywhere in that region:
      image 
    3. Click anywhere in the area to be collapsed and hit CTRL + M, CTRL + M
    4. Click anywhere in the area to be collapsed and go to Edit -> Outlining -> Toggle Outlining Expansion on the Menu Bar

     

    Once collapsed, the code area will look like this:

    image

  • The Ultimate Visual Studio Tips and Tricks Blog

    Track Changes in the Editor

    • 12 Comments

    Menu:  Tools -> Options -> Text Editor -> General
    Versions:  2008,2010
    Published:  4/14/2010
    Code:  vstipEdit0048

     

    Download the seriously cool Tip of the Day Extension to get the daily tips delivered to your Start Page!

     

    image

    To use this feature you need to have "Track Changes" and "Selection Margin" checked. 

     

    Okay, so ever wonder how those colors to the left of your code actually work?

    image

     

    Let's begin with a clean slate.  Notice there are no colors:

    image

     

    Now let me add a couple of lines of code:

    image

     

    So, all new code will turn yellow to show you what part of the document is "dirty" (unsaved).  If we save the code then we get this:

    image

     

    The "clean" (saved) indicator will remain as long as you have the file open.  When you close and reopen the file, this is what you get:

    image

     

    New in VS2010:  There is now an orange indicator that is used to show a change that is different from the saved version.  This was added for the scenario where a user does an undo after a save operation:

    image

     

     

    Here is a grid to help keep the scenarios straight:

    Marker Different from file saved on disk? Different from file that was opened?
    Nothing No No
    Yellow Yes Yes
    Green No Yes
    Orange Yes No

     

    Very cool stuff!

  • The Ultimate Visual Studio Tips and Tricks Blog

    Creating and Using Synchronization Services with Visual Studio 2008

    • 12 Comments

     

    So, thanks to Rob S. for staying on me for this one.   This is a demo that I did during the Heroes Happen Here Launch Events and just absolutely dropped the ball on getting out to folks.  Here I am now trying to redeem myself, so let's get after it.

     

    If you want to learn more about Sync Services you can go here:  http://msdn.microsoft.com/en-us/library/bb726031(SQL.100).aspx

     

    Also, I use the sample databases (old school) for SQL Server in this demo that can be found here:  http://msdn.microsoft.com/en-us/library/ms143221.aspx

     

    You can watch me do this session and other sessions by using the links here:  http://blogs.msdn.com/zainnab/pages/heroes-happen-here-launch-resources.aspx

     

    Specifically, check out the Defy Occasionally Connected Challenges with Smart Client Applications session.

     

     

    Annnnd, away we go...

     

    1. Create a new Windows Application in Visual Studio 2008 (either language is fine) and call it SynchCoolnessCS or SynchCoolnessVB as appropriate:

      image

    2. Resize your from then add a DataGridView and a Button to your form like this:

      image

    3. Set the Anchor property of the DataGridView so that it is anchored to all sides:

       image

    4. Now to the fun part.  We will configure a local database cache to work in our disconnected scenario.
    5. Right-click on your project and choose Add...New Item...

      image

    6. Let's add a Local Database Cache leaving the name set to it's default value:

      image

    7. Now you should be in the Configure Data Synchronization Dialog:

      image

    8. I'm going to assume you don't already have a connection to your database server but if you do, just select it from the dropdown.
    9. For those that don't have a connection already, click the New... button for Server Connection, fill out the appropriate information, then
      click OK

      image

    10. In my case, I chose to use the pubs database on the local server ( . = local server)
    11. The Client Connection information should "automagically" fill in for you and you should now have something like this:

      image

    12. Notice the + Add button in the lower left?  Click on that puppy.  In the Configure Tables for Offline Use Dialog, check the authors table (or
      any other table you want).  Notice the options to the right?  Take a minute to check them out and/or make sure you watch the video for an
      explanation of these.  At this point, just click on the OK Button.

      image

    13. You should notice that your Cached Tables has been updated:

      image

    14. VERY IMPORTANT!!  Make sure you click on the Show Code Example in the lower right corner.

      image

    15. Then click on Copy Code to the Clipboard Button a couple of times to make sure it is definitely copied:

      image

    16. Click on Close and then click on OK to get out of all the dialog boxes.
    17. It should synchronize then present you with a new dialog box (note the DataSet name at the botttom), check the Tables box, then click Finish:

      image

    18. You should now see some new files in Solution Explorer:

      image

    19. Double-click on your button and then paste your code inside the button:

      VB
      image


      CS
      image

    20. Let's pause for a moment to consider what to do if you lose the sample text from the clipboard.  Do you start over? NO!
      All you have to do is Right-Click the .sync file and choose view designer to get back to the dialog where you can copy the
      code again:

      image

    21. Now we have to make the DataGridView aware of your cache.  In Design View, set the source of the DataGridView to the local
      authors table:

      image

    22. You should see something like this:

      image

    23. Now go back into your code and let's finish out what we need to do.

    24. What you do from here depends on your needs.  By default, the data will only synch from the server to the client and
      NOT the other direction.  If that is all you want to do then go back into your code and add this line after the TODO for
      reloading your server data:

    25. VB
      ' TODO: Reload your project data source from the local database (for example, call the TableAdapter.Fill method).
      Me.AuthorsTableAdapter.Fill(Me.PubsDataSet.authors)


      CS
      // TODO: Reload your project data source from the local database (for example, call the TableAdapter.Fill method).
      this.authorsTableAdapter.Fill(this.pubsDataSet.authors);

    26. If, however, you want the data to flow in, say, both directions you need to modify your code to look like this:


      VB
    27. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
              ' Update the dataset
              Me.AuthorsTableAdapter.Update(Me.PubsDataSet.authors)

              ' Call SyncAgent.Synchronize() to initiate the synchronization process.
              ' Synchronization only updates the local database, not your project’s data source.
              Dim syncAgent As LocalDataCache1SyncAgent = New LocalDataCache1SyncAgent()

              ' Set synch direction, default is DownloadOnly
              syncAgent.authors.SyncDirection = Microsoft.Synchronization.Data.SyncDirection.Bidirectional

              ' Synch up
              Dim syncStats As Microsoft.Synchronization.Data.SyncStatistics = syncAgent.Synchronize()

              ' TODO: Reload your project data source from the local database (for example, call the TableAdapter.Fill method).
              Me.AuthorsTableAdapter.Fill(Me.PubsDataSet.authors)
          End Sub


      CS

      private void button1_Click(object sender, EventArgs e)
              {
                  // update the DataSet
                  this.authorsTableAdapter.Update(this.pubsDataSet.authors);

                  // Call SyncAgent.Synchronize() to initiate the synchronization process.
                  // Synchronization only updates the local database, not your project’s data source.
                  LocalDataCache1SyncAgent syncAgent = new LocalDataCache1SyncAgent();

                  // Set synch direction, default is DownloadOnly
                  syncAgent.authors.SyncDirection = Microsoft.Synchronization.Data.SyncDirection.Bidirectional;

                  // Synch Up
                  Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize();

                  // TODO: Reload your project data source from the local database (for example, call the TableAdapter.Fill method).
                  this.authorsTableAdapter.Fill(this.pubsDataSet.authors);
              }

    28. That's it!  Run that sucker:

      image


    29. Change Green to something else like Purple:

      image
    30. Click the button.  One of two things will happen:  (1) if you didn't set the direction for the synch it will replace Purple with Green since the direction
      is DownloadOnly (Server to Client only) and therefore doesn't accept updates from the client; or (2) it will appear to do nothing and leave Purple there:

      image
    31. Don't be fooled.  It has synched with the database.  You can verify by going into your authors table and seeing for yourself:

      image
    32. And, my intrepid adventurers, that is how you use ADO.NET Data Synch goodness.  Hope you enjoyed the ride! :)

  • The Ultimate Visual Studio Tips and Tricks Blog

    Using Visual Studio 2008 / VSTO / Outlook to Pull Out RFC 822 Header Data

    • 12 Comments

     

    Mike B. asked me to show how to get header information from emails using VSTO.  So here is a step-by-step tutorial on how to create a Form Region that will show header info:

     

    1. Open up the New Project dialog, choose Office...2007 under Project Types (either language is fine), and click on Outlook 2007 Add-in 

       image
    2. Name the project HeaderStuffCS or HeaderStuffVB, depending on which language you use, then click on OK
    3. Now let's add our Task Pane.  Right-click on the project in Solution Explorer, choose Add... New Item...

       image
    4. Under Categories choose Office then under Template select Outlook Form Region

       image
    5. For the Name, call this ShowHeaderInfo and click on Add
    6. This will start a series of dialogs to create the Form Region
    7. The first dialog just let's us choose to create a new form or use an existing one.  Just go with the default (new form) and click Next.

      image
    8. Now we get to choose our region type.  For this one we will go with Adjoining then click on Next

      image
    9. For the descriptive text and display messages, deselect the Inspectors that are in compose mode option and click Next

      image
    10. Finally, we get to choose which of the eight standard classes we want to use this region with or we can specify a custom class.  We will leave the default setting here (mail message) and click on Finish

      image
    11. You will see ShowHeaderInfo.cs or ShowHeaderInfo.vb in Solution Explorer and a design surface should be visible.  Resize the surface to make room for a couple of controls.

      image
    12. In this case we will throw on a button and a textbox.  Set the multiline property of the textbox to true and resize it a little.  Also, press F4 to bring up the properties and set its ScrollBars property to Vertical.

      image
    13. Now comes the fun part :)  Double-click the button to crank some code for its click event.

      image

      image
    14. To get to the header information that we may want we will use the PropertyAccessor.  Essentially this will give us a way to dig into a variety of different information available in the message.
    15. Type the following inside the click event:

      CS

      // get a reference to our mail item
      Outlook.MailItem curMail = (Outlook.MailItem)this.OutlookItem;
    16. // use the property accessor to get info into our textBox
      textBox1.Text = (string) curMail.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E");


      VB

      ' get a reference to our mail item

      Dim curMail As Outlook.MailItem = Me.OutlookItem

      ' use the property accessor to get info into our textbox

      TextBox1.Text = curMail.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E")

    17. Press F5 to run your project.  It should start up Outlook and when you read any mail you should see your region at the bottom.  Click on the button to see the header information.

      image

    18. Close Outlook when you are done.
    19. That's it!  Congratulations you can now get header information!

     

    At this point you are probably pissed because you don't know what the heck that whole GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E") thing did.  Well, basically there are a variety of ways you can get info using the PropertyAccessor.  Take a look at http://msdn.microsoft.com/en-us/library/bb147567.aspx and you will see a listing of these ways.

     

    You accessed the information described in RFC 822.  Specifically, you dumped out the entire SMTP message envelope.  To do this, I used the "mapi/proptag/{some hex value}" option.  But I needed to know the hex value so where did it come from?  Here is where you can get the values that can be used:  http://msdn.microsoft.com/en-us/library/ms530451.aspx 

     

    If you click on the link for PR_TRANSPORT_MESSAGE_HEADERS it will take you to a description of the value(s) you will get and the values you need to get them.  You will note there is a Property Tag entry where we can get the hex value we use to get our information:

    image

    If we plug the hex into our code, we get: GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E")  and we are in business

     

    Now it's up to you to play with the different values to see what you can get back.  Enjoy! :)

  • The Ultimate Visual Studio Tips and Tricks Blog

    Code Trippin (Red Hot Chili Peppers Would Be Proud)

    • 12 Comments

    So we have a new initiative in the West that my buddy Bags is a part of:  Code Trip.  In addition to being a cool name the "tour" concept really rocks.  Check it out at

    buswrap

    http://thecodetrip.com

  • The Ultimate Visual Studio Tips and Tricks Blog

    Agile Processes in a Waterfall World...

    • 11 Comments

    Really nice article Agile meets Waterfall.  It's technology is Java but easily translated to our world:

     

    http://www.javaworld.com/javaworld/jw-03-2008/jw-03-agile-practice.html

  • The Ultimate Visual Studio Tips and Tricks Blog

    Web Application Projects vs. Web Site Projects in Visual Studio 2008

    • 11 Comments

    The last one!  This series is DONE!  Keep an eye out for more my next series in a month or so.

     

    Wecast is here and files are attached.

  • The Ultimate Visual Studio Tips and Tricks Blog

    View White Space

    • 11 Comments

    Keyboard:  CTRL + R, CTRL + W
    Menu:  Edit -> Advanced -> View White Space
    Command:  Edit.ViewWhiteSpace
    Versions:  2008,2010
    Published:  4/9/2010
    Code:  vstipEdit0043

    I've hijacked today's tip to remind everyone that next Monday I will start giving away $100 ThinkGeek gift certificates (one every day for about 30 days).  For details of my evil plan, go here.  Also, make sure to sign up for a Visual Studio Launch event in your area.  Happy coding!

    Download the seriously cool Tip of the Day Extension to get the daily tips delivered to your Start Page!

     

    Ever want to see the white space you are working with?  Maybe you want to know if your spaces are tabs or you have extra spaces on lines.  It's easy to view white space.  Just go to Edit -> Advanced -> View White Space (CTRL + R, CTRL + W) to go from this:

    image

     

    To this:

    image

  • The Ultimate Visual Studio Tips and Tricks Blog

    Create Code Shortcuts in the Task List

    • 11 Comments

    Keyboard:  CTRL + K, CTRL + H [toggles the shortcut on or off]
    Menu:  Edit -> Bookmarks -> Add Task List Shortcut
    Command:  Edit.ToggleTaskListShortcut
    Versions:  2008,2010
    Published:  6/8/2010
    Code:  vstipTool0030

     

    You can create shortcuts to lines of code that you want to revisit later.  It's easy!  Just go to any line of code then press CTRL + K, CTRL + H (toggles the shortcut on or off).  This will create the shortcut glyph in the Margin like this:

    image

     

    To see all your shortcuts, go to the Task List (CTRL + \, T) and choose "Shortcuts" from the drop-down list:

    image

     

    Now you should see all your shortcuts:

    image

     

    You can now treat them like any other task and set priority levels as well as mark them complete:

    image

     

    NOTE:  You can RIGHT CLICK any task and choose "Delete" to remove it from the list.

  • The Ultimate Visual Studio Tips and Tricks Blog

    Prototype Tip for the New Book

    • 11 Comments

    Folks,

     

    Wanted to get your input on this one.  I'm working on the new Tips and Tricks book and had a concept for how I want to show the information.  The format is basically the same it is now except heavier use of graphics so instead of SHIFT + ALT + [UP or DOWN ARROW] I use pictures instead.  I'm also going to include keyboard mappings if they are different than the default and add mouse commands.  There will also be some graphic to represent the version(s) supported and, finally, a list of related tips.  This is a VERY rough draft but wanted to get folks engaged early on to get your thoughts.

     

    Here is the prototype tip that I was thinking of:

    ======================================================

    Zero-length box selection

    vstipEdit0009

    clip_image002 + clip_image004+clip_image006clip_image008

    clip_image004[1] +clip_image011

    clip_image013

     

    Related Tips: vstipEdit0006, vstipEdit0007, vstipEdit0008

     

    Let's assume that you have a situation with some variables like the ones below and you want to make them all public:
    clip_image015

    The answer is a zero-length box selection.  Hold down your ALT key and Left Mouse Button, then drag straight down.  Note the line that is created:
    clip_image017

    Release the ALT key and the Left Mouse Button.  Now, just start typing:
    clip_image019

    Bask in the wonder and glory that is the zero-length box selection! :)

Page 5 of 135 (1,345 items) «34567»