C# Tutorials

Over the past 6 months I’ve worked on some intermediate C# tutorials, they go over topics that are not usually covered by other video tutorials on the internet.

 

Click the read more button to see the list.

Read more of this post

Advertisements

AdvancedPostIt Devlopment Update (DevV0.07)

I’ve been working on a lot of things in this Dev Vision, This program is nearly to be Beta tested (by DevV0.10 maybe). I’ve added and fixed a lot of things, this has probbly been the largest DevV.

Read more of this post

WindowsAPICodePack Taskbar videos

Codesnippets for the 4 videos on the taskbar.

Read more of this post

Determine which operating system your program is running on with C#

Another tutorial from my developing for windows 7 series. How to check what OS the program is running on.

Layout of the form I'm using

OperatingSystem SystemInfo = Environment.OSVersion;
        public Form1()
        {
            InitializeComponent();
            label2.Text = SystemInfo.VersionString;
            label1.Text = OSV();
        }
        private string OSV()
        {
            if (SystemInfo.Platform == System.PlatformID.Win32NT)
            {
                if (SystemInfo.Version.Major == 5)
                    return "XP";
                else if (SystemInfo.Version.Major == 6)
                {
                    if (SystemInfo.Version.Minor == 1)
                        return "Win 7";                    
                    return "Vista";
                }
            }
            return "";
        }

Using the TaskDialog (WindowsAPICodePack)

In the last few weeks i started a tutorial series on YouTube on Developing for Windows 7 using the WindowsAPICodePack.

Anyway here is the codesnippets that i show in my tutorials.

Read more of this post

AdvancedPostIt Devlopment Update (DevV0.06)

A lot of new things have been added to this protect from DevV0.05, the size of the project has nearly tripled in a week!

Here is the log for 0.06:

-The ‘image viewer’ Renamed to “AdvancedPostItImage”
-Zoom/pan implemented for the image viewer.
-Reworked logic for image viewer.
-Video Support…
-New App “VideoPlayerVLC” and “VideoPlayerWindows.xaml” for videos.
-Main Program Interface..”AdvancedPostItManager”.
-System tray icon implimented.. no functionality yet.
-Early version of a ‘playlist’ implemented.

Few things that i will do before the beta:

-Make the playlist fully funtional.
-Options menu.
-Anything else that i think will be good.

I’m going to take a break form developing this program at lest until the 20th of this month.

DevV0.06

Using the VLC ActiveX control in WPF

How to integrate the powerful VLC media player into your WPF application

Prerequisites:

  • Windows version of VLC Media Player with the ActiveX component installed.
  • Microsoft Visual Studio 2010 professional / Microsoft Visual C# 2010 Express (Don’t know if this method works on older versions).

Instructions:

  1. If you are not adding this to a current project then create a Visual C# > Windows > WPF Application.
  2. Add a User Control to your project (Project > Add New Item > Visual C# > User Control).
  3. Open the Toolbox (if you can’t see this: View > Toolbox).
  4. Right Click anywhere on the Toolbox then click on Choose Items. (This may take a while to open)
  5. Navigate to the COM Components tab, find and check “VideoLAN VLC ActiveX plugin v1” (axvlc.dell) and press OK.
  6. Now in your Toolbox you should see “VideoLAN VLC ActiveX plugin v1”. Double click on it and set its Dock Property to “Fill”
  7. Now save an build your project (Build > Build Solution.. or press F6)
  8. In the Solution Explorer under References you should now see “AXVLC” and “AxAXVLC”. if you don’t add them manually by right clicking on References, go into your projects debug folder and add “AxInterop.AXVLC.dll” and “Interop.AXVLC.dll”.
  9. Right clicking on References in the Solution Explorer, then Add Reference; Browse to the .NET Tab and find and select “WindowsFormsIntegration”, then press OK.
  10. Now in MainWindow.xaml (or where ever you want to add it to), Add a name to your grid (or the container)… i named mine “grid1”.
  11. From the toolbox add a WindowsFormsHost to the grid, and name it. I named mine “WFH1”  (see Figure 1)
  12. Now right click on your main window and click on View Code.
  13. Declare “AxAXVLC.AxVLCPlugin” as a global variable. (AxAXVLC.AxVLCPlugin vlcPlayer = new AxAXVLC.AxVLCPlugin();
  14. in your default constructor add the player object as the child of the WindowsFormsHost (WFH1.Child = vlcPlayer;)
  15. And that’s it! you wont see anything when you run the program, but the player is there, i will post a code snippet below so you can get a file to open and play in it (Figure 2).
  16. See http://wiki.videolan.org/ActiveX for instructions on how to use the VLC media player ActiveX Plugin.

UPDATE 16-OCT-2011: (List of Fields/Methods/Events of the Plug-in)
Here are a list of fields/methods/events that should allow you to have a lot of control over the plug-in:
Fields

  • bool AutoLoop { get; set; }
  • bool AutoPlay { get; set; }
  • bool CtlVisible { get; set; }
  • int Length { get; }
  • string MRL { get; set; }
  • bool Playing { get; }
  • int PlaylistCount { get; }
  • int PlaylistIndex { get; }
  • float Position { get; set; }
  • int Time { get; set; }
  • string VersionInfo { get; }
  • int Volume { get; set; }

Events

  • MediaPlayerBackward;
  • MediaPlayerBuffering;
  • MediaPlayerEncounteredError;
  • MediaPlayerEndReached;
  • MediaPlayerForward;
  • MediaPlayerNothingSpecial;
  • MediaPlayerOpening;
  • MediaPlayerPausableChanged;
  • MediaPlayerPaused;
  • MediaPlayerPlaying;
  • MediaPlayerPositionChanged;
  • MediaPlayerSeekableChanged;
  • MediaPlayerStopped;
  • MediaPlayerTimeChanged;
  • pauseEvent;
  • playEvent;
  • stopEvent;

Methods

  • void addTarget(string uri, object options, VLCPlaylistMode mode, int position);
  • void AttachInterfaces();
  • void CreateSink();
  • void DetachSink();
  • void fullscreen();
  • object getVariable(string name);
  • void pause();
  • void play();
  • void playFaster();
  • void playlistClear();
  • void playlistNext();
  • void playlistPrev();
  • void playSlower();
  • void setVariable(string name, object value);
  • void shuttle(int seconds);
  • void stop();
  • void toggleMute();

Figuare 1

Example of further useage:

I just added a button to my application to open allow the user to select a file and play it in the player:

[Updated 08 Oct 2012, courtesy of bielb89 from YouTube]

VLC V2.x.x.x +You will need to add “file:///” +before the Url for the file.

Figure 2.. Click on the more button to see a written version of the code.. [This Picture is outdated]

using System.Windows;
using System.Windows.Forms;

namespace WPFVLC
{
    ///
<summary> /// Interaction logic for MainWindow.xaml
 /// </summary>
    public partial class MainWindow : Window
    {
        AxAXVLC.AxVLCPlugin vlcPlayer = new AxAXVLC.AxVLCPlugin();
        public MainWindow()
        {
            InitializeComponent();
            WFH1.Child = vlcPlayer;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            string mrl = "";
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.ShowDialog();
            if (ofd.FileName != "")
            {
                mrl = ofd.FileName;
                vlcPlayer.addTarget("file:///" +mrl, null, AXVLC.VLCPlaylistMode.VLCPlayListReplaceAndGo, 0);
                vlcPlayer.play();
            }
        }
    }
}