Tuesday, November 20, 2012

How to play a media file in a loop in Windows media player in .net/C#


We can achieve this through:                                                                    // Set the PlayCount property to a big number and normally before the countdown finishes user   // will interact with system definitly                                                          axWindowsMediaPlayer1.settings.playCount = 200000000;                                           // Set the Mode Loop to true                                                                    axWindowsMediaPlayer1.settings.setMode("Loop", true);                                           // in PlayStateChange event, when it is observed that media player state is stopped then play   // is again                                                                                      axWindowsMediaPlayer1.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(axWindowsMediaPlayer1_PlayStateChange);
void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
        {
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsStopped)
            {         
                axWindowsMediaPlayer1.Ctlcontrols.play();
            }
        }

how to check the state of media in window media player in .Net/C#


   axWindowsMediaPlayer1.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(axWindowsMediaPlayer1_PlayStateChange);

  void axWindowsMediaPlayer1_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
        {
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsStopped)
            {
                 // Your code
            }
        }

Usage of Windows media player in .net


axWindowsMediaPlayer1 is default name of windows media player control name.
     axWindowsMediaPlayer1.URL = @"C:\test.wmv";

how to add windows media player in C#.net


On toolbox, right click and choose Items....

From COM Components select Windows Media Player
 You will see that Windows media player icon at the right side of left toolbox and as you will place that icon on the form windows media player will added on teh form and you will the two references in the right side references area.


Friday, November 16, 2012

How to remove a blank row at the end of WPF datagrid


  <DataGrid Name="dataGrid1" CanUserAddRows="False">

WPF - How to fill the datagrid with its propotionate columns

Width="0.25*" in this way columns will be proportionately filled in the WPF datagrid
all the columns will have 25% of the area of the datagrid.
<DataGrid Name="dataGrid1" AutoGenerateColumns="False" ItemsSource="{Binding Values}">
    <DataGrid.Columns>
         <DataGridTextColumn  Header="Value1" Binding="{Binding Value1, Width="0.25*"/>
         <DataGridTextColumn  Header="Value2" Binding="{Binding Value2, Width="0.25*"/>
         <DataGridTextColumn  Header="Value3" Binding="{Binding Value3, Width="0.25*"/>
         <DataGridTextColumn  Header="Value4" Binding="{Binding Value4, Width="0.25*"/>
    </DataGrid.Columns>           
 </DataGrid>

WPF - Inheriting a style



In the following style, a TextBlock's style in created with blinking animation.
// Here is the base style for TextBlock
        <Style x:Key="CellBaseStyle"  TargetType="{x:Type TextBlock}">
            <Setter Property="Background" Value="Transparent"/> 
            <Setter Property="Padding" Value="0,50,0,0"></Setter>
        </Style>

// Here you will use BasedOn property of Style to use the base style for TextBlock, properties in base style can be overridden in this style as well just like background property
        <Style TargetType="{x:Type TextBlock}" x:Key="SelectedCellStyle" 
               BasedOn="{StaticResource CellBaseStyle}">
            <Setter Property="Background">
                <Setter.Value>
                    <SolidColorBrush>
                        <SolidColorBrush.Color>
                            
                            <Color R="0" G="168" B="0"/>
                        </SolidColorBrush.Color>
                    </SolidColorBrush>
                </Setter.Value>
            </Setter>           
 
            <Setter Property="Foreground" Value="White"/>
            
            <Style.Triggers>
                <EventTrigger RoutedEvent="Binding.TargetUpdated">
                    <BeginStoryboard HandoffBehavior="Compose">
                        <Storyboard TargetProperty="(TextBlock.Background).(SolidColorBrush.Color)">
                            <ColorAnimation Duration="0:0:0.7" To="DarkGreen"   AutoReverse="True" RepeatBehavior="1" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Style.Triggers>
        </Style>

Friday, November 2, 2012

TableLayoutPanel Flickering in WinForms



Now use this tablelayoutpanel instead of default TableLayoutPanel in VS. It will decease the intensity of flickering of controls in tablelayoutpanel.

 public partial class MyTablelayoutPanel : TableLayoutPanel
    {
        public MyTablelayoutPanel()
        {
            InitializeComponent();

// this will reduce flicker
            this.DoubleBuffered = true;

            SetStyle(ControlStyles.AllPaintingInWmPaint |
            ControlStyles.OptimizedDoubleBuffer |
            ControlStyles.UserPaint, true);
                     }

        public NXBTablelayoutPanel(IContainer container)
        {
            container.Add(this);
            InitializeComponent();

// this will reduce flicker
            this.DoubleBuffered = true;
            SetStyle(ControlStyles.AllPaintingInWmPaint |
            ControlStyles.OptimizedDoubleBuffer |
            ControlStyles.UserPaint, true);
        }
    }